C++ SfML绘制到其他窗口
我知道如何在用sf::RenderWindow创建的窗口中绘制文本;但我需要画文本到已经存在的游戏窗口。它使它变成黑色,我不想抹掉整个窗口,只是更新它的文本。代码:C++ SfML绘制到其他窗口,c++,window,draw,sfml,hwnd,C++,Window,Draw,Sfml,Hwnd,我知道如何在用sf::RenderWindow创建的窗口中绘制文本;但我需要画文本到已经存在的游戏窗口。它使它变成黑色,我不想抹掉整个窗口,只是更新它的文本。代码: #include <SFML/Graphics.hpp> #include <SFML/Graphics/Font.hpp> #include <windows.h> #include <iostream> using namespace std; int main() {
#include <SFML/Graphics.hpp>
#include <SFML/Graphics/Font.hpp>
#include <windows.h>
#include <iostream>
using namespace std;
int main()
{
HWND hWindow = FindWindow(0, "Counter-Strike: Global Offensive");
if(!hWindow) exit(0);
else
{
int i=0;
string tmp, str;
sf::RenderWindow window(hWindow);
sf::Font font;
if(!font.loadFromFile("verdana.ttf"))
{
cout << "error";
}
sf::Text text;
text.setFont(font);
text.setCharacterSize(17);
text.setColor(sf::Color::White);
while (window.isOpen())
{
i++;
itoa(i, (char*)tmp.c_str(), 10);
str = tmp.c_str();
text.setString(str);
sf::Event event;
while (window.pollEvent(event))
{
if (event.type == sf::Event::Closed)
window.close();
}
Sleep(1000);
window.clear(sf::Color::Transparent);
window.draw(text);
window.display();
}
return 0;
}
}
请帮我做这件事:我想这不会像你想象的那么容易。 我知道的每一个可以操纵游戏backbuffer的程序都会钩住API调用。这并不难。这里有一些很好的图书馆。但真正的问题是,几乎所有游戏都使用DirectX。 SFML使用OpenGL。我认为他们不能混为一谈 您应该使用Direct2D或其他基于DirectX的图形库。 甚至还有一些教程解释了如何编写覆盖图。就用谷歌吧