Note that you can't use the ON_UPDATE_COMMAND_UI message on this toolbar, since it can only be refresh when the dialog enters in idle state. To do so, you must subclass the CToolBar (or CStatusBar) class - in CMyToolBar for instance -, add the message handler for WM_IDLEUPDATECMDUI, and write the following code in this function :
/////////////////////////////////////////////////////////////////////////////
// CMyToolBar::OnIdleUpdateCmdUI
// OnIdleUpdateCmdUI handles the WM_IDLEUPDATECMDUI message, which is
// used to update the status of user-interface elements within the MFC
// framework.
//
// We have to get a little tricky here: CToolBar::OnUpdateCmdUI
// expects a CFrameWnd pointer as its first parameter. However, it
// doesn't do anything but pass the parameter on to another function
// which only requires a CCmdTarget pointer. We can get a CWnd pointer
// to the parent window, which is a CCmdTarget, but may not be a
// CFrameWnd. So, to make CToolBar::OnUpdateCmdUI happy, we will call
// our CWnd pointer a CFrameWnd pointer temporarily. LRESULT CMyToolBar::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM)
{
if (IsWindowVisible())
{
CFrameWnd *pParent = (CFrameWnd *)GetParent();
if (pParent)
OnUpdateCmdUI(pParent, (BOOL)wParam);
}
return 0L;
}
In order to have the toolbar updated you MUST override the ContinueModal() function that way:
/////////////////////////////////////////////////////////////////////////////
// CMyToolBar::OnIdleUpdateCmdUI
// OnIdleUpdateCmdUI handles the WM_IDLEUPDATECMDUI message, which is
// used to update the status of user-interface elements within the MFC
// framework.
//
// We have to get a little tricky here: CToolBar::OnUpdateCmdUI
// expects a CFrameWnd pointer as its first parameter. However, it
// doesn't do anything but pass the parameter on to another function
// which only requires a CCmdTarget pointer. We can get a CWnd pointer
// to the parent window, which is a CCmdTarget, but may not be a
// CFrameWnd. So, to make CToolBar::OnUpdateCmdUI happy, we will call
// our CWnd pointer a CFrameWnd pointer temporarily. LRESULT CMyToolBar::OnIdleUpdateCmdUI(WPARAM wParam, LPARAM)
{
if (IsWindowVisible())
{
CFrameWnd *pParent = (CFrameWnd *)GetParent();
if (pParent)
OnUpdateCmdUI(pParent, (BOOL)wParam);
}
return 0L;
}
In order to have the toolbar updated you MUST override the ContinueModal() function that way:
解决方案 »
- MFC基于对话框的打印
- 如何在acitvex控件程序中设置断点,调试
- 请大哥大姐指教 CreateInstance 的问题
- 关于IE工具条的位置的问题
- 谁给贴上一个用RASDIAL()函数做的宽带拨号程序源码(SDK),能在XP下执行就行,200分送上!
- 怎样将一个VC控制台程??????????????
- 单步调试
- 进期要在WIN2K平台下用VC写一个类似于代理的程序,请问那里有WIN2K平台下的抓帧的工具,就向WIN98下的NETXRAY?
- 请问MultiByteToWideChar()函数怎么用?
- 一个有关消息的问题,高手请入?
- 用ATL写activex看哪一本书比较好!
- 一个编译出错的问题?
{
m_wndToolbar.SendMessage( WM_IDLEUPDATECMDUI, WPARAM(TRUE), 0);
return CDialog::ContinueModal();
}
For AfxLoadString to compile you must Include the file "Afxpriv.h" at the beginning of the CPP file