• Advertisement
Sign in to follow this  

WinAPI: PostThreadMessage() issue with ShowWindow()

This topic is 3188 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a window with a message loop that receives messages from another thread via PostThreadMessage() to minimize itself, but every time the command is received and the ShowWindow(hWnd, SW_MINIMIZE) is called either the command is not removed from PeekMessage or the same command is added to the queue again resulting in an infinite loop. PeekMessage has the PM_REMOVE flag specified. I know this is a very specific problem but if anyone can help, please do!

Share this post


Link to post
Share on other sites
Advertisement
It also happens to PostMessage() when posting from different thread.

Share this post


Link to post
Share on other sites
What exactly are you trying to do with the window? ShowWindow() will post a WM_SHOWWINDOW message to the window, hence the infinite loop. To avoid it, maybe something like this might work for you:

case WM_SHOWWINDOW:
{
static BOOL bIgnore = FALSE;
if( bIgnore ) break;
if( wParam == 0 ) // Or whatever, depending on your goal.
{
bIgnore = TRUE;
ShowWindow( ... );
bIgnore = FALSE;
return 0;
}
}
break;

Share this post


Link to post
Share on other sites
I don't even process WM_SHOWWINDOW so that couldn't be it.

What my app does is one thread sends a custom message (using PostThreadMessage()) to another thread that has contains a window. The custom message tells the thread with the window to call ShowWindow(hWnd, SW_MINIMIZE).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement