C language implementation interface (do not use MFC \ To avoid forgetting), mfc

Source: Internet
Author: User
Tags textout

C language implementation interface (do not use MFC \ To avoid forgetting), mfc

I feel that MFC is not a programmer's detail, and the basic interface is implemented today to avoid forgetting it later.

Source code:

# 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 a window
HWnd = CreateWindow ("Hello Win", "Timed Shutdown -- junmuzi", WS_OVERLAPPEDWINDOW, CW_USEDEFAULT, NULL, NULL, hInstance, NULL );
// Display window
ShowWindow (hWnd, nCmdShow );
// Update window
UpdateWindow (hWnd );
// Enter the message loop: when the message retrieved from the application message queue is WM_QUIT, a cycle is introduced.
While (GetMessage (& Msg, NULL, 0, 0 ))
{
TranslateMessage (& Msg); // converts keyboard messages
DispatchMessage (& Msg); // resend the message
}
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, hWnd, NULL );
HWndEdit_minute = CreateWindow ("edit", NULL, WS_CHILD | WS_VISIBLE | WS_BORDER, 180,60, 100,25, hWnd, NULL );
HWndButton_ OK = CreateWindow ("button", "OK", WS_CHILD | WS_VISIBLE | WS_BORDER, 340, 60,100, 25, hWnd, NULL );
HWndButton_cancel = CreateWindow ("button", "cancel Timed Shutdown", WS_CHILD | WS_VISIBLE | WS_BORDER, 460, 60,100, 25, hWnd, NULL );
Return 0;
Case WM_COMMAND:
If (HWND) lParam = hWndButton_ OK) & (HIWORD (wParam) = BN_CLICKED ))
// Press hWndButton_ OK
{
Num_text_hour = GetWindowText (hWndEdit_hour, strEdit_hour, 10); // obtain the hour content of the edit box control.
// Sprintf (str, "The result is: % s", strEdit_hour );
// Sprintf (hour, "% s", strEdit_hour );
If (num_text_hour = 0)
{
MessageBox (NULL, "The hour cannot be blank! "," Error message: ", MB_ OK );
}
Num_text_minute = GetWindowText (hWndEdit_minute, strEdit_minute, 10); // obtain the content of the edit box control minute
If (num_text_minute = 0)
{
MessageBox (NULL, "the minute cannot be blank! "," Error message: ", MB_ OK );
}
If (! (Atoi (strEdit_hour)> = 0) & (atoi (strEdit_minute)> = 0) & (atoi (strEdit_minute) <= 60 )))
{
MessageBox (NULL, "illegal input (input hour must be greater than or equal to 0, input minute 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 (strEdit_minute)> = 0) & (atoi (strEdit_minute) <= 60 ))
{
Num = atoi (strEdit_hour) * 3600 + atoi (strEdit_minute) * 60; // The number of seconds for converting the hour and minute
// 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 % 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 hour % s Minutes !!! ", StrEdit_hour, strEdit_minute );
System (cmd); // shutdown the computer.
InvalidateRect (hWnd, NULL, TRUE );
}
}
If (HWND) lParam = hWndButton_cancel) & (HIWORD (wParam) = BN_CLICKED ))
// Press hWndButton_cancel.
{
Sprintf (cmd, "shutdown-a"); // cancel Timed shutdown
Sprintf (str, "shutdown is canceled at a specified time !!! ");
System (cmd); // cancel "shutdown the computer".
InvalidateRect (hWnd, NULL, TRUE );
}
Case WM_PAINT: // design edit box
HDC = BeginPaint (hWnd, & Ps );
TextOut (hDC, 10, 10, "Enter the time after which you want to set Shutdown (hours and minutes):", 48 );
TextOut (hDC, "Hour", 4 );
TextOut (hDC, "Minute", 4 );
// TextOut (hDC, 10, 90, str, strlen (str ));
TextOut (hDC, 10, 90, str, strlen (str ));
EndPaint (hWnd, & Ps );
Return 0;
Case WM_DESTROY:
PostQuitMessage (0 );
Return 0;
}
Return DefWindowProc (hWnd, message, wParam, lParam );
}

 

// Program for automatic shutdown

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.