Drawing a line to a handle process

I want to draw a line in a solitaire process, or any process in general, but it doesnt work. I've managed to get the code from a drawing tutorial, but im not experienced at that, plus it's very hard to find any tutorials on c++ graphics, so any help would be really appreciated. here's my code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include <Windows.h>
#include <iostream>


int main()
{
	HDC hdc;
	HWND app = FindWindow(0, "Solitaire");
	DWORD id;
	GetWindowThreadProcessId(app, &id);
	HANDLE handle = OpenProcess(PROCESS_ALL_ACCESS, FALSE, id);
	PAINTSTRUCT ps;
	hdc = BeginPaint(app, &ps);
	HPEN hPen,hOldPen;
	COLORREF xio = RGB(255,0,0);
	hPen = CreatePen(PS_SOLID, 10 , xio);
	hOldPen = (HPEN)SelectObject(hdc, hPen);

	MoveToEx(hdc,100,100,NULL);
	LineTo(hdc,250,500);

	system("pause");
	

}
You can only use BeginPaint() in the context of a WM_PAINT message. That's plain wrong right away.

Now I have never ever tried to do something like this, so I'll just say and you try: Change BeginPaint() for GetDC(NULL) to get a DC for the entire screen. See if you can draw in it. If you can, then use that. Just make sure you calculate the coordinates right.
thanks it works! i've just changed to GetDC(app).
Topic archived. No new replies allowed.