求指点,我新手!
我新手,刚学,代码编译有点简单,大家别笑我想弄个定时关机,下面是代码,可是当时间到的时候没反映,怎么回事
#include "stdafx.h"
#include "time.h"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
}
return FALSE;
}
void CALLBACK TimerProc (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
SYSTEMTIME stLocal;
GetLocalTime(&stLocal);
TCHAR str1[256];
wsprintf(str1,TEXT("%u"),stLocal.wHour);
SetDlgItemText(hwnd,IDC_EDIT1,str1);
TCHAR str2[256];
wsprintf(str2,TEXT("%u"),stLocal.wMinute);
SetDlgItemText(hwnd,IDC_EDIT2,str2);
TCHAR str3[256];
wsprintf(str3,TEXT("%u"),stLocal.wSecond);
SetDlgItemText(hwnd,IDC_EDIT3,str3);
}
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
SetTimer(hwnd,0,1000,TimerProc);
return TRUE;
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_OK:
{
SYSTEMTIME stLocal;
GetLocalTime(&stLocal);
TCHAR str1[256];
wsprintf(str1,TEXT("%u"),stLocal.wHour);
TCHAR str2[256];
wsprintf(str2,TEXT("%u"),stLocal.wMinute);
TCHAR str3[256];
wsprintf(str3,TEXT("%u"),stLocal.wSecond);
TCHAR str6[256];
GetDlgItemText(hwnd,IDC_EDIT6,str6,sizeof(str1));
TCHAR str7[256];
GetDlgItemText(hwnd,IDC_EDIT6,str7,sizeof(str7));
TCHAR str8[256];
GetDlgItemText(hwnd,IDC_EDIT8,str8,sizeof(str8));
if(str6==str1,str7==str2,str3==str8)
ExitWindowsEx(EWX_SHUTDOWN,4);
}
break;
default:
break;
}
}
void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
#include "stdafx.h"
#include "time.h"
#include <windows.h>
#include <windowsx.h>
#include "resource.h"
#include "MainDlg.h"
BOOL WINAPI Main_Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch(uMsg)
{
HANDLE_MSG(hWnd, WM_INITDIALOG, Main_OnInitDialog);
HANDLE_MSG(hWnd, WM_COMMAND, Main_OnCommand);
HANDLE_MSG(hWnd,WM_CLOSE, Main_OnClose);
}
return FALSE;
}
void CALLBACK TimerProc (HWND hwnd, UINT message, UINT iTimerID, DWORD dwTime)
{
SYSTEMTIME stLocal;
GetLocalTime(&stLocal);
TCHAR str1[256];
wsprintf(str1,TEXT("%u"),stLocal.wHour);
SetDlgItemText(hwnd,IDC_EDIT1,str1);
TCHAR str2[256];
wsprintf(str2,TEXT("%u"),stLocal.wMinute);
SetDlgItemText(hwnd,IDC_EDIT2,str2);
TCHAR str3[256];
wsprintf(str3,TEXT("%u"),stLocal.wSecond);
SetDlgItemText(hwnd,IDC_EDIT3,str3);
}
BOOL Main_OnInitDialog(HWND hwnd, HWND hwndFocus, LPARAM lParam)
{
SetTimer(hwnd,0,1000,TimerProc);
return TRUE;
}
void Main_OnCommand(HWND hwnd, int id, HWND hwndCtl, UINT codeNotify)
{
switch(id)
{
case IDC_OK:
{
SYSTEMTIME stLocal;
GetLocalTime(&stLocal);
TCHAR str1[256];
wsprintf(str1,TEXT("%u"),stLocal.wHour);
TCHAR str2[256];
wsprintf(str2,TEXT("%u"),stLocal.wMinute);
TCHAR str3[256];
wsprintf(str3,TEXT("%u"),stLocal.wSecond);
TCHAR str6[256];
GetDlgItemText(hwnd,IDC_EDIT6,str6,sizeof(str1));
TCHAR str7[256];
GetDlgItemText(hwnd,IDC_EDIT6,str7,sizeof(str7));
TCHAR str8[256];
GetDlgItemText(hwnd,IDC_EDIT8,str8,sizeof(str8));
if(str6==str1,str7==str2,str3==str8)
ExitWindowsEx(EWX_SHUTDOWN,4);
}
break;
default:
break;
}
}
void Main_OnClose(HWND hwnd)
{
EndDialog(hwnd, 0);
}
...全文


