PRB: VBX Controls Automatically Disabled in MFC Dialog BarLast reviewed: July 22, 1997Article ID: Q119766 |
1.00 1.50
WINDOWS
kbprg kbprb
The information in this article applies to:
The Microsoft Foundation Classes (MFC), included with: - Microsoft Visual C++ for Windows, versions 1.0 and 1.5
SYMPTOMSAfter adding VBX controls to an MFC dialog bar object, they are automatically disabled when the program is executed.
CAUSEMany VBX controls are implemented by subclassing the standard Windows button class. MFC CDialogBar objects automatically disable button controls which do not implement a WM_COMMAND or ON_UPDATE_COMMAND_UI message handler. This is by design, but since ClassWizard does not provide support for adding these handlers for VBX controls, it can sometimes be undesirable.
RESOLUTIONThere are two methods which can be used to work around this problem.
Method #1:This solution requires you to manually add an ON_COMMAND_UPDATE_UI handler for each VBX control that subclasses the standard Windows button class. This handler will simply enable the control whenever it is called. As mentioned above, ClassWizard does not provide support for adding ON_UPDATE_COMMAND_UI handlers for VBX controls. It only allows you to create VBX event notification functions. Note: The ON_UPDATE_COMMAND_UI handler, in case of a CDialogBar would be added to the parent of CDialogBar, which usually is the CMainFrame class created by AppWizard. To manually add an ON_UPDATE_COMMAND_UI handler, follow these steps:
//{{AFX_MSG(CMainFrame) ... //}}AFX_MSG afx_msg void OnUpdateVBXControl1(CCmdUI* pCmdUI); afx_msg void OnUpdateVBXControl2(CCmdUI* pCmdUI); BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd) //{{AFX_MSG_MAP(CMainFrame) ... //}}AFX_MSG_MAP ON_UPDATE_COMMAND_UI(IDC_VBXCONTROL1, OnUpdateVBXControl1) ON_UPDATE_COMMAND_UI(IDC_VBXCONTROL2, OnUpdateVBXControl2)END_MESSAGE_MAP()
In this example, IDC_VBXCONTROL1 and IDC_VBXCONTROL2 are the resource identifiers for the two VBX controls.
void CMainFrame::OnUpdateVBXControl1(CCmdUI* pCmdUI){ pCmdUI->Enable(TRUE);}
void CMainFrame::OnUpdateVBXControl2(CCmdUI* pCmdUI){ pCmdUI->Enable(TRUE);}
Method #2:This solution is much easier to implement, although it has the drawback of preventing automatic disabling of non-VBX button controls on a dialog bar. Thus, no button control will ever be disabled even if it doesn't implement a WM_COMMAND or ON_UPDATE_COMMAND_UI handler. The CControlBar class defines the OnUpdateCmdUI() pure virtual function, which is overridden in the CDialogBar class to call CWnd::UpdateDialogControls. This function is presented below:
void CDialogBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOLbDisableIfNoHndler) { UpdateDialogControls(pTarget, bDisableIfNoHndler);} This is the function which is responsible for automatically disabling button controls on a dialog bar. You can prevent this function from being called by deriving a class from CDialogBar and overriding this function so that it resembles the following:
void CMyDerivedDialogBar::OnUpdateCmdUI(CFrameWnd* pTarget, BOOLbDisableIfNoHndler) { UpdateDialogControls(pTarget, FALSE);}
MORE INFORMATIONTo reproduce the problem add a VBX control to the dialog bar in the CTRLBARS sample included as a MFC sample with Visual C++. To add the VBX do the following:
REFERENCESTechnical Note 31: Control Bars, under MFC Technotes included with Visual C++.
|
Additional reference words: 1.00 1.50 2.00 2.50 disabled gray grey dialog
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |