An application can create a deadlock condition in Windows if it yields control while processing a message sent from another application (or by Windows on behalf of another application) by means of the SendMessage function. The application does not have to yield explicitly. Calling any one of the following functions can result in the application yielding control:
DialogBox
DialogBoxIndirect
DialogBoxIndirectParam
DialogBoxParam
GetMessage
MessageBox
PeekMessage
Yield
Normally a task that calls SendMessage to send a message to another task will not continue executing until the window procedure that receives the message returns. However, if a task that receives the message yields control, Windows can be placed in a deadlock situation where the sending task needs to execute and process messages but cannot because it is waiting for SendMessage to return.
A window function can determine whether a message it receives was sent by SendMessage by calling the InSendMessage function. Before calling any of the functions listed above while processing a message, the window function should first call InSendMessage. If InSendMessage returns TRUE, the window function must call the ReplyMessage function before calling any function that yields control.
As an alternative, can use a system modal dialog box or message box. Because system modal windows prevent other windows from receiving input focus or messages, an application should use system modal windows only when necessary.