Timed shutdown program written with Win32

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.