How to properly get mouse coordinates in Win32

So I've been fiddling around with this, but what I'm trying to do is just to print a message using TextOut() at the coordinates of my mouse. Everything builds just fine but when I click, nothing happens. It originally would just quit the program, but I just forgot a break statement. Anyway, here is the code in questions:

1
2
3
4
5
6
7
8
9
10
11
case WM_LBUTTONDOWN:
			POINT pts;
			hdc = BeginPaint(hWnd, &ps);
			GetCursorPos(&pts);
			ScreenToClient(hWnd, &pts);
			TextOut(hdc,
				pts.x, pts.y,
				greeting, _tcslen(greeting));

			EndPaint(hWnd, &ps);
			break;
This is incorrect use of the BeginPaint and EndPaint - functions.
If the window has no update region then the DC returned by BeginPaint will be 0 (zero) size and so no painting will occur (as painting cannot occur ouside the DC clipping rectangle)

You should use the GetDC and ReleaseDC functions instead (The GetDC funtion will return a DC for the whole client area)
Last edited on
Topic archived. No new replies allowed.