C Language Implementation interface (without mfc\ to avoid forgetting)

Source: Internet
Author: User

I feel MFC does not belong to the programmer scrutiny things, this implementation of the basic interface to avoid future forgetting.

Source:

#include <windows.h>
#include <stdio.h>
Char str[] = {' 0 '};
Char cmd[] = {' 0 '};
Char hour[10], minute[10];
int num;
int Num_text_hour, Num_text_minute;
Char num_str[];
LRESULT CALLBACK WndProc (Hwnd,uint,wparam,lparam);
int WINAPI WinMain (hinstance hinstance,hinstance hprevinstance, LPSTR lpcmdline,int ncmdshow)
{
HWND hwnd;
MSG msg;
Wndclass Wndclass;
Wndclass.style=cs_hredraw|cs_vredraw;
Wndclass.lpfnwndproc=wndproc;
wndclass.cbclsextra=0;
wndclass.cbwndextra=0;
Wndclass.hinstance=hinstance;
Wndclass.hicon=loadicon (null,idi_application);
Wndclass.hcursor=loadcursor (Null,idc_arrow);
Wndclass.hbrbackground= (Hbrush) getstockobject (White_brush);
Wndclass.lpszmenuname=null;
Wndclass.lpszclassname= "Hello Win"; Window class name
Registration window
if (! RegisterClass (&wndclass))
{
MessageBox (NULL, "Window registration failed!", "Hello Win", 0);
return 0;
}
Create window
Hwnd=createwindow ("Hello Win", "Timed shutdown--junmuzi", Ws_overlappedwindow, Cw_usedefault, Cw_usedefault, Cw_usedefault, CW_ Usedefault, NULL, NULL, HINSTANCE, NULL);
Display window
ShowWindow (hwnd,ncmdshow);
Update window
UpdateWindow (HWND);
Enter the message loop: When the message picked up from the application message queue is Wm_quit, the loop is rolled out
while (GetMessage (&msg,null,0,0))
{
TranslateMessage (&AMP;MSG); converting keyboard messages
DispatchMessage (&AMP;MSG); Distributing messages
}
return msg.wparam;
}


LRESULT CALLBACK WndProc (HWND hwnd,uint message,wparam wparam,lparam LPARAM)
{
HDC hdc;
Paintstruct Ps;
Char stredit_hour[10], stredit_minute[10];
Static HWND Hwndbutton_ok, Hwndbutton_cancel, Hwndedit_hour, Hwndedit_minute;
Switch (message)
{
Case WM_CREATE:
Hwndedit_hour = CreateWindow ("edit", null,ws_child| ws_visible| Ws_border,10,60,100,25,hwnd,null,null,null);
Hwndedit_minute = CreateWindow ("edit", null,ws_child| ws_visible| Ws_border,180,60,100,25,hwnd,null,null,null);
HWNDBUTTON_OK = CreateWindow ("button", "OK", ws_child| ws_visible| Ws_border, 340, hwnd,null,null,null);
Hwndbutton_cancel = CreateWindow ("button", "Cancel timer shutdown", ws_child| ws_visible| Ws_border, 460, hwnd,null,null,null);
return 0;
Case WM_COMMAND:
if ((HWND) LPARAM==HWNDBUTTON_OK) && (HiWord (WParam) ==bn_clicked))
Press the key HWNDBUTTON_OK
{
Num_text_hour = GetWindowText (hwndedit_hour,stredit_hour,10); Get the contents of the edit box control hour
sprintf (str, "The result is:%s", stredit_hour);
sprintf (Hour, "%s", Stredit_hour);
if (Num_text_hour = = 0)
{
MessageBox (NULL, "hours cannot be empty!", "error message:", MB_OK);
}
Num_text_minute = GetWindowText (hwndedit_minute,stredit_minute,10); Get the contents of the edit box control minute
if (Num_text_minute = = 0)
{
MessageBox (NULL, "minutes cannot be empty!", "error message:", MB_OK);
}
if (! ( (Atoi (Stredit_hour) >= 0) && (atoi (Stredit_minute) >= 0) && (atoi (stredit_minute) <= 60)))
{
MessageBox (NULL, "illegal input (the input hour must be greater than or equal to 0, the entered minutes must be greater than or equal to 0, and less than or equal to 60)", "error message:", MB_OK);
}
if (Num_text_hour! = 0) && (num_text_minute! = 0) && (atoi (Stredit_hour) >= 0) && (atoi (Stredi T_minute) >= 0) && (atoi (stredit_minute) <= 60))
{
num = atoi (stredit_hour) * 3600 + atoi (stredit_minute) * 60; Turn the hours and minutes into the number of seconds
Itoa (num, num_str, 10);
sprintf (str, "The result is:%s", Stredit_minute);
sprintf (Minute, "%s", Stredit_minute);
strcat (cmd, str_);
sprintf (cmd, "shutdown-s-T%s%s%d", Stredit_hour, Stredit_minute, num);
sprintf (cmd, "shutdown-s-t%d", num); Timed Shutdown command
sprintf (str, "The computer will shut down after%s minutes after ", Stredit_hour, Stredit_minute);
System (CMD); Shutdown the computer.
InvalidateRect (hwnd,null,true);
}
}
if ((HWND) LParam = = Hwndbutton_cancel) && (HiWord (wParam) = = bn_clicked))
Press the key Hwndbutton_cancel
{
sprintf (cmd, "shutdown-a"); Cancel timed shutdown
sprintf (str, "Computer timed off is canceled!!!" ");
System (CMD); Cancel "shutdown the computer".
InvalidateRect (hwnd,null,true);
}
Case wm_paint://Design edit box
Hdc=beginpaint (HWND,&AMP;PS);
TextOut (hdc,10,10, "Please enter how long you want to set up after shutdown (hours and minutes):", 48);
TextOut (hdc,120,60, "Hour", 4);
TextOut (hdc,290,60, "minute", 4);
TextOut (Hdc,10,90,str,strlen (str));
TextOut (Hdc,10,90,str,strlen (str));
EndPaint (HWND,&AMP;PS);
return 0;
Case Wm_destroy:
PostQuitMessage (0);
return 0;
}
return DefWindowProc (Hwnd,message,wparam,lparam);
}

Programs that enable automatic shutdown

C Language Implementation interface (without mfc\ to avoid forgetting)

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.