Tune function, message, and event routine

zhaozj2021-02-08  212

Tune function, message, and event routine

The calling mechanism has been used in a lot of use from the assembly era: preparing an outgoing code, and the caller can jump to the start address of this code, and then return the subsequent address when the jump is returned. The CPU prepares ready-made call instructions for this purpose. When calling the site, the field address is played from the stack after the call is completed to automatically return. It is a wonderful invention of the stack protection, which makes the caller and the adjusters without each other, so there is a later function and components, so that the program is so happy. If the selection is the most influential inventions of the human beings, after the fire and the wheel, the author is pushing the stack call. Although this is said that this call mechanism is not perfect. The callback function is an example. The function and other meals prepared for the caller, and its cooking deals with diners, but the truth is not the case. For example, write a quick sort function for others to call, which must contain a relatively small. Trouble coming: What data-integer, floating point, string? Thus, there is only a different sort function for each type of data. More password is to column a callback function address in the function parameters, and notify the caller: Jun must prepare a comparison function, which contain two pointer parameters, the function should compare the size of this two pointer index, and by Function Return Value Description Comparison Results. The sort function is relatively small, and the parameters are passed by the pointer, and the comparative data type can be fully compared. The caller is turned back to call the caller's function (sufficient bite), so it is called a callback. The callback function makes the program structure a lot. There are many callback functions in the Windows API function. Although there is a detailed description, the beginners still make the beginners fog. I am afraid this is also helpless. No matter what kind of things, it can be comfortable with the tree structure single-way description. If a grandchildren in a family is a ancest, I am afraid that no one can clarify the clue. But the complex data processing often needs to form a mesh structure, and non-simple client / server relationships can be exhausted. The Windows system also contains another more wide callback mechanism, namely a message mechanism. The message is the basic control means of Windows, and the watch is not related to the function call, it is actually a variable function call. The purpose of sending messages is to inform the recruitment to run a preparatory code, which is equivalent to calling a function. The WPARAM and LPARAM included with the message are equivalent to the parameters of the function, but more common than normal parameters. The application can actively send messages, more cases, waiting for Windows send messages. Once the message enters the message queue, those who are interested, jump to perform the corresponding message processing code. The operating system is called the application service, called by the application. Once the application is started, it will be in turn to wait for the call to the operating system. This is also a callback, or is a generalized callback. In fact, this callback can also be formed between the applications. If the process B receives the message sent by the process A, it starts a piece of code, which sends a message to the process A, which forms a callback. This kind of callback is more concealed, and it will not be able to recurrently call. If you deliberately write this recursive call, it is very interesting to terminate the conditions. But this program structure is too hidden unless it is necessary, it is still not necessary. Using messages can also be constituted a narrow callback. An example of the above-mentioned sorting function can be replaced with the callback function address to the window handle. Thus, when comparing data is required, the callback function is not called, but transmits a message to the specified window by using the API function sendMessage. Receiving the message party is responsible for comparing the data size, transmitting the comparison result to the message sender through the return value of the message itself.

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

New Post(0)