Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS General Discussion » Problem in CExtToolControlBar Collapse All
Subject Author Date
Rafael Heitor Correia de Melo Apr 6, 2004 - 3:03 PM

I’m using your classes for the menu and the toolbar in my project but I’m think I found an error on the update/paint of your toolbar. In my project I have a function that works like a thread, this function do some processing and during this sometime this code below is executed:


if (::PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
{
  ::TranslateMessage(&msg);
  ::DispatchMessage(&msg);
}


The problem is, during the executing of my function the user can do lots of things including taking actions that could change the state (enable/disable) of some menu/toolbar itens. This actions works fine for the menu itens, but the equivalent itens of the toolbar (who has the same ID that the menu itens) doesnt’t work like they should. The toolbar buttons for example still grayed after they became enabled. And it seems like a painting problem because if I click on the button the desirable functionality is executed.


Can someone please help me with this problem ?


Sorry for the long message.


Thanks in advance,
Rafael Melo

Technical Support Apr 8, 2004 - 2:15 AM

Dear Rafael,

The DispatchMessage() function delivers a message to the window procedure,
i.e. it invokes the window procedure for an appropriate HWND.
This means the MFC message routing is not used.
For example, if you have a CView-derived object inside the SDI application with a CFrameWnd-derived
object as a main frame window and click a toolbar button,
the WM_COMMAND message is sent to the CFrameWnd window.
The DispatchMessage() function delivers the WM_COMMAND directly to CFrameWnd.
But MFC allows you to handle this message in CView.
This is possible because MFC uses the command routing mechanism instead of simple direct
message delivery to the window objects.
The use of the DispatchMessage() API causes neither the command routing,
nor correct CCmdUI-based command updating are performed.
So, you should use the CWinThread::PumpMessage() method which performs peeking,
pre-translating, routing and delivering all the messages.
The message pumping algorithm of the CWinThread class is more complex than the simple mechanism
of the message delivery to the window objects via the DispatchMessage() API.
So, your code should look like:

if( ::PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE ) ) 
{
    // You should use PM_NOREMOVE !!!
    // this just tests whether any message is available
    // in the message queue 
    // --------------------------------
    // If we are here, then we can let the MFC pump
    // the first available message for further processing 
    // (i.e. peeking with PM_REMOVE, pre-translating, routing and delivering)
    ( ::AfxGetThread() ) -> PumpMessage();
}
If you encounter any problems with toolbar buttons, send us your project so we can help you.