/* Example simple MFC program using Timer, CToolBar, CStatusBar, and CString classes. Mike Barnes */ #include #include // needed for CToolBar use #include "toolStatus.h" #include "resource.h" CtoolStatus_App toolStatusApp; // create an application framework const int myTimer = 1; // Must redefine InitInstance to initialize application BOOL CtoolStatus_App :: InitInstance () { m_pMainWnd = new CMainWindow; m_pMainWnd->ShowWindow (m_nCmdShow); m_pMainWnd->UpdateWindow(); return TRUE; } BEGIN_MESSAGE_MAP (CMainWindow, CFrameWnd) ON_WM_PAINT () ON_WM_TIMER () ON_CONTROL_RANGE(BN_CLICKED, ID_BUTTON40001, ID_BUTTON40004, OnButton) ON_COMMAND_RANGE (IDM_ABOUT, IDM_USAGE, OnHelp) END_MESSAGE_MAP () CMainWindow :: CMainWindow() { UINT nStatusBar; // CRect rect = new CRect(0,0,300, 300); color = RGB(0,0,0); Create (NULL, "toolStatus", WS_OVERLAPPEDWINDOW, rect, NULL, MAKEINTRESOURCE(IDR_MENU1)); m_wndToolBar.Create(this, WS_CHILD | WS_VISIBLE | CBRS_TOP | CBRS_FLYBY | CBRS_TOOLTIPS ); m_wndToolBar.LoadToolBar(IDR_TOOLBAR1); m_wndStatusBar.Create(this); // Status bar with two panes for text and set pane individually m_wndStatusBar.SetIndicators(&nStatusBar, 2); m_wndStatusBar.SetPaneInfo(0, ID_SEPARATOR, SBPS_NORMAL | SBPS_STRETCH, 0); m_wndStatusBar.SetPaneInfo(1, IDS_STRING40007, SBPS_NORMAL, 70); // set time for every 5 seconds SetTimer(myTimer, 1000, NULL); // after window create } void CMainWindow::OnPaint() { CPaintDC dc (this); CRect rect; GetClientRect(&rect); dc.SetBkColor(color); if (rect.right < 150 || rect.bottom < 150) return; dc.Rectangle(rect.left + 50, rect.top + 50, rect.right - 50, rect.bottom - 50); dc.FillSolidRect(rect.left + 75, rect.top + 75, (rect.right - 75) - (rect.left + 75), (rect.bottom - 75) - (rect.top + 75), color); } void CMainWindow::OnHelp(UINT nID) { if (nID == IDM_ABOUT) MessageBox("About menu"); else MessageBox("Usage menu"); } CString CMainWindow::makeMsg(CString msg, UINT i){ char tmsg[10]; _itoa(i, tmsg, 10); // converts and int to a string return (msg + " " + tmsg); } void CMainWindow::OnButton(UINT nId) { m_wndStatusBar.SetPaneText(0, makeMsg("On button", nId), TRUE); } void CMainWindow::OnTimer(UINT nTimerID) { static int count = 0, red = 64, green = 128, blue = 192; count = (count + 1) % 1000; red = (red + 8) % 256; green = (green + 16) % 256; blue = (blue + 32) % 256; color = RGB(red, green, blue); m_wndStatusBar.SetPaneText(1, makeMsg("On timer", count), TRUE); Invalidate(); // force window redraw }