Because of my memory is not very good, often forget to turn off the computer at night, wasted a lot of electricity. On the internet also found some time off the software, think of the recent oneself also learning VC + +, I want to write a timed shutdown of the small program, just can also test what they learn.
Program Source: Click to download
Let's take a look:
The writing is relatively simple, but as long as the function can be achieved.
To write a WIN32 application, you first have to have the WinMain function:
int Apientry _tWinMain (hinstance hinstance,
HInstance hPrevInstance,
LPTSTR lpCmdLine,
int nCmdShow)
{
Unreferenced_parameter (hprevinstance);
Unreferenced_parameter (lpCmdLine);
G_hinstance = hinstance;
DialogBox (HInstance, (LPCTSTR) Idd_main, NULL, Dlgproc);
return 0;
}
Call Dailogbox () in WinMain to bring up a dialog box, the following is the processing of the message.
INT_PTR CALLBACK Dlgproc (HWND hwnd, UINT umsg, WPARAM WPARAM, LPARAM LPARAM)
{
int wmid;
Switch (umsg)
{
Case WM_INITDIALOG:
G_hwnd = hWnd;
InitDialog ();
Break
Case WM_CLOSE:
Shell_NotifyIcon (Nim_delete, &g_nidtray);
EndDialog (hWnd, 0);
Break
Case Wm_timer:
Processtimer ();
Break
Case WM_SIZE:
if (WParam = = size_minimized)
{
ShowWindow (G_hwnd, sw_hide);
}
Break
Case Nw_shellnotify:
Switch (LParam)
{
Case WM_LBUTTONDBLCLK:
ShowWindow (G_hwnd, Sw_showdefault);
SetForegroundWindow (G_hwnd);
Break
Case WM_RBUTTONUP:
{
Point Ptposition;
GetCursorPos (&ptposition);
SetForegroundWindow (G_hwnd);
TrackPopupMenu (GetSubMenu (g_hmenu, 0), Tpm_leftalign | Tpm_leftbutton, ptposition.x, PTPOSITION.Y, 0, G_hwnd, NULL);
}
Break
}
Break
Case WM_COMMAND:
Wmid = LoWord (WParam);
Switch (WMID)
{
Case Idbtn_shutdown:
Datetime_getsystemtime (GetDlgItem (G_hwnd, Iddt_time), &g_stshutdown);
SetTimer (HWnd, Id_timer, +, NULL);
Changeenable (FALSE);
Break
Case Idbtn_cancel:
KillTimer (HWnd, Id_timer);
Updateremaintime (NULL);
Changeenable (TRUE);
Break
Case Idm_show:
ShowWindow (G_hwnd, Sw_showdefault);
SetForegroundWindow (G_hwnd);
Break
Case Idm_exit:
SendMessage (G_hwnd, wm_close, 0, 0L);
Break
Default
Return DefWindowProc (HWnd, umsg, WParam, LParam);
}
Break
}
return 0;
}
The main part is the above content, want to complete the program source code can be downloaded.
program Source: Click to download