Solved

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

Posted on 2002-04-29
2
940 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 300 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

Need Help in Real-Time?

Connect with top rated Experts

22 Experts available now in Live!

Get 1:1 Help Now