PeekMessage for Parent Window
-
I'm writing a plug-in for a product that provides extremely little (ie. none) feedback about the window environment. Even something as simple as a resize event is not delivered. So, I'm trying to hook into the parent window(s) to catch messages that they receive and process them appropriately. To that end, I've created a simple class that looks something like this:
CSizeWatcher::operator()( HWND hWnd )
{
MSG zMsg;while( true )
{
if( ::PeekMessage( &zMsg, hWnd, WM_SIZE, WM_SIZE, PM_NOREMOVE ) )
{
if( zMsg.message == WM_QUIT )
{
break;
}if( zMsg.message == WM\_SIZE ) { printf( "oh..." ); } }
}
}And it gets invoked from the
OnInitDialog
method like this (effectively, it is actually instantiated in a separate thread):zWatcher( ::GetParent( m_hWnd ) );
Using Spy++, I see that I do have the correct
HWND
, but I never seem to get any messages.PeekMessage
never returns true. I have tried removing the Min and Max, setting both to zero, but again, no messages. Is this an inappropriate use ofPeekMessage
? Can one not use it to peek into the queues for parent (or any) windows? Perhaps Hooks are what I need to look at? Thanks, CraigL -
I'm writing a plug-in for a product that provides extremely little (ie. none) feedback about the window environment. Even something as simple as a resize event is not delivered. So, I'm trying to hook into the parent window(s) to catch messages that they receive and process them appropriately. To that end, I've created a simple class that looks something like this:
CSizeWatcher::operator()( HWND hWnd )
{
MSG zMsg;while( true )
{
if( ::PeekMessage( &zMsg, hWnd, WM_SIZE, WM_SIZE, PM_NOREMOVE ) )
{
if( zMsg.message == WM_QUIT )
{
break;
}if( zMsg.message == WM\_SIZE ) { printf( "oh..." ); } }
}
}And it gets invoked from the
OnInitDialog
method like this (effectively, it is actually instantiated in a separate thread):zWatcher( ::GetParent( m_hWnd ) );
Using Spy++, I see that I do have the correct
HWND
, but I never seem to get any messages.PeekMessage
never returns true. I have tried removing the Min and Max, setting both to zero, but again, no messages. Is this an inappropriate use ofPeekMessage
? Can one not use it to peek into the queues for parent (or any) windows? Perhaps Hooks are what I need to look at? Thanks, CraigLWell, absolutely no luck getting the PeekMessage to work, so I've instead gone and sub-classed the window. Although it's far more tricky from c++, it does get what I need.
-
Well, absolutely no luck getting the PeekMessage to work, so I've instead gone and sub-classed the window. Although it's far more tricky from c++, it does get what I need.
GetMessage[^] and PeekMessage[^] use the message queue: they will only work for messages that were posted (see PostMessage[^]). The WM_SIZE[^] message is sent (see SendMessage[^]). Subclassing or hooking (See SetWindowsHookEx[^]) is the way to go.
Steve