Solved

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

Posted on 2002-04-29
2
931 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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
how to monitor remote shell execution on linux 9 92
isEverywhere  challenge 19 64
java ^ examples 8 57
Detect file exist or not 3 76
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
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.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

743 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

17 Experts available now in Live!

Get 1:1 Help Now