The MFC button controls whether the editing box displays the system time (Dynamic Display), and the mfc Display System

Source: Internet
Author: User

The MFC button controls whether the editing box displays the system time (Dynamic Display), and the mfc Display System

1. public in dlg. h

Bool flag;

Static UINT time (void * param );

2. In the constructor

Flag = false;


3. In the button generation function

If (flag)
{
Flag = false;
// GetDlgItem (IDC_ShowTime)-> SetWindowTextW (_ T (""));
/* M_showtime.SetWindowText (_ T (""));
M_showtime.SetFocus ();*/
// UpdateData (true );
CEdit * pedt = (CEdit *) GetDlgItem (IDC_ShowTime );
Pedt-> SetWindowText (_ T (""); // The editing box cannot be cleared, or cleared and restored.

// I don't know what's going on. If anyone knows, please let me know.
}
Else
{
AfxBeginThread (time, this); //, THREAD_PRIORITY_IDLE );

Flag = true;

}

4.

UINT CmyDlg: time (void * param)
{
CmyDlg * dlg = (CmyDlg *) param;
CEdit * incluimebox = (CEdit *) dlg-> GetDlgItem (IDC_ShowTime); // IDC_ShowTime is the edit box ID.
CString str;
While (dlg-> flag)
{
Sleep (1000 );
CTime time = CTime: GetCurrentTime ();
Str = time. Format (_ T ("% Y-% m-% d % H: % M: % S % "));
SysTimeBox-> SetWindowTextW (str );
}
Return 0;
}


The MFC editing box outputs the current system time.

CTime tm = CTime: GetCurrentTime ();
CString str1 = tm. Format ("% Y-% m-% d % H: % M: % S ");
SetDlgItemText (IDC_EDIT, str1); // IDC_EDIT is the ID of the edit box.

If you want to beat it, you can add a timer message response function.
Put the code in the timer message Response Function
Scheduled in the initialization dialog box
SetTimer (1, 1000, NULL); // The timer value is 1 s, and it will be as beat as a table

Can the content in the edit box of MFC be dynamically updated? I used the edit box control to display the system time. What should I do if I want it to automatically update as time changes?

Enable the Timer: SetTimer );
ClassWizard implements the OnTimer function in the dialog box and writes the following information to it:
If (1 = nIDEvent)
{
// Your above code
UpdateData (FALSE );

}

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.