Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

CStatusBar & CToolBar in a CReBar on a modeless dialog and ON_UPDATE_COMMAND_UI

Posted on 2002-04-29
2
Medium Priority
?
984 Views
Last Modified: 2013-11-20
My app is an ATL COM EXE server (out-of-proc)  with MFC support added in.  I have an invisible main window, whose main purpose in life is to provide the app's message pump.

I also have a modeless dialog which is the application's primary window.  On this dialog I have a CReBar, and in the CReBar are 2 bands; a CToolBar and a CStatusBar.

I would like to use MFC's ON_UPDATE_COMMAND_UI mechanism to update both the enabled-state of the buttons in the toolbar and the indicators of the status bar, but I can't get it to work.  My ON_UPDATE_COMMAND_UI handlers for the individual controls (example, the button in the toolbar) are never called in the controlbar.  The update-handlers are fired in the dialog class for the dialog's menubar, but they are not fired in the CReBar or CStatusBar or CToolBar classes.

I am using the technique outlined in 'MFC Answer Book' FAQ # 6.10 and FAQ # 4.8, but it's not working as advertised.

Could anyone shed any light on this for me?  Has anyone else done something like what I am doing?

Thanks for the use of your brain.
0
Comment
Question by:quando
2 Comments
 
LVL 12

Accepted Solution

by:
migel earned 1200 total points
ID: 6979689
Hi!
I think that this happens due to CControlBar class design
its implementation checks is CFrameWnd derived class in the parents chain and if none of that found just not start UpdateUI mechanism.
Try derive your own classes for CRebar, CToolBar and CStatusBar and handle:
WM_IDLEUPDATECMDUI (you nee to include "afxpriv.h" to use this message)
for example:
// your dialog class h file
ON_MESSAGE(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
LRESULT OnIdleUpdateCmdUI(WPARAM wParam, LPARAM)

///cpp file
LRESULT CControlBar::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM)
{
     // handle delay hide/show
     BOOL bVis = GetStyle() & WS_VISIBLE;
     UINT swpFlags = 0;
     if ((m_nStateFlags & delayHide) && bVis)
          swpFlags = SWP_HIDEWINDOW;
     else if ((m_nStateFlags & delayShow) && !bVis)
          swpFlags = SWP_SHOWWINDOW;
     m_nStateFlags &= ~(delayShow|delayHide);
     if (swpFlags != 0)
     {
          SetWindowPos(NULL, 0, 0, 0, 0, swpFlags|
               SWP_NOMOVE|SWP_NOSIZE|SWP_NOZORDER|SWP_NOACTIVATE);
     }

     // the style must be visible and if it is docked
     // the dockbar style must also be visible
     if ((GetStyle() & WS_VISIBLE) &&
          (m_pDockBar == NULL || (m_pDockBar->GetStyle() & WS_VISIBLE)))
     {
          CFrameWnd* pTarget = (CFrameWnd*)GetOwner();
          if (pTarget == NULL || !pTarget->IsKindOf(RUNTIME_CLASS(CMyDialog))) /// << main changes here!
               pTarget = GetParent(); /// << change too
          if (pTarget != NULL)
               OnUpdateCmdUI(pTarget, (BOOL)wParam);
     }
     return 0L;
}
0
 
LVL 1

Author Comment

by:quando
ID: 7003727
Sorry, I forgot that I had asked this question.  I solved this problem long ago on my own.

Miguel, you were close enough to right.  
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
Introduction: Database storage, where is the exe actually on the disc? Playing a game selected randomly (how to generate random numbers).  Error trapping with try..catch to help the code run even if something goes wrong. Continuing from the seve…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question