To aquire a DC (Device Context) of a program, you can first get the Window Handle of the application, then get the DC from the HWND.
Here's what I have, and it appears to not work with *anything*:
#include <iostream>
#include <windows.h>
#define WindowName "Untitled - Notepad"
using namespace std;
int main() {
TCHAR szBuffer[20];
int iLength = 0;
HWND hwnd = FindWindow(0, WindowName); /* aquire the Window Handle */
HDC hdc = GetDC(hwnd); /* aquire the Device Context FROM the Window Handle */
RECT rect;
rect.bottom = 50;
rect.left = 50;
rect.right = 50;
rect.top = 50;
iLength = wsprintf(szBuffer, "Hello World");
cout << "szBuffer: " << szBuffer << "!";
while (true) {
/* supposed to draw out the text, but appears to not */
DrawText(hdc, szBuffer, iLength, &rect, DT_CENTER);
/* Hotkey to end the program when the "END" key is depressed */
if ( ( (GetAsyncKeyState(VK_END)) ? 1 : 0) ) { return 0; }
}
cin.get();
return 0;
}
My question is: How do you use DrawText to draw on an external application (or game)?

Ask A New Question
Reply





MultiQuote





|