BOOL SetNewTime(WORD hour, WORD minutes)
{
SYSTEMTIME st;
char *pc;
GetSystemTime(&st); // gets current time
st.wHour = hour-8; // adjusts hours
st.wMinute = minutes; // and minutes
if (!SetSystemTime(&st)) // sets system time
{return FALSE;}
else
return TRUE;
}
void CMy1Dlg::OnOK()
{
// TODO: Add extra validation here
VC下测试:
void CMy1Dlg::OnOK()
{
// TODO: Add extra validation here
BOOL SetNewTime(WORD hour, WORD minutes)
{
SYSTEMTIME st;
char *pc;
GetSystemTime(&st); // gets current time
st.wHour = hour; // adjusts hours
st.wMinute = minutes; // and minutes
if (!SetSystemTime(&st)) // sets system time
return FALSE;
return TRUE;
}
SetNewTime(11,00);
CDialog::OnOK();
}
抱错:E:\fire\2324252562362626\1\1Dlg.cpp(177) : error C2601: 'SetNewTime' : local function definitions are illegal
错在那里啊?
Windows中有修改系统时间的API,是SetSystemTime。
例子:
// SetNewTime - sets system time
// Return value - TRUE if successful, FALSE otherwise
// hour - new hour (0-23)
// minutes - new minutes (0-59)
BOOL SetNewTime(WORD hour, WORD minutes)
{
SYSTEMTIME st;
char *pc;
GetSystemTime(&st); // gets current time
st.wHour = hour; // adjusts hours
st.wMinute = minutes; // and minutes
if (!SetSystemTime(&st)) // sets system time
return FALSE;
return TRUE;
}