MFC:文档中插入符号位置的更改如何调用 OnUpdateCmdUI?
我正在阅读有关工具栏的内容,并且遇到了这个
假设您从 CToolBar 派生了一个名为 CStyleBar 的工具栏类,其中包含一个组合框,其中包含系统中安装的所有字体的列表。当用户在文档中移动插入符号时,您需要更新组合框,以便其中选择的项目是当前插入符号位置处的字体名称。您可以重写 OnUpdateCmdUI,如下所示,而不是通过直接更新组合框选择来响应插入符位置的每个更改:
void CStyleBar::OnUpdateCmdUI (CFrameWnd* pTarget, BOOL bDisableIfNoHndler) { CToolBar::OnUpdateCmdUI (pTarget, bDisableIfNoHndler); CString string = GetTypefaceAtCaret (); if (m_wndComboBox.SelectString (-1, string) == CB_ERR) m_wndComboBox.SetCurSel (-1); }
因此,唯一让我困惑的是,如何通过文档调用移动插入符 OnUpdateCmdUI?如果它不调用
OnUpdateCmdUI
在文档中移动插入符还会调用什么?
如有任何帮助,我们将不胜感激。
问候。
I was reading about toolbars, and I came across this
Let's say you've derived a toolbar class named CStyleBar from CToolBar that includes a combo box with a list of all the fonts installed in the system. As the user moves the caret through a document, you want to update the combo box so that the item selected in it is the name of the typeface at the current caret position. Rather than respond to each change in the caret position by updating the combo box selection directly, you can override OnUpdateCmdUI as shown here:
void CStyleBar::OnUpdateCmdUI (CFrameWnd* pTarget, BOOL bDisableIfNoHndler) { CToolBar::OnUpdateCmdUI (pTarget, bDisableIfNoHndler); CString string = GetTypefaceAtCaret (); if (m_wndComboBox.SelectString (-1, string) == CB_ERR) m_wndComboBox.SetCurSel (-1); }
So, the only thing confusing me is, how come moving caret throught the document call OnUpdateCmdUI
? and if it doesn't calls OnUpdateCmdUI
what else does moving caret thru the document calls?
Any help is appreciated.
Regards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
移动插入符号不会调用 OnUpdateCmdUI。
根据《The MFC Answer Book》,当
CWinThread::Run()
发现没有更多消息需要处理时,调用CWinThread::OnIdle()
发送WM_IDLEUPDATECMDUI
消息发送到框架窗口及其所有子窗口。在执行了几个函数之后,CToolBar::OnUpdateCmdUI()
被调用。因此,移动插入符不会调用该函数。主循环在空闲时要求大型机及其子级更新它们的架子。
Moving the caret does not call OnUpdateCmdUI.
According to "The MFC Answer Book", when
CWinThread::Run()
finds there are no more messages to process, callsCWinThread::OnIdle()
which sendsWM_IDLEUPDATECMDUI
messages to the frame window and all of its children. After a couple more functions,CToolBar::OnUpdateCmdUI()
is called.So, moving the caret does not call the function. It's the main loop, when idle, who asks the mainframe and its children to update themshelves.