Window Type registration class, window type registration

Source: Internet
Author: User

Window Type registration class, window type registration

As you can see from the previous window program, this program mainly does three things: the first is the registration window, the second is the creation window, and the third is the display window. From the code of the program, it is easy to see what each function is doing. This is typically based on functional programming, and the cloud is like a flow. For small programs, this programming method is no problem. Now let's take a look at it. If you want to register multiple windows, create multiple windows and display multiple windows, and then use such function code, it is more difficult to reuse them. Therefore, with the development of programming technology and the increase of software projects, object-oriented programming is widely used. This allows you to easily design the registration, creation, and display of multiple windows. For example, you can encapsulate the registration window as a class. To create multiple windows, you can create multiple objects. An object is a data structure plus algorithm, so common objects have member variables and member functions. Whether or not object-oriented programming is not the language you use, but the idea you use in programming. As long as we use the data structure and algorithm encapsulation idea, we are using object-oriented programming. For example, if the C language does not support Object-Oriented Programming in Linux kernel programming, developers also use this idea in programming. Therefore, language support for Object-Oriented Programming is only a more convenient tool. It is not a key factor, but a developer's mindset rather than a tool. It also supports Object-Oriented Programming in Python, which has its own class definition method.

Window Type Registration

Let's take a look at the sample code as follows:

# Developer: Cai junsheng (QQ: 9073204) Shenzhen

# Window type registration
class WinClassMaker:    def __init__(self, wndProc, className, hInst):        self.wndClass = WNDCLASSEX()        self.wndClass.cbSize = sizeof(WNDCLASSEX)        self.wndClass.style = CS_HREDRAW | CS_VREDRAW        self.wndClass.lpfnWndProc = wndProc        self.wndClass.cbClsExtra = 0        self.wndClass.cbWndExtra = 0        self.wndClass.hInstance = hInst        self.wndClass.hIcon = 0        self.wndClass.hCursor = 0        self.wndClass.hBrush = windll.gdi32.GetStockObject(WHITE_BRUSH)        self.wndClass.lpszMenuName = 0        self.wndClass.lpszClassName = className        self.wndClass.hIconSm = 0    def Register(self):        return windll.user32.RegisterClassExW(byref(self.wndClass))

From this code, the class definition of Python starts with the keyword class, followed by the class name WinClassMaker, followed by a colon (:), and finally a code block of the class. The keywords in Python are the same as those in c ++, but their constructor, analysis constructor, and C ++ are quite different. The constructor of the Python class is the _ init _ function, and the Destructor is the _ del _ function. Constructor _ init _ is the first function automatically executed in a class. Therefore, most of the Code created is stored here, such as defining member variables. Destructor _ del _ is the final function automatically called in a class. It is mainly used to release occupied resources. A class has this attribute, which facilitates resource management, so that you forget to call the delete action after resource allocation, and submit the call time to the compiler for processing, this greatly improves the efficiency of developers and eliminates the need to worry about resource deletion. In addition, the reuse of classes is the reuse of data structures and functions. Because these functions are all written for these data structures, the error opportunities are also reduced. Finally, you can use the class to place the data structure in the class, as long as you use the function provided by it, so that when the function name remains unchanged, however, when the member variables of the class change and their algorithms change, the caller can not modify the code or perceive the changes.



In windows api, the registered window category is different from the window created

WM_TIMER has the lowest priority. Only no other messages in the queue are executed, while WM_PAINT has a higher priority.

Start from Window Creation:
Createdomainwex, which will directly deliver WM_CREATE to the window routine without entering the message queue. Other messages are normally transmitted through the message queue, then, use GetMessage and DispatchMessage to retrieve and distribute the message to the corresponding routine until WM_QUITE is obtained, and the message loop ends.
For buttons and mouse messages, the system queue is first entered, and then the system queue is distributed to the corresponding thread message queue.
Remember, message queues are all threads, not all windows and processes, except system queues.

What is the registration window class? What is a window handle? What is the message structure?

. In short, from the user's point of view
Is a rectangle area on the display screen. From the application's perspective, the window is a part of the rectangle shielding area under its control.
A class describes the characteristics of a group of similar objects. Use class. w5nd. Ws can create multiple objects,
That is, create multiple windows. You only need to use a copy of executable code that defines class functions.
The windows window class describes the class name and the address of the Zhoukou function used by all windows in the class. When
CKaIwind. When using the w function, you must specify the class, and the class features will be provided to the created Zhoukou.
Can Change wind. A collection of executable code and data loaded into the memory by ws. The windows module can be included in the executable
The file NAME must be the same as the NAME stated in the module definition file.
3. module definition file
The module definition file contains many declaration statements, which indicate the module name, type, segment usage, and introduction surface.
Number (the number of images must be introduced to the dynamic connection library ).
4. Extract function ()
A function in one module is referenced by another module. This function rod is called a derived function. For the content covered in this section
The function defined by the EXNRl3 statement in the module definition file is the derived function, that is, the "Callback
Function ".
5. instance ()
In WInd. In ws, one of the multiple copies that can be independently loaded into the module is called an instance. Wtndows can mount one
Multiple instances of applications.
Wind. Ws applications adapt to an arbitrary integer assigned by a specific metric (km ).
"Handle" to identify different items, including modules, instances, windows, memory blocks, and GDI objects.

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.