Implementation details to
perform with a CDialog
instance
-
Include the
MFC header
file declaring private
Windows messages and
macros in the source
file (.cpp) of your
dialog class
implementation.
Collapse
Copy Code
#include <afxpriv.h>
-
In the corresponding
header file where your
dialog window class is
defined declare the
prototypes of the
WM_KICKIDLE
message handler and the
update UI handler as
well. The
WM_KICKIDLE
message is always sent
by the system if your
dialog instance is idle.
This is a good time to
do some framework job.
Collapse
Copy Code
virtual BOOL OnInitDialog();
afx_msg void OnPaint();
[...]
afx_msg void OnKickIdle();
afx_msg void OnUpdateUserButton(CCmdUI* pCmdUI);
DECLARE_MESSAGE_MAP()
-
Update your message map
in .cpp file to map the
WM_KICKIDLE
message and
the update notification
message for the desired
resource (the push
button in our sample).
Collapse
Copy Code
BEGIN_MESSAGE_MAP(CCmdUIDemoDlg, CDialog)
ON_WM_PAINT()
[...]
ON_MESSAGE_VOID(WM_KICKIDLE, OnKickIdle)
ON_UPDATE_COMMAND_UI(IDC_BUTTON1, OnUpdateUserButton)
END_MESSAGE_MAP()
-
At last implement the
bodies of both message
handlers
Collapse
Copy Code
void CCmdUIDemoDlg::OnKickIdle()
{
UpdateDialogControls(this, FALSE);
}
void CCmdUIDemoDlg::OnUpdateUserButton(CCmdUI *pCmdUI)
{
pCmdUI->Enable(m_bToggle);
}
-
Done! By the pCmdUI
pointer you've now
access to the methods of
the
CCmdUI
instance associated with
the object, e.g. the
value of the
Enable()
method's parameter
(BOOL) decides if the
control is enabled or
disabled as known from a
menuitem or tool bar
button.
Implementation details to
perform with a CFormView
instance (not part of the
demo code)
To use the update
notification mechanism for a
CFormView
instance instead of a
CDialog
instance perform the
following steps by analogy:
-
Include the
MFC header
file declaring private
Windows messages and
macros in the source
file (.cpp) of your
dialog class
implementation.
Collapse
Copy Code
#include <afxpriv.h>
-
In the corresponding
header file where your
view class is defined
declare the prototypes
of the
WM_IDLEUPDATECMDUI
message
handler and the update
UI handler as well. The
WM_IDLEUPDATECMDUI
message is
always sent by the
system if your view
instance is idle.
Collapse
Copy Code
[...]
afx_msg void OnIdleUpdateCmdUI();
afx_msg void OnUpdateUserControl(CCmdUI* pCmdUI);
DECLARE_MESSAGE_MAP()
-
Update your message map
in .cpp file to map the
WM_IDLEUPDATECMDUI
message and the update
notification message for
the desired resource.
Collapse
Copy Code
BEGIN_MESSAGE_MAP(CMyFormView, CFormView)
[...]
ON_MESSAGE_VOID(WM_IDLEUPDATECMDUI, OnIdleUpdateCmdUI)
ON_UPDATE_COMMAND_UI(IDC_MY_CONTROL, OnUpdateUserControl)
END_MESSAGE_MAP()
-
At last implement the
bodies of both message
handlers
Collapse
Copy Code
void CMyFormView::OnIdleUpdateCmdUI()
{
UpdateDialogControls(this, FALSE);
}
void CMyFormView::OnUpdateUserControl(CCmdUI *pCmdUI)
{
pCmdUI->Enable(...);
}
-
Done!