To compare it with the process of creating a window in MFC, we also created a window in win api:
In other words, the process of creating a window using win api is indeed annoying.
1 /**/ /*
2 Create window in MFCProgramProcess:
3 1: Create an application class that inherits from cwinapp and create a global instance of this class.
4 2: create a window class inherited from wframewnd
5 3: declare the message processing process and message ing in the window class
6 4: Define the application class and specify the application Main Window in its entry function.
7 5. Define the window class, create the window itself in its constructor, and create related controls.
8 6. Add the event to be processed in message ing.
9 6. Implement Message Processing functions for window classes
10
11 The Windows API creation process is as follows:
12 Design a window class;
13 Registration window class;
14 Create window;
15 Display and update window.
16 */
17 # Include < Windows. h >
18 // Unique class name. Generally, GUID is used to avoid repeated class names with other programs.
19 // Static const char * class_name = l "{198ceab2-ad78-4ed3-b099-247639080cb0 }";
20 // Message Processing Method Pre-Reference
21 Lresult callback mywndproc (hwnd, uint umsg, wparam, lparam );
22
23 Int Winapi winmain (hinstance, hinstance hprevinstance, lpstr lpcmdline, Int Nshowcmd)
24 {
25 Wndclass;
26 Wndclass. cbclsextra = 0 ;
27 Wndclass. cbwndextra = 0 ;
28 Wndclass. hbrbackground = Reinterpret_cast < Hbrush > (Color_btnface + 1 );
29 Wndclass. hcursor = Loadicon ( 0 , Makeintresource (idi_winlogo ));
30 Wndclass. hicon = Loadicon (null, idi_error );
31
32 Wndclass. hinstance = Hinstance;
33 Wndclass. lpfnwndproc = Mywndproc; // Message Processing Function of the specified window
34 Wndclass. lpszclassname = L " Mywindow " ;
35
36 Wndclass. lpszmenuname = NULL;
37 Wndclass. Style = Cs_hredraw | Cs_vredraw;
38
39 Registerclass ( & Wndclass ); // Registration window class
40 // Create window
41 Hwnd = Createwindow (L " Xuzhize " , L " Mcjeremy " , Ws_overlappedwindow, 0 , 0 , 600 , 400 , Null, null, hinstance, null );
42 // Display window
43 Showwindow (hwnd, sw_shownormal );
44 Updatewindow (hwnd );
45
46 // Message Loop
47 MSG;
48 While (Getmessage ( & MSG, null, 0 , 0 ))
49 {
50 // Convert message Parameters
51 Translatemessage ( & MSG );
52 // Send and distribute messages
53 Dispatchmessage ( & MSG );
54 }
55 Return 0 ;
56 }
57
58 // Message Processing functions
59 // This function is defined by the application but not called by the application.
60 Lresult callback mywndproc (hwnd, uint umsg, wparam, lparam)
61 {
62 Switch (Umsg)
63 {
64 Case Wm_lbuttondown:
65 MessageBox (hwnd, l " Mouse clicked " , L " ASDFASDF " , 0 );
66 HDC;
67 HDC = Getdc (hwnd ); // Getdc obtains the device context of the current window. If no parameter is added, the context of the entire screen is displayed.
68 Textout (HDC, 0 , 50 , L " ASDFASDF " , Strlen ( " Asdfdfasdf " ));
69 Releasedc (hwnd, HDC ); // The DC obtained through getdc () and getwindowdc () requires releasedc () to be released.
70 // If you use createdc () or createwindowdc (), you must use deletedc () to release it.
71 Break ;
72 Case Wm_close:
73 If (Idyes = MessageBox (hwnd, l " End? " , L " Xxx " , Mb_yesno ))
74 {
75Destroywindow (hwnd );
76}
77 Break ;
78 Case Wm_destroy:
79 Postquitmessage ( 0 ); // If it is a "window destruction" event, it should be shipped in the Message Queue
80 Break ;
81 Default :
82 Return Defwindowproc (hwnd, umsg, wparam, lparam );
83 }
84 Return 0 ;
85 }