MFC single-document taskbar adding system time

Source: Internet
Author: User

Creation of the status bar: CStatusBar object creation Call the CREATE function creates a status bar

if (!m_wndstatusbar.create (this))
{
TRACE0 ("Failed to create status bar\n");
return-1; Fail to create
}

Call SetIndicators to append a string resource ID to each indicator:

M_wndstatusbar.setindicators (indicators, sizeof (indicators)/sizeof (UINT));

Static UINT indicators[] =
{
Id_separator,//Status line indicator
Id_indicator_caps,
Id_indicator_num,
ID_INDICATOR_SCRL,
Ids_timer,
Ids_progress,

...//Here the string resource is added to the status bar
};

Added in the frame WM_PAINT message corresponding function OnPaint

SetTimer (1000,1000,null);

To capture the Wm_timer message, add the following code to the OnTimer function

CTime time=ctime::getcurrenttime ();//Returns a CTime object through a static method
CString Str=time. Format ("%h:%m:%s"); Format time to Str
CCLIENTDC DC (this); Create a DC for a framework class
CSize SIZE=DC.  GetTextExtent (str); Get the dimensions that appear on the screen in a string
int index =m_wndstatusbar.commandtoindex (ids_timer); Get an index by ID
M_wndstatusbar.setpaneinfo (INDEX,IDS_TIMER,SBPS_NORMAL,SIZE.CX); Set the width of the indicator
M_wndstatusbar.setpanetext (INDEX,STR); Sets the text of the specified index indicator

MFC single-document taskbar adding system time

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.