MFC通过button控制编辑框是否显示系统时间

在dlg.h中public

bool flag;

在构造函数中

flag=false;

在button的生成函数中

if(flag)
{
flag=false;
//m_showtime.SetWindowText(_T(""));
GetDlgItem(IDC_ShowTime)->SetWindowTextW(_T(""));   //IDC_ShowTime为编辑框ID


}
else
{

CTime time = CTime::GetCurrentTime();
CString str;
str = time.Format(_T("%Y-%m-%d %H:%M:%S %A"));
//SetWindowTextW(str);//,THREAD_PRIORITY_IDLE);
GetDlgItem(IDC_ShowTime)->SetWindowTextW(str);


flag=true;


}

原文地址:https://www.cnblogs.com/mthoutai/p/7401532.html