HOWTO: Clear a Message Box

ID: Q74444


The information in this article applies to:


SUMMARY

During the processing of the MessageBox() function, Windows creates a bitmap to save the part of the screen covered by the message box. Normally, before the MessageBox() function returns, Windows repaints the portion of the screen covered by the message box using the bitmap. In this scenario, when the user clicks on a button to dismiss the message box, the message box disappears immediately.

It is important to note that under low memory conditions, Windows will discard the bitmap. If the bitmap is discarded and a significant amount of processing takes place between the MessageBox() call and painting the application's window, the vestigial image of the message box will remain on the screen during the processing. If the user clicks on this image with the mouse, the underlying window will receive the mouse messages. This can cause unexpected (and possibly undesirable) effects.

To address this problem, call UpdateWindow() immediately after MessageBox(). The parameter to UpdateWindow() should be the parent window of the message box (or of the application's main window if the message box has no parent). This will cause the application to paint the affected window if the bitmap has been discarded. The message box will disappear immediately under all circumstances.

Additional query words: WIN16SDK


Keywords          : kbMessageBox kbNTOS kbGrpUser kbWinOS 
Version           : 
Platform          : 
Issue type        : kbhowto 

Last Reviewed: March 7, 1999