"Windows programming" learning notes (1)

xiaoxiao2021-03-06  80

1. Declare a structural variable, generally use a structural lowercase as a variable name.

2. LP and NP are the same on 32 for the operating system.

3. The window is established according to a window category, and the window category is used to identify the window message handler for processing the window message.

Different windows can be established in accordance with the same window category. For example, all button windows in Windows - including buttons, check boxes, and radio buttons - are based on the same window category. The window category defines the window message handler and other features of the window established according to this category. When a window is created, you want to define some features unique to this window.

Before setting up a window for the program, you must first call the registerClass to register a window category. This function only requires a parameter, that is, a structural pointer that pointing to WNDCLASS. The most important thing in the Wndclass structure is the second and last parameters. The second field (lpfnWndProc) is the address of the window message handler used in all windows created in this category. In Hellowin.c, this is a WndProc function. The last field is the text name of the window category. Program writers can freely define their names. In a program that only establishes a window, the window category name is usually set to the program name.

4. The second field of the WNDCLASS structure is initialized by the following description:

WNDCLASS.LPFNWNDPROC = WNDPROC;

This narrative setting this window category window message handler is WNDPROC, ie the second function in Hellowin.c. This process will handle all messages for all windows established based on this window category. In the C language, when the function name is used in the structure, it is truly provided by the pointer to the function.

5. The painting is a drawing word, refers to the coloring style of one area. Windows has several standard paintings, also known as "STOCK" painting.

6. After initializing the 10 fields of the structure, hellowin calls registerclass to register this window category. This function has only one parameter, which is a pointer to the WNDCLASS structure. In fact, the RegisterClassa function will get a pointer to the WNDCLASSA structure.

7. In 32-bit Windows, HPREVINSTANCE is always NULL. This program code will be implemented normally, and it is actually not necessary to check HPREVINSTANCE.

8. MessageBoxw is one of several Unicode functions that can be performed in a Windows 98 environment. (Learn a little more)

9. Window Category Defines the general feature of the window, so many different windows can be established using the same window category. When you actually call the CREATEWINDOW to create a window, you may specify more detailed information about the window.

10. Windows programming newbies sometimes confuse the difference between window categories and windows, and why all features of a window cannot be set once. In fact, it is very convenient to separate these style information in this way. For example, all button windows can be established based on the same window category, and the window message handler related to this window category is located inside Windows. The window category is responsible for handling the keyboard and mouse input of the button, and defines the appearance image on the screen. From this point, all buttons work in the same way. But not all buttons are the same. They can have different sizes, different screen positions, and different strings. Some of the features later are part of the window definition instead of the window category definition. My understanding: It is actually like crude oil and various refined oil concepts. ^ _ ^

11. When establishing a "top" window, if the application window, comment is set to NULL as the "Parent Window Handle". Typically, if there is a parent child relationship between the window, the sub-window always appears above the parent window. The application window appears above the desktop window, but does not have to find the handle of the desktop window for call CREATEWINDOW.

12 .windows maintains a "message queue" for each Windows program currently executed. After the input event occurs, Windows converts the event into a "message" and puts the message into the program's message queue. As long as the Message field that removes the message from the message queue is not WM_QUIT (its value is 0x0012), GetMessage will pass a non-zero value. The WM_QUIT message will cause getMessage to pass 0.13. DispatchMessage (& MSG);

Also post the MSG structure to Windows. Then Windows sends the message to the appropriate window message handler to process it. That is to say, Windows will call the window message handler. In Hellown, this window message handler is the WndProe function. After processing the message, WndProc is returned to Windows. At this point, Windows also stays in the DispatchMessage call. After ending the DISPATCHMESSAGE call, Windows returns to Hellowin and then starts the message cycle from the next GetMessage call. (A bit like winding password -_!) 14. In Hellown, the window message handler is a function named WndProc (that is, window procedure). The window message handler can be named any (not conflicting with other names). A Windows program can contain multiple window message handles. A window message handler is always associated with a particular window category registered with the call registerclass. 15. Program usually does not directly call the window message handler, and the window message handler is usually called by the Windows itself. By calling the SendMessage function, the program can call its own window message handler directly. (A bit strange, stay) 16. The first message received by the window message handler - is also the first message for WndProc selection processing - is WM_CREATE. WNDPROC receives this message when Windows processes the CreateWindow function in WinMain. That is to say, when hellowin calls CREATEWINDOW, Windows will do some work that it must do. In these work, Windows calls WNDPROC, sets the first parameter to window handle, and the second parameter is set to WM_CREATE. WNDPROC processes the WM_CREATE message and transmits the control back to Windows. Windows can then pass back from the CreateWindow call to Hellowin and continue in WinMain to perform the next process. WNDPROC ends the entire WM_CREATE process by transmitting 0 from the window message handler. 17. The second message processed by WndProc is WM_PAINT. This message is very important in Windows programming. When a part of the window display area is displayed or all change to "invalid", it is necessary to "update the screen", will be notified by this message. How does the display of the display area become invalid? When the window is originally created, the entire display area is invalid because the program has not been drawn on the window. The first WM_PAINT message (usually when you call UpdateWindow in WinMain) Indicates that the window message handler draws something on the display area. After the user changed the size of the Hellowin window, the display area of ​​the display area is restarted. The reader should still remember that the style field of the Wndclass structure in Hellowin is set to the flag CS_HREDRAW and CS_VREDRAW, such a format setting indicates Windows, and after the window size changes, the entire window display content is invalid. Then, the window message handler will receive a WM_PAINT message. When the user minimizes Hellowin, then recover the window to the previous size, Windows will not save the contents of the display area. In a graphical environment, the amount of data involved in the window display area is large. Therefore, the Windows order window is invalid, the window message handler receives a WM_PAINT message and automatically restores the content of its window. When the window is overlapped, Windows does not save the content covered by another window. After this part is no longer covered, it is marked as invalid.

