Tutorials to .com

Tutorials to .com » Software » Vc » Using VC + + in the status bar displays the clock

Using VC + + in the status bar displays the clock

Print View , by: iSee ,Total views: 34 ,Word Count: 562 ,Date: Tue, 25 Aug 2009 Time: 10:10 PM


In the VC's control, there is a Status bar in the form in the status bar to add the date and time. In fact, a simple code, you can create a clock displayed in the status bar, and also set the clock bar displayed. For example, as follows:
Firstly, by default MFC AppWizard to create a single document interface application framework.
Then, write code:
1) In the String Table added to New String, this is defined as ID_INDICATOR_CLOCK, its Caption set to 00:00:00 (due to the status bar pane, under the Caption to determine the default width of the time, using this value will be time for the display of pre - stay space). Note that this step operation in two ways:
A kind of create a new String Table, and add a String; and another in the original String Table added. When using the latter mode operation, if completed, the clock does not show the time bar, you need this New String in the String Table in the corresponding Value value plus 1 (which can be modified in resource.h).

...
static UINT indicators [] =
(
ID_SEPARATOR,
ID_INDICATOR_CLOCK,
ID_INDICATOR_CAPS,
ID_INDICATOR_NUM,
ID_INDICATOR_SCRL,
);
...
This step in the insertion position of ID_INDICATOR_CLOCK pane will affect the time display position in the status bar.
3) Install timer: In MainFrm.cpp add the code in OnCreate function is as follows:
int CMainFrame:: OnCreate (LPCREATESTRUCT lpCreateStruct)
(... ...
SetTimer (1,1000, NULL); / / install the timer, and its time interval set to 1000 ms return 0;
)
4) preparation of time to deal with a function: Using ClassWizard to CMainFrame class to join WM_TIMER message processing function OnTimer, and add the code to the following:
void CMainFrame:: OnTimer (UINT nIDEvent)
(/ / TODO: Add your message handler code here and / or call default
CTime time;
time = CTime:: GetCurrentTime ();// get the current time CString s = time.Format ( "% H:% M:% S ");// conversion time format m_wndStatusBar.SetPaneText (m_wndStatusBar.CommandToIn -
dex (ID_INDICATOR_CLOCK), s); / / display clock CFrameWnd:: OnTimer (nIDEvent);)
5) The destruction of the timer: Using ClassWizard to CMainFrame class to join WM_CLOSE message handler OnClose, and add the code to the following:
void CMainFrame:: OnClose ()
(/ / TODO: Add your message handler code here and / or call default
KillTimer (1); / / destroy the timer CFrameWnd:: OnClose ();)
Finally, compile run.
How kind, your clock is also a good bar. In addition, you can also call CStatusBar member function SetPaneStyle, SetPaneInfo to set your clock bar displayed. For example: In MainFrm. Cpp in the OnCreate function, add the following code, you can clock your column pop out:
int CMainFrame:: OnCreate (LPCREATESTRUCT lpCreateStruct)
(...
m_wndStatusBar.SetPaneInfo (m_wndStatusBar.CommandTo -
Index (ID_INDICATOR_CLOCK), ID_INDICATOR_CLOCK, SBPS_POPOUT, 50);
return 0;)
Learn how to add a clock, adding another pane are similar. In this way, you can arbitrarily customize their own status bar of the.


Visual C++ Tutorial Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.