[这个贴子最后由默数悲伤在 2006/02/24 11:34pm 第 1 次编辑]
#include
#include
#include "resource.h"
DWORD hour = 0;
DWORD minu = 0;
void rTHREAD()
{SYSTEMTIME st;
while(TRUE)
{GetLocalTime( &st );
if( (st.wHour == hour)&&(st.wMinute == minu))
break;
else
Sleep(1);
}
HANDLE hToken;
TOKEN_PRIVILEGES tkp;
if(!OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES|TOKEN_QUERY,&hToken))
return;
LookupPrivilegeValue(NULL,SE_SHUTDOWN_NAME,&tkp.Privileges[0].Luid);
tkp.PrivilegeCount=1;
tkp.Privileges[0].Attributes=SE_PRIVILEGE_ENABLED;
AdjustTokenPrivileges(hToken,FALSE,&tkp,0,(PTOKEN_PRIVILEGES)NULL,0);
InitiateSystemShutdown(
NULL,
NULL,
0,
TRUE,
FALSE
);
CloseHandle( hToken );
return;
}
void Dlg_OnCommand(HWND hwnd,UINT wNotifyCode,int wID,HWND hwndCtl)
{
switch(wID)
{
case IDCANCEL:
EndDialog(hwnd,wID);
break;
case IDOK:
hour=GetDlgItemInt(hwnd,IDC_EDIT2,NULL,FALSE);
minu=GetDlgItemInt(hwnd,IDC_EDIT3,NULL,FALSE);
}
}
BOOL Dlg_OnInitDialog(HWND hwnd,HWND hwndFocus,LPARAM lParam)
{
CreateThread(
NULL,
0,
(LPTHREAD_START_ROUTINE)rTHREAD,
NULL,
0,
NULL);
SendMessage(hwnd,WM_SETICON,ICON_BIG,(LPARAM)LoadIcon((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),MAKEINTRESOURCE(IDI_ICON1)));
SendMessage(hwnd,WM_SETICON,ICON_SMALL,(LPARAM)LoadIcon((HINSTANCE)GetWindowLong(hwnd,GWL_HINSTANCE),MAKEINTRESOURCE(IDI_ICON1)));
return(TRUE);
}
BOOL CALLBACK DialogProc(
HWND hwndDlg, // handle to dialog box
UINT uMsg, // message
WPARAM wParam, // first message parameter
LPARAM lParam // second message parameter
)
{
switch(uMsg)
{
case WM_INITDIALOG:
SetWindowLong(hwndDlg,DWL_MSGRESULT,(LONG)Dlg_OnInitDialog(hwndDlg,(HWND)wParam,lParam));
case WM_COMMAND:
Dlg_OnCommand(hwndDlg,HIWORD(wParam),LOWORD(wParam),(HWND)lParam);
break;
}
return(FALSE);
}
int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE,LPSTR lpCmdLine,int nShowCmd)
{
DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),NULL,DialogProc);
return (0);
}
//rc
//Microsoft Developer Studio generated resource script.
//
#include "resource.h"
#define APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 2 resource.
//
#include "afxres.h"
/////////////////////////////////////////////////////////////////////////////
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// Chinese (P.R.C.) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_CHS)
#ifdef _WIN32
LANGUAGE LANG_CHINESE, SUBLANG_CHINESE_SIMPLIFIED
#pragma code_page(936)
#endif //_WIN32
#ifdef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// TEXTINCLUDE
//
1 TEXTINCLUDE DISCARDABLE
BEGIN
"resource.h\0"
END
2 TEXTINCLUDE DISCARDABLE
BEGIN
"#include ""afxres.h""\r\n"
"\0"
END
3 TEXTINCLUDE DISCARDABLE
BEGIN
"\r\n"
"\0"
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Dialog
//
IDD_DIALOG1 DIALOG DISCARDABLE 100, 100, 115, 34
STYLE DS_MODALFRAME | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "定时关机"
FONT 10, "System"
BEGIN
PUSHBUTTON "ok",IDOK,68,14,42,12
EDITTEXT IDC_EDIT2,3,14,18,12,ES_AUTOHSCROLL | ES_NUMBER
EDITTEXT IDC_EDIT3,34,14,17,13,ES_AUTOHSCROLL | ES_NUMBER
LTEXT "时",IDC_STATIC,22,15,10,10
LTEXT "分",IDC_STATIC,55,15,14,11
END
/////////////////////////////////////////////////////////////////////////////
//
// DESIGNINFO
//
#ifdef APSTUDIO_INVOKED
GUIDELINES DESIGNINFO DISCARDABLE
BEGIN
IDD_DIALOG1, DIALOG
BEGIN
TOPMARGIN, 7
END
END
#endif // APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Icon
//
// Icon with lowest ID value placed first to ensure application icon
// remains consistent on all systems.
IDI_ICON2 ICON DISCARDABLE "icon1.ico"
#endif // Chinese (P.R.C.) resources
/////////////////////////////////////////////////////////////////////////////
#ifndef APSTUDIO_INVOKED
/////////////////////////////////////////////////////////////////////////////
//
// Generated from the TEXTINCLUDE 3 resource.
//
/////////////////////////////////////////////////////////////////////////////
#endif // not APSTUDIO_INVOKED
点击源文件 |