Solved

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

Posted on 2002-04-29
2
966 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Get proactive database performance tuning online

At Percona’s web store you can order full Percona Database Performance Audit in minutes. Find out the health of your database, and how to improve it. Pay online with a credit card. Improve your database performance now!

Question has a verified solution.

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

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

615 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