June 24th, 2013

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

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.)

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.