Sign in to follow this  
Starter

WinAPI: PostThreadMessage() issue with ShowWindow()

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this