Weird behaviour of "Textout" ...

Gentle people, This drives me nuts! Please consider the following pieces of code:

InitInstance:
szBkwMsg = "Message1"; <-----
ShowWindow( hWnd, nCmdShow );
UpdateWindow( hWnd );
SendMessage( hWnd, WM_COMMAND, IDM_BKW, 0 );
WndProc:
case IDM_BKW:
while (szInDs == "")
{
if (DialogBox(hInst, .... <-----
{

}
}
szBkwMsg = "Message2"; <-----
UpdateWindow( hWnd );
DialogBox(hInst, ... <-----

case WM_PAINT:
hdc = BeginPaint (hWnd, &ps);
TextOut(hdc, iTextx, iTexty, szBkwMsg, strlen(szBkwMsg));
EndPaint( hWnd, &ps );
return 0

Simple and straight forward I thought, but what happens is:
- "Message1" written in Initinstance shows up only after the call to the dialogbox in WndProc ("if (DialogBox(hInst, ...."). This would not hurt, but "Message2" developed a very peculiar behaviour. Watching the process in debug mode everything works fine. I can see "Message2" being processed and shown (after the call to a dialogbox). But executing the program outside debug or stopping the program after the call to the dialogbox for the first time "Message1" (!!!) is displayed.

I may be a novice in Windows programming, but I am an old warhorse in OS/370 event-driven programming and I have tried everything which came to my mind, but still:
- I need a dialogbox to show the message on the screen, and
- I always see "Message1" when not in debug-mode

Does anybody have an idea where I go wrong
Thanks a lot for yout interest!

e.g.gru


Answer this question

Weird behaviour of "Textout" ...

  • mwherman2000

    You only call UpdateWindow, not InvalidateRect! If there was no change to the display at the specific point, UpdateWindow will do nothing. You can also use RedrawWindow.

  • yeltomw

    Problem solved! InvalidateRect did zje trick!

    Thank you! E.G.Gru

  • Lweek

    Sorry, didn't work either! Called RedrawWindow after UpdateWindow and had the same result! According to the documentation available to me UpdateWindow invalidates everything in the window specified. Which is true, for I see an empty window before the call to a dialogbox to show the "new" contents of the window. This is all rather exasperating, but thank you for your interest and help!

    e.g.gru

  • domi

    No! UpdateWindow invalidates nothing. UpdateWindow updates only what was invalidated!

    Can you post a sample code somewhere that I can check. Place a link to the project here, or send it by email.



  • Weird behaviour of "Textout" ...