MFC教程(13)-- MFC工具条和状态栏(2)
2007-03-18 21:29:40 来源:WEB开发网核心提示:消息WM_POPMESSAGESTRING用来重新设置状态栏,这两个消息对应的消息处理函数分别是OnSetMessageString和OnPopMessageString,MFC教程(13)-- MFC工具条和状态栏(2),OnSetMessageString和OnPopMessageString分别实现如下:OnSe
消息WM_POPMESSAGESTRING用来重新设置状态栏。
这两个消息对应的消息处理函数分别是OnSetMessageString和OnPopMessageString,OnSetMessageString和OnPopMessageString分别实现如下:
OnSetMessageString
LRESULT CFrameWnd::OnSetMessageString(WPARAM wParam, LPARAM lParam)
{
//最近一次被显示的消息字符串IDS(一个消息对应的字符串)
UINT nIDLast = m_nIDLastMessage;
m_nFlags &= ~WF_NOPOPMSG;
//得到状态栏
CWnd* pMessageBar = GetMessageBar();
if (pMessageBar != NULL)
{
LPCTSTR lpsz = NULL;
CString strMessage;
//设置状态栏文本
if (lParam != 0) //指向一个字符串
{
ASSERT(wParam == 0); // can't have both an ID and a string
lpsz = (LPCTSTR)lParam; // set an explicit string
}
else if (wParam != 0)//一个字符串资源IDS
{
//打印预览时映射SC_CLOSE成AFX_IDS_PREVIEW_CLOSE;
if (wParam == AFX_IDS_SCCLOSE && m_lpfnCloseProc != NULL)
wParam = AFX_IDS_PREVIEW_CLOSE;
//得到资源ID所标识的字符串
GetMessageString(wParam, strMessage);
lpsz = strMessage;
}
//在状态栏中显示文本
pMessageBar->SetWindowText(lpsz);
// 根据最近一次选择的消息更新状态条所属窗口的有关记录
CFrameWnd* pFrameWnd = pMessageBar->GetParentFrame();
if (pFrameWnd != NULL)
{
//记录最近一次显示的消息字符串
pFrameWnd->m_nIDLastMessage = (UINT)wParam;
//记录最近一次Tracking的命令ID和字符串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;
}
OnSetMessageString函数直接或者从ID从字符串资源中得到字符串指针。如果是从ID得到字符串指针,则函数GetMessageString被调用。
更多精彩
赞助商链接