The window message handler receives a WM_PAINT message to update the content of the window. (This large section does not have a nonsense, it is a focus) 18. In the BeginPaint call, if the background of the display area has not been deleted, it is deleted by Windows. The entire display area is valid throughout the display area and is sent back to a "device content handle". The device content refers to an entity output device (e.g., a video display) and its device driver. Endpaint Release the device content handle to make it no longer valid. 19. getClientRect (hwnd, & respons); the first parameter is the handle of the program window. The second parameter is an indicator, pointing to the Rectangle structure of a RECT type. This structure has four long fields, which are left, TOP, Right, and Bottom. GetClientRect Sets the four fields to the size of the window display area. The LEFT and TOP fields are typically set to 0, the Right and the Bottom field are set to the width and height of the display area (the number of pixels points). (Khan! Finally knowing the specific meaning of Rect) 20. Once the display area becomes invalid (as in the case where the size of the occurs), WndProc will receive a new WM_PAINT message. WNDPROC has changed the changed window size by calling getClientRect and the text is displayed in the center of the new window. (Click the mouse on the window, will the mobile window do?) 21. Assume that the user performs Hellowin, and the user finally click on the Close button, or assumes that the keyboard or mouse is selected from the system menu, DefWindowProc processing This keyboard or mouse input, after detecting the user selected the Close option, it sends a WM_SYSCOMMAND message to the window message handler. WndProc passes this message to DEFWINDOWPROC. DefWindowProc Sends a WM_CLOSE message to the window message handler to respond. WndProc will pass it again to DefWindowProc. DESTROYWINDOW Call DestroyWindow (Isn't a write wrong?) To respond to this WM_CLOSE message. DestroyWindow causes Windows to send a WM_DESTROY message to the window message handler. WNDPROC calls PostquitMessage, put a WM_QUIT message into the message queue to respond to this message. This message causes the message loop in WinMain to end. 22. The message can be divided into "queue" and "non-queue". Queue messages are in the Windows in the program message queue. In the message loop of the program, it is retransmond and assigned to the window message handler. Non-queued messages directly to the window message handler when the Windows Call window. That is, the queue's message is "Send" to the message queue, not the queue, "Send" to the window message handler. Queue messages are basically the result of the user input to hit the key (such as a WM_KEYDOWN and WM_KEYUP messages), the characters generated by the keystroke (WM_CHAR), the mouse movement (WM_MOUSEMOVE), and the mouse button (WM_LButtondown) are given. Queue messages also include clock messages (WM_TIMER), update messages (WM_PAINT), and exit messages (WM_QUIT). Non-queen messages are other messages. In many cases, non-queen messages come from call specific Windows functions. For example, when WinMain calls CREATEWINDOW, Windows will create a window and send a WM_CREATE message to the window message handler in the process.

When WinMain calls ShowWindow, Windows will send WM_SIZE and WM_SHOWWINDOW messages to the window message handler. When WinMain calls UpdateWindow, Windows will send a WM_Paint message to the window message handler. The queue message signal issued when the keyboard or mouse input can also appear in the non-queue message. For example, when selecting a menu item with a keyboard or mouse, the keyboard or mouse message is queue, and the WM_COMMAND message selected by the menu item may be non-queue. 23. The message is different from the interrupt of the hardware when entering and exit in an ordered synchronization. When processing a message in a window message handler, the program will not be suddenly interrupted by other messages. 24. Although the Windows program can perform multi-threaded execution, the message queue per operative message is only for the window message handler executes the message executed in the execution. In other words, the message loop and window message handler are not executed concurrently. When a message loop receives a message from its message queue, then call DispatchMessage When sending the message to the window message handler until the window message handler converts the control back to Windows, DispatchMessage ends the execution. My understanding: Each thread has its own message queue, and a message queue is independent of each other. 25. Of course, the window message handler can call the window message handler to send another message function. At this time, the window message handler must complete the processing of the second message before the function call back. At that time, the window message handler will handle the initial message. For example, when the window procedure calls UpdateWindow, Windows handles the call window message handler to process the WM_PAINT message. After the window message handler processes the end of the WM_PAINT message, the UpdateWindow call will transmit the control back to the window message handler. call! Basically, it is here, the author's use is very refined, some difficulties have to go back and see. Harvest is still quite a lot ^ _ ^

转载请注明原文地址:https://www.9cbs.com/read-120847.html

New Post(0)