⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 subject_27409.htm

📁 一些关于vc的问答
💻 HTM
字号:
<p>
序号:27409 发表者:阿平 发表日期:2003-01-11 10:16:47
<br>主题:请教 	pCmdUI-&gt;SetCheck()
<br>内容:我建立了一个基于对话框的程序,在程序里加入到一个菜单。<BR>当使用pCmdUI-&gt;SetRadio();或者是pCmdUI-&gt;SetCheck()都没有效果这是为什么啊,我什么地方做错了吗?<BR><BR>void CSkinTestDlg::OnUpdateMenuitemSkin1(CCmdUI* pCmdUI) <BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;// TODO: Add your command update UI handler code here<BR>&nbsp;&nbsp;&nbsp;&nbsp;// MessageBox("OnMenuitem32772()");这一条已经执行了<BR>&nbsp;&nbsp;&nbsp;&nbsp;MessageBox("OnMenuitem32772()");<BR>&nbsp;&nbsp;&nbsp;&nbsp;pCmdUI-&gt;SetRadio();<BR>}<BR><BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:tjhe 回复日期:2003-01-11 10:28:16
<br>内容:这是一本书上的文章,可以参考一下:<BR><BR><BR>ON_UPDATE_COMMAND_UI宏用于菜单和工具条处理,比如设置菜单的 状态 (enabled/disabled, checked/unchecked 等) 。这些处理是通过调用OnUpdateXXX来实现的。可是,该宏只适用于基于文档/视窗模型的应用程序,而对于对话框,还没有提高类似的功能来处理按钮的状态而使用该宏,在处理对话框中拥有大量按钮、而这些按钮之间存在状态控制关系时尤为重要。本程序讲解该宏在对话框中实现。<BR><BR>本程序从CDialog派生了一个类CCmdUIDialog,实现了必要的代码来调用OnUpdateXXX函数。在使用时,你可以直接从 CCmndUIDialog派生,而不从CDialog派生新类,并手工添加ON_UPDATE_COMMAND_UI宏到新类。 <BR><BR>类声明:<BR>#if !defined(AFX_CMDUIDIALOG_H__7D35F4B8_7531_11D1_8FA7_000000000000__INCLUDED_)<BR>#define AFX_CMDUIDIALOG_H__7D35F4B8_7531_11D1_8FA7_000000000000__INCLUDED_<BR><BR>#if _MSC_VER &gt;= 1000<BR>#pragma once<BR>#endif // _MSC_VER &gt;= 1000<BR>// CmdUIDialog.h : header file<BR>// <BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CCmdUIDialog dialog<BR><BR>class CCmdUIDialog : public CDialog<BR>{<BR>// Construction<BR>public:<BR>&nbsp;&nbsp;&nbsp;&nbsp;CCmdUIDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd = NULL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;CCmdUIDialog(UINT nIDTemplate, CWnd* pParentWnd = NULL);<BR>&nbsp;&nbsp;&nbsp;&nbsp;CCmdUIDialog();<BR>&nbsp;&nbsp;&nbsp;&nbsp;BOOL ContinueModal();<BR><BR>// Implementation<BR>protected:<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Generated message map functions<BR>&nbsp;&nbsp;&nbsp;&nbsp;//{{AFX_MSG(CCmdUIDialog)<BR>&nbsp;&nbsp;&nbsp;&nbsp;// NOTE: the ClassWizard will add member functions here<BR>&nbsp;&nbsp;&nbsp;&nbsp;//}}AFX_MSG<BR>&nbsp;&nbsp;&nbsp;&nbsp;DECLARE_MESSAGE_MAP()<BR>};<BR><BR>//{{AFX_INSERT_LOCATION}}<BR>// Microsoft Developer Studio will insert additional declarations immediately before the previous line.<BR><BR>#endif // !defined(AFX_CMDUIDIALOG_H__7D35F4B8_7531_11D1_8FA7_000000000000__INCLUDED_)<BR><BR><BR>类实现:<BR>// CmdUIDialog.cpp : implementation file<BR>//<BR><BR>#include "stdafx.h"<BR>#include "delme.h"<BR>#include "CmdUIDialog.h"<BR><BR>#ifdef _DEBUG<BR>#define new DEBUG_NEW<BR>#undef THIS_FILE<BR>static char THIS_FILE[] = __FILE__;<BR>#endif<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CCmdUIDialog dialog<BR><BR><BR>CCmdUIDialog::CCmdUIDialog(LPCTSTR lpszTemplateName, CWnd* pParentWnd)<BR>&nbsp;&nbsp;&nbsp;&nbsp;: CDialog(lpszTemplateName, pParentWnd)<BR>{<BR>}<BR><BR>CCmdUIDialog::CCmdUIDialog(UINT nIDTemplate, CWnd* pParentWnd)<BR>&nbsp;&nbsp;&nbsp;&nbsp;: CDialog(nIDTemplate, pParentWnd)<BR>{<BR>}<BR><BR>CCmdUIDialog::CCmdUIDialog()<BR>{<BR>}<BR><BR><BR>BOOL CCmdUIDialog::ContinueModal()<BR>{<BR>&nbsp;&nbsp;&nbsp;&nbsp;// Iterate all child windows and instruct to update themselves<BR>&nbsp;&nbsp;&nbsp;&nbsp;CWnd* pWndChild=GetWindow(GW_CHILD);<BR>&nbsp;&nbsp;&nbsp;&nbsp;int iIndex=0;<BR>&nbsp;&nbsp;&nbsp;&nbsp;while (NULL!=pWndChild)<BR>&nbsp;&nbsp;&nbsp;&nbsp;{<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;CCmdUI state;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.m_nID=::GetWindowLong(*pWndChild, GWL_ID);<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.m_nIndex=iIndex++;<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.m_pOther=pWndChild;<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// ***CCmdUI::DoUpdate is undocumented MFC***<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;state.DoUpdate(this, FALSE);<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;pWndChild=pWndChild-&gt;GetWindow(GW_HWNDNEXT);<BR>&nbsp;&nbsp;&nbsp;&nbsp;}<BR><BR>&nbsp;&nbsp;&nbsp;&nbsp;// Must call the base class<BR>&nbsp;&nbsp;&nbsp;&nbsp;return CDialog::ContinueModal();<BR>}<BR><BR>BEGIN_MESSAGE_MAP(CCmdUIDialog, CDialog)<BR>&nbsp;&nbsp;&nbsp;&nbsp;//{{AFX_MSG_MAP(CCmdUIDialog)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// NOTE: the ClassWizard will add message map macros here<BR>&nbsp;&nbsp;&nbsp;&nbsp;//}}AFX_MSG_MAP<BR>END_MESSAGE_MAP()<BR><BR>/////////////////////////////////////////////////////////////////////////////<BR>// CCmdUIDialog message handlers<BR>注意:本类使用了MFC没有公开的成员函数CCmdUI::DoUpdate。<BR><BR>请参见一个例子:dialog\commandui_dialog目录。<BR><BR>第二种实现方法<BR>在不派生一个新类的情况下,重载下面两的函数中任一个函数:<BR><BR><BR>BOOL ::PreTranslateMessage( MSG* pMsg )<BR>{<BR>UpdateDialogControls( this, TRUE );<BR>return CDialog::PreTranslateMessage( pMsg );<BR>}<BR><BR>或者: <BR><BR><BR>BOOL ::ContinueModal( )<BR>{<BR>UpdateDialogControls( this, TRUE );<BR>return CDialog::ContinueModal( );<BR>}<BR><BR>注意:ContinueModal调用比PreTranslateMessage频繁五倍。<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -