Application window example
1 // Windows. the H file contains the data types and data structures required by the application. 2 # include <Windows. h> 3 # include <tchar. h> 4 5 lresult callback WndProc (HWND, UINT, WPARAM, LPARAM ); // Window Function Description 6 // -------------------------------- the following code of the entry function defaults 7 int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) 8 {9 WNDCLASSEX wcex; 10 HWND hWnd; 11 MSG msg; 12 TCHAR szWindowClass [] = L "window display For example, "; // window class name 13 TCHAR szTitle [] = L" My Windows "; // window title name 14 15 // ------------------------------ the following initialization window class ------------------------------ 16 wcex. cbSize = sizeof (WNDCLASSEX); // window class size 17 wcex. style = 0; // The window type is the default type 18 wcex. lpfnWndProc = WndProc; // The window processing function is WndProc19 wcex. cbClsExtra = 0; // window class no extension 20 wcex. cbWndExtra = 0; // window instance no extended 21 wcex. hInstance = hInstance; // the current instance handle 22 wcex. hIcon = LoadIcon (hInstance, MAKEINTRE SOURCE (IDI_APPLICATION); 23 // The Window icon is the default icon 24 wcex. hCursor = LoadCursor (NULL, IDC_ARROW); 25 // The cursor 26 wcex is used in the window. hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH); // The window background is white 27 wcex. lpszMenuName = NULL; // no menu in the window 28 wcex. lpszClassName = szWindowClass; // The window class name is "window example" 29 wcex. hIconSm = LoadIcon (wcex. hInstance, MAKEINTRESOURCE (IDI_APPLICATION); 30 // The small icon of the window is the default icon 31 32 // ---------------------------- The following is the registration of the window class- ----------------------------- 33 if (! RegisterClassEx (& wcex) // if the registration fails, a warning 34 {35 MessageBox (NULL, _ T ("window class registration failed! "), _ T (" window registration "), NULL); 36 return 1; 37} 38 // ------------------------------ the following creation window ---------------------------- 39 hWnd = CreateWindow (40 szWindowClass, // window class 41 szTitle, // window instance Title 42 WS_OVERLAPPEDWINDOW, // window style 43 CW_USEDEFAULT, CW_USEDEFAULT, // the coordinates in the lower left corner of the window are 44 CW_USEDEFAULT, CW_USEDEFAULT, // The window height and width are 45 by default NULL, // This window has no parent window 46 NULL, // This window has no main menu 47 hInstance, // create the current handle of this window application 48 NULL // do not use this value 49); 50 if (! HWnd) // if the window fails to be created, a warning 51 {52 MessageBoxW (NULL, L "failed to create the window! ", _ T (" create window "), NULL); 53 return 1; 54} 55 ShowWindow (hWnd, nCmdShow); // display window 56 UpdateWindow (hWnd ); // draw user Area 57 while (GetMessage (& msg, NULL, 0, 0) // message loop 58 {59 TranslateMessage (& msg); 60 DispatchMessage (& msg ); 61} 62 63 return (int) msg. wParam; // when the program ends, the information is returned to the system 64} 65 // ---------------------------- The following is the code of the Window Function Limit 66 lresult callback WndProc (HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) 67 {68 switch (message) 69 {70 case WM_DESTROY: 71 PostQuitMessage (0); // call PostQuitMessage to send the WM_QUIT message 72 break; 73 default: 74 return DefWindowProc (hWnd, message, wParam, lParam); 75 // default system message processing function 76 break; 77} 78 return 0; 79}