Drawing content at a fixed screen position, regardless of window position

Raymond Chen

Today’s Little Program draws content at a fixed screen position. The idea is that the window is really a viewport into some magical world. Unfortunately, our magical world just has a sign that says “Booga booga.” Creating a more interesting magical world is left as an exercise.

Start with our scratch program and make these changes:

void OnMove(HWND hwnd, int x, int y)
 InvalidateRect(hwnd, 0, TRUE);

void PaintContent(HWND hwnd, PAINTSTRUCT *pps) { POINT ptOrigin = { 0, 0 }; ClientToScreen(hwnd, &ptOrigin); POINT ptOrg; SetWindowOrgEx(pps->hdc, ptOrigin.x, ptOrigin.y, &ptOrg); TextOut(pps->hdc, 200, 200, TEXT(“Booga booga”), 11); SetWindowOrgEx(pps->hdc, ptOrg.x, ptOrg.y, nullptr); }

HANDLE_MSG(hwnd, WM_MOVE, OnMove);

Run this program and drag the window across the screen. When it reaches the “magic place”, you will see the words “Booga booga”. (You can resize the window to be smaller in order to make finding the magic place more of a challenge.)


Discussion is closed.

Feedback usabilla icon