WinMain function notes and winmain function notes

Source: Internet
Author: User

WinMain function notes and winmain function notes

1 # include <windows. h> 2 3 lresult callback WindowProc (4 _ In _ HWND hwnd, 5 _ In _ UINT uMsg, 6 _ In _ WPARAM wParam, 7 _ In _ LPARAM lParam 8 ); 9 10 int CALLBACK WinMain (11 _ In _ HINSTANCE hInstance, 12 _ In _ HINSTANCE hPrevInstance, 13 _ In _ LPSTR, 14 _ In _ int nCmdShow15) 16 {17 WCHAR * cls_Name = TEXT ("My Class"); 18 19 WNDCLASS wc ={}; 20 wc. hbrBackground = (HBRUSH) COLOR_WINDOW; 21 wc. lpfnWndProc = WindowProc; 22 wc. lpszClassName = cls_Name; 23 wc. hInstance = hInstance; 24 25 RegisterClass (& wc); 26 27 HWND hwnd = CreateWindow (28 cls_Name, // Class Name, 29 L "My applications", // window title text 30 WS_OVERLAPPEDWINDOW, // window appearance style 31 38, // The window is relative to the X coordinate of the parent level 32 20, // The window is relative to the Y coordinate of the parent level 33 480, // The window width is 34 250, // The window height is 35 NULL, // No parent window, NULL 36 NULL, // no menu, NULL 37 hInstance, // The instance handle of the current application 38 NULL); // No additional data, NULL 39 if (hwnd = NULL) 40 {41 return 0; 42} 43 44 ShowWindow (hwnd, SW_SHOW); 45 46 UpdateWindow (hwnd); 47 48 49 MSG; 50 while (GetMessage (& msg, NULL, 0, 0) 51 {52 TranslateMessage (& msg); 53 DispatchMessage (& msg); 54} 55 return 0; 56} 57 58 59 lresult callback WindowProc (60 _ In _ HWND hwnd, 61 _ In _ UINT uMsg, 62 _ In _ WPARAM wParam, 63 _ In _ LPARAM lParam64) 65 {66 switch (uMsg) 67 {68 case WM_DESTROY: 69 {70 PostQuitMessage (0); 71 return 0; 72} 73 default: 74 break; 75} 76 return DefWindowProc (hwnd, uMsg, wParam, lParam); 77} 78 79/* typedef struct tagWNDCLASS {80 UINT style; 81 WNDPROC lpfnWndProc; 82 int cbClsExtra; 83 int cbWndExtra; 84 HINSTANCE hInstance; 85 HICON hIcon; 86 HCURSOR hCursor; 87 HBRUSH hbrBackground; 88 LPCTSTR blocks; 89 LPCTSTR lpszClassName; 90} WNDCLASS, * PWNDCLASS ;*/

 

Parameters in winMain:
Hinstance-this parameter is the instance handle generated by Windows for the application. An instance is a pointer used to track resources.
The previous instance of hprevinstance is the parent program instance of the program.
Ipcmdline-command line parameters.
Ncmdshow indicates how to open a program window. The value of ncmdshow is generally used in ShowWindows () to set the form of creating a subwindow.

The parameter value can be:

SW_FORCEMINIMIZE: minimizes the window in WindowNT5.0, even if the thread that owns the window is suspended. This parameter is used when windows are minimized from other threads.

SW_HIDE: Hide the window and activate other windows.
SW_MAXIMIZE: Maximize the specified window.
SW_MINIMIZE: minimizes the specified window and activates the next top-level window in the Z sequence.
SW_RESTORE: activated and displayed in the window. If the window is minimized or maximized, the system restores the window to its original size and position. The flag should be specified by the application when the minimal window is restored.
SW_SHOW: the original size of the window is used to activate and display the window.
SW_SHOWDEFAULT: The display status is set based on the SW_FLAG flag specified in the STARTUPINFO structure. The STARTUPINFO structure is passed to the CreateProcess function by the program that starts the application.
SW_SHOWMAXIMIZED: Activate the window and maximize it.
SW_SHOWMINIMIZED: activates the window and minimizes it.
SW_SHOWMINNOACTIVE: the window is minimized, and the activation window remains active.
SW_SHOWNA: display the window in the original status. The activation window remains active.
SW_SHOWNOACTIVATE: displays the last window size and status. The activation window remains active.
SW_SHOWNORMAL: Activate and display a window. If the window is minimized or maximized, the system restores it to the original size and size. The application should specify this flag when displaying the window for the first time.

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.