MFC中获取系统时间设为编辑框默认值

在进行一些设置时,由于需要输入的内容比较多,会显得十分繁琐,故通过获取系统时间并设置为Edit控件的默认值。

默认值的设置方式是通过建立虚函数,代码如下:

BOOL Reward::OnInitDialog()

{

  CDialog::OnInitDialog();

  CStringstr; //获取系统时间

   CTime tm;  //带头文件  #include

   tm=CTime::GetCurrentTime();   

 //  str=tm.Format("现在时间是%Y%m%d%X");

  str=tm.Format("%Y.%m");

  m_year_month=str;    //m_year_month为编辑框的变量名

  UpdateData(FALSE);

  returnTRUE;  // return TRUE unless you set thefocus to a control

                // EXCEPTION: OCX Property Pagesshould return FALSE

}​

建立虚函数的方式即通过在窗体中创建类向导构建。具体略。

猜你喜欢

转载自blog.csdn.net/PPPPluie/article/details/84879697