我的工程是基于对话框的工程,menu属于主对话框类
我是按照这个帖子做的
http://community.csdn.net/Expert/topic/2703/2703248.xml?temp=.8762934
我的程序如下:
void CSSD1983Dlg::OnMenucom1()
{
bFlag=1;
}void CSSD1983Dlg::OnMenucom2()
{
bFlag=2;
}void CSSD1983Dlg::OnUpdateMenucom1(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(bFlag==1);
}void CSSD1983Dlg::OnUpdateMenucom2(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(1);
}
可是程序运行点击Menu以后,它们的checked属性一点变化都没有,怎么回事啊,是不是因为
用了基于对话框的工程就不能这样啊?
大侠赐教,急死了!
我是按照这个帖子做的
http://community.csdn.net/Expert/topic/2703/2703248.xml?temp=.8762934
我的程序如下:
void CSSD1983Dlg::OnMenucom1()
{
bFlag=1;
}void CSSD1983Dlg::OnMenucom2()
{
bFlag=2;
}void CSSD1983Dlg::OnUpdateMenucom1(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(bFlag==1);
}void CSSD1983Dlg::OnUpdateMenucom2(CCmdUI* pCmdUI)
{
pCmdUI->SetCheck(1);
}
可是程序运行点击Menu以后,它们的checked属性一点变化都没有,怎么回事啊,是不是因为
用了基于对话框的工程就不能这样啊?
大侠赐教,急死了!
解决方案 »
- 在ODBC编程中,如何成批添加记录,就是全部记录添加在CRecordset中后,然后再更新数
- 字符串数组赋值的问题,急急急
- 自动计划(autoplan)源代码***强烈推荐
- 对话框向单文档转化的问题(菜鸟问题)
- 数组定义问题。在线急等!解决问题,马上结贴!!
- 怎样在一个mfc应用程序中操作两个数据库??????????????
- 在线给分:有关CBitmap的成员函数GetBitmapBits( ),GetBitmap( ) 出现的问题
- 关于stream的一个问题
- 向大家请教GDI方式实现动画的问题
- 新手求救
- 小弟我对一个函数不明白,请高手指教。
- 如何在Html中写入字符串“<%=link%>”?
ON_UPDATE_COMMAND_UI( id, memberFxn )
{
UpdateMenuItems(GetMenu());
return 0;
}void CMainDlgDlg::UpdateMenuItems(CMenu* pMenu)
{
if(NULL==pMenu)return;
UINT nCount = pMenu->GetMenuItemCount();
CCmdUI cmdUI;
cmdUI.m_nIndexMax = nCount;
for(UINT n=0;n<nCount;++n){
UINT nID = pMenu->GetMenuItemID(n);
if(nID==UINT(-1)){
CMenu* pSubMenu = pMenu->GetSubMenu(n);
UpdateMenuItems(pSubMenu);
}else{
if(nID){
cmdUI.m_nIndex = n;
cmdUI.m_nID = nID;
cmdUI.m_pMenu = pMenu;
cmdUI.DoUpdate(this, FALSE);
}
}
}
}
ON_MESSAGE(WM_KICKIDLE,OnKickIdle)
再问一句,WM_KICKIDLE消息在添加消息的window_handler里面好像没有啊?
它是对话框的消息吗?为什么没有呢?从哪里知道这个消息的?
BEGIN_MESSAGE_MAP(CTest6Dlg, CDialog)
//{{AFX_MSG_MAP(CTest6Dlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
。
ON_WM_INITMENUPOPUP()//加这句
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
void CTest6Dlg::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{
CDialog::OnInitMenuPopup(pPopupMenu, nIndex, bSysMenu);
// TODO: Add your message handler code here
ASSERT(pPopupMenu != NULL);
// Check the enabled state of various menu items. CCmdUI state;
state.m_pMenu = pPopupMenu;
ASSERT( state.m_pOther == NULL );
ASSERT( state.m_pParentMenu == NULL ); // Determine if menu is popup in top-level menu and set m_pOther to
// it if so (m_pParentMenu == NULL indicates that it is secondary popup).
HMENU hParentMenu;
if (AfxGetThreadState()->m_hTrackingMenu == pPopupMenu->m_hMenu)
state.m_pParentMenu = pPopupMenu; // Parent == child for tracking popup.
else if ((hParentMenu = ::GetMenu(m_hWnd)) != NULL)
{
CWnd* pParent = this;
// Child windows don't have menus--need to go to the top!
if (pParent != NULL &&
(hParentMenu = ::GetMenu( pParent->m_hWnd )) != NULL)
{
int nIndexMax = ::GetMenuItemCount(hParentMenu);
for (int nIndex = 0; nIndex < nIndexMax; nIndex++)
{
if (::GetSubMenu(hParentMenu, nIndex) == pPopupMenu->m_hMenu)
{
// When popup is found, m_pParentMenu is containing menu.
state.m_pParentMenu = CMenu::FromHandle(hParentMenu);
break;
}
}
}
} state.m_nIndexMax = pPopupMenu->GetMenuItemCount();
for ( state.m_nIndex = 0; state.m_nIndex < state.m_nIndexMax; state.m_nIndex++ )
{
state.m_nID = pPopupMenu->GetMenuItemID(state.m_nIndex);
if (state.m_nID == 0)
continue; // Menu separator or invalid cmd - ignore it. ASSERT(state.m_pOther == NULL);
ASSERT(state.m_pMenu != NULL);
if (state.m_nID == (UINT)-1)
{
// Possibly a popup menu, route to first item of that popup.
state.m_pSubMenu = pPopupMenu ->GetSubMenu(state.m_nIndex);
if ( state.m_pSubMenu == NULL ||
( state.m_nID = state.m_pSubMenu->GetMenuItemID(0)) == 0 ||
state.m_nID == (UINT)-1)
{
continue; // First item of popup can't be routed to.
}
state.DoUpdate(this, TRUE); // Popups are never auto disabled.
}
else
{
// Normal menu item.
// Auto enable/disable if frame window has m_bAutoMenuEnable
// set and command is _not_ a system command.
state.m_pSubMenu = NULL;
state.DoUpdate(this, FALSE);
} // Adjust for menu deletions and additions.
UINT nCount = pPopupMenu ->GetMenuItemCount();
if ( nCount < state.m_nIndexMax )
{
state.m_nIndex -= (state.m_nIndexMax - nCount);
while ( state.m_nIndex < nCount &&
pPopupMenu->GetMenuItemID( state.m_nIndex ) == state.m_nID )
{
state.m_nIndex++;
}
}
state.m_nIndexMax = nCount;
}
}
{
// TODO: Add your command update UI handler code here
// pCmdUI->SetCheck(m_viewTaxonomy.IsWindowVisible());
}