水月洞天
水激晟世,月浣環情;別有靈洞,亦預驚天!
1.在状态栏显示时钟。
在字符串表中加入一项ID_INDICATOR_TIMER.
修改indicators结构为:
static UINT indicators[] =
{
 ID_SEPARATOR,           // status line indicator
 ID_INDICATOR_TIMER,
};
在int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
函数中设置状态栏样式,
 UINT nID, nStyle;
 int cxWidth;
 m_wndStatusBar.GetPaneInfo(1,nID,nStyle,cxWidth);
 //m_wndStatusBar.SetPaneInfo(1,nID,SBPS_POPOUT,cxWidth);
 //m_wndStatusBar.SetPaneInfo(1,nID,SBPS_NOBORDERS,cxWidth);
 m_wndStatusBar.SetPaneInfo(1,nID,SBPS_NORMAL,cxWidth);
用Class Wizard为CMfc01View加入OnTimer(UINT nIDEvent)消息响应函数。
void CMfc01View::OnTimer(UINT nIDEvent)
{
 // TODO: Add your message handler code here and/or call default
 AfxGetApp()->OnIdle(0); //Call OnIdle(0), so the statusbar will be refreshed.
 CView::OnTimer(nIDEvent);
}
为新加的ID,ID_INDICATOR_TIMER映射一个消息响应函数:
void CMainFrame::OnShowTimer(CCmdUI *pCmdUI) {
 CTime t=CTime::GetCurrentTime();
 m_wndStatusBar.SetPaneText(m_wndStatusBar.CommandToIndex(ID_INDICATOR_TIMER),t.Format("%P %I:%M:%S"));
 //m_wndStatusBar.SetPaneText(0,"hello,can you see it?");
}
消息映射表中需加入:
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
 //{{AFX_MSG_MAP(CMainFrame)
 ...
 ON_UPDATE_COMMAND_UI(ID_INDICATOR_TIMER, OnShowTimer)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()
这样状态栏的第二部分就可以显示时间了。
posted on 2009-06-30 10:13  动力传说  阅读(1343)  评论(1编辑  收藏  举报