MFC Tutorial-mfc toolbar and status bar (2)

Source: Internet
Author: User
Tags assert exit resource

Message wm_popmessagestring is used to reset the status bar.

The message processing functions for these two messages are onsetmessagestring and onpopmessagestring,onsetmessagestring and onpopmessagestring, respectively, as follows:

Onsetmessagestring
Lresult cframewnd::onsetmessagestring (WPARAM WPARAM, LPARAM LPARAM)
{
Last displayed message string IDs (a string corresponding to a message)
UINT nidlast = m_nidlastmessage;
M_nflags &= ~wf_nopopmsg;
Get status bar
cwnd* Pmessagebar = Getmessagebar ();
if (Pmessagebar!= NULL)
{
LPCTSTR lpsz = NULL;
CString strmessage;
Set status bar text
if (lParam!= 0)//point to a string
{
ASSERT (wParam = 0); Can ' t have both an ID and a string
Lpsz = (LPCTSTR) LParam; Set an explicit string
}
else if (wParam!= 0)//a string resource IDs
{
Map Sc_close into afx_ids_preview_close when printing preview;
if (WParam = = Afx_ids_scclose && m_lpfncloseproc!= NULL)
WParam = Afx_ids_preview_close;
Gets the string identified by the resource ID
Getmessagestring (WParam, strmessage);
Lpsz = strmessage;
}
Display text in the status bar
Pmessagebar->setwindowtext (LPSZ);
Updates the record of the window to which the status bar belongs based on the most recently selected message
cframewnd* Pframewnd = Pmessagebar->getparentframe ();
if (Pframewnd!= NULL)
{
Record the last message string displayed
Pframewnd->m_nidlastmessage = (UINT) WParam;
Log the last tracking command ID and string IDs
pframewnd->m_nidtracking = (UINT) WParam;
}
}
M_nidlastmessage = (UINT) WParam; New ID (or 0)
m_nidtracking = (UINT) WParam; So F1 on toolbar buttons work
return nidlast;
}

The Onsetmessagestring function obtains a string pointer from the string resource either directly or from the ID. If you get a string pointer from an ID, the function getmessagestring is called.

The string corresponding to the command ID is made up of two parts, the first of which is displayed in the status bar, and the latter part is used for ToolTip display, and the separator symbol is "". For example, the string id_app_exit (corresponding to "Exit" menu, Button) is "Exit application Exit", when the mouse falls on the "Exit" button, the status bar displays "Exit Application", ToolTip shows "exit". According to this format, getmessagestring separates the first part of the text information. The use of the second part will be used in the discussion of the ToolTip section.

After the string is obtained, onsetmessagestring calls the SetWindowText function of the status bar. SetWindowText causes the message Wm_settext message to be sent to the status bar, and the message handler function of the status bar Onsettext called, which is actually equal to calling SetPaneText (0, lpsz), which displays the string lpsz information in the No. 0 pane of the status bar. For toolbars, SetWindowText can be considered a simplified version of SetPaneText (0, lpsz).

Incidentally, Pmessagebar->getparentframe () returns to the main border window even if pmessagebar points to a floating toolbar. For berths and floats, see the description in Section 13.2.5 below.

With regard to Onsettext, it is implemented as follows:

LRESULT CStatusBar::OnSetText(WPARAM, LPARAM lParam)
{
ASSERT_VALID(this);
ASSERT(::IsWindow(m_hWnd));
int nIndex = CommandToIndex(0); //返回0
if (nIndex < 0)
return -1;
return SetPaneText(nIndex, (LPCTSTR)lParam) ? 0 : -1;
}
OnPopMessageString
LRESULT CFrameWnd::OnPopMessageString(WPARAM wParam,
LPARAM lParam)
{
//WF_NOPOPMSG表示边框窗口不处理WM_POPMESSAGESTRING
if (m_nFlags & WF_NOPOPMSG)
return 0;
//调用OnSetMessageString
return SendMessage(WM_SETMESSAGESTRING, wParam, lParam);
}

Generally, when the status bar message is cleared, the wm_popmessagestring is sent and a string resource is specified with the message parameter wparam, whose ID is afx_ids_idlemessage and the corresponding string is "Ready".

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.