MFC: how come change in caret postion in document calls 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.Moving the caret does not call OnUpdateCmdUI.
According to "The MFC Answer Book", when CWinThread::Run()
finds there are no more messages to process, calls CWinThread::OnIdle()
which sends WM_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.
精彩评论