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 );
}