evc如何调用和修改系统时间

来源:互联网 发布:淘宝大学官网网址 编辑:程序博客网 时间:2024/06/11 17:48

我建立了六个编辑框,想在每个编辑框中显示对应的年,月,日,时,分,秒

现在,我的做法如下,

以修改月份的为例:

void CParamSet1::OnSetfocusEdit16() //这个是用来修改月份的编辑框,当单击该编辑框时,即弹出输入数据对话框
{
 // TODO: Add your control notification handler code here
 datechange = false; //这个我是为了判断每次的输入是否按下ok键而定义的bool变量,若没按下,则输入肯定无效
 UpdateData(true);
 point_select=15; //该值没多大作用,只是我用来标示某个编辑对话框而设
    NumInput.DoModal(); //调用输入键盘,该键盘为我自己建立的,而非系统提供
 if(datetime>=10 && datetime<=120 && datechange)//若满足条件,则修改时间,这里,由于我将输入的每个数据默认扩大了10倍的,如果不用扩大,则为1到12之间,即表示输入的数据要在这二者之间,否则,无效
 {
  SYSTEMTIME st;//建立的时间变量
  GetLocalTime(&st);//获得计算机的区域时间
  st.wMonth = (int)(datetime*0.1);//datetime为我输入的数值,将该数据赋给st.wMonth
  SetLocalTime(&st);//将设置好的时间写回原来的地址
 }
// SetSystemTime(&st);
 UpdateData(FALSE);//刷新数据,使之及时显出 
}

 

另外,若要实时显示时间信息,还要在定时器中添加:

 GetLocalTime(&time);//这里,time为我建立的另一个SYSTEMTIME变量,m_Year等也是我建立的整形变量
 m_Year = (unsigned int)time.wYear;//这里年份应该是4位的,但默认是后两位,不影响大局,我没有改动
 m_Month = (unsigned int)time.wMonth;
 m_Day = (unsigned int)time.wDay;
 m_Hour = (unsigned int)time.wHour;
 m_Minute = (unsigned int)time.wMinute;
 m_Second = (unsigned int)time.wSecond;

 

最后,就要在初始化函数OnInitDialog中打开定时器SetTimer(1,500,NULL);//我的设置时0.5秒刷新一次

原创粉丝点击