工具栏和状态栏

在OnInitDialog()函数中添加代码:

 1     if (!m_ToolBar.CreateEx(this, TBSTYLE_FLAT, WS_CHILD | WS_VISIBLE | CBRS_ALIGN_TOP | CBRS_GRIPPER | CBRS_TOOLTIPS, CRect(4, 4, 0, 0)) || !m_ToolBar.LoadToolBar(IDR_TOOLBAR1)) {
 2         return FALSE;
 3     }
 4     
 5     //加入状态栏显示
 6     if (!m_StatusBar.CreateEx(this) || !m_StatusBar.SetIndicators(indicators, sizeof(indicators) / sizeof(UINT))) {
 7         TRACE0("Failed to create status bar.");
 8         return -1;
 9     }
10     CRect rect;
11     GetClientRect(&rect);
12     m_StatusBar.SetPaneInfo(0, ID_INDICATOR_POS, SBPS_NORMAL, rect.Width() / 3);
13     m_StatusBar.SetPaneInfo(1, ID_INDICATOR_COLOR, SBPS_NORMAL, rect.Width() / 3);
14     m_StatusBar.SetPaneInfo(2, ID_INDICATOR_TIME, SBPS_STRETCH, rect.Width() / 3);
15     //重置工具条、状态栏
16     RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);

在定时器的OnTimer()函数中写如下代码:

 1 void C工具栏Dlg::OnTimer(UINT_PTR nIDEvent)
 2 {
 3     if (nIDEvent == 1) {
 4         //显示鼠标坐标信息
 5         CPoint pt;
 6         GetCursorPos(&pt);
 7         CString strPos;
 8         strPos.Format(_T("X=%d,Y=%d"), pt.x, pt.y);
 9         m_StatusBar.SetPaneText(0, strPos);
10         //显示鼠标所在位置颜色信息
11         HDC hDC = ::GetDC(NULL);
12         COLORREF ref = ::GetPixel(hDC, pt.x, pt.y);
13         CString strColor;
14         strColor.Format(_T("R=%d,G=%d,B=%d"), GetRValue(ref), GetGValue(ref), GetBValue(ref));
15         m_StatusBar.SetPaneText(1, strColor);
16         //显示系统当前时间
17         CTime time = CTime::GetCurrentTime();
18         CString strTime = time.Format(_T("%Y-%m-%d %H:%M:%S"));
19         m_StatusBar.SetPaneText(2, strTime);
20     }
21 
22     CDialogEx::OnTimer(nIDEvent);
23 }

猜你喜欢

转载自www.cnblogs.com/mktest123/p/12126584.html