I'm using the DrawText function in a Win32 program to display "Local" at the top center of the screen and "Server" in the center. When I run the program it displays "Local" but not "Server". Here is the code in my message loop:
case WM_PAINT:
{
RECT localLabel;
localLabel.left = 0;
localLabel.top = 0;
localLabel.right = 270;
localLabel.bottom = 20;
PAINTSTRUCT localPs;
HDC localHandle = BeginPaint(hwnd, &localPs);
DrawText(localHandle, "Local", -1, &localLabel, DT_CENTER);
EndPaint(hwnd, &localPs);
PAINTSTRUCT serverPs;
RECT serverLabel;
serverLabel.left = 0;
serverLabel.top = 100;
serverLabel.right = 270;
serverLabel.bottom = 20;
HDC serverHandle = BeginPaint(hwnd, &serverPs);
DrawText(serverHandle, "Server", -1, &serverLabel, DT_CENTER);
EndPaint(hwnd, &serverPs);
}
break;
I tried using the same PAINTSTRUCT but that didn't help. I tried using the same HDC but that didn't help either. How can I display both on the screen?
Thanks.
Your second rectangle is not valid (
bottom
should be120
instead of20
because it's the actual bottom coordinate, not the height). Also, you have to render both strings before callingEndPaint()
:Finally, as an aside, you probably don't want to leave all that code in one of your window procedure's
case
statements. Consider moving it into its own function to improve readability (and maintainability).