We often make some applications (such as timer event callback processing, recording actions with callback functions, etc.) when designing the callback function, so that its inner mechanism is, how is it defined? ? Is it different from other functions (such as hook functions)? Here is a simple introduction to your own experience.
Using the callback function is actually when a function is called (usually an API function), the address of one of its functions (this function is a callback function) is passed to that function. And that function is required to call the callback function using the delivered address, then you can use this opportunity to process messages in the callback function or complete a certain action. As for how to define the callback function, it is related to the specific API function, generally in the help, the parameters and return values of the callback function. C generally requires Callback before the callback function, which is mainly to explain the call mode of the function.
As for the hook function, just a special case of the callback function. It is used to refer to the callback function used with the setWindowsHooKex function as the hook function. Some people use the function that uses the VirtualQueryEx installed as hook functions, but this called is not popular.
It can also be more likely to understand that the callback function is like an interrupt processing function, and the system is automatically called when it meets the conditions you set. To this end, you need to do three things:
Declaration;
2. Definition;
3. Set the trigger condition, which is transformed into the address as a parameter in your function to make the system call.
Note and definition should pay attention to: The callback function is called by the system, so it can be considered to be a Windows system, do not treat it as a member of your class.
Specifies the callback function as a parameter of a function, this function is called by the function, such as ... enumchildWindows (hwnd, enumchildproc, null); ...
Bool Callback EnumchildProc (HWND HWNDCHILD, LPARAM LPARAM) {// Handle Your Code Here getWindowText (HWndchild, BUF, BUFSIZE); RETURN TRUE;}
The second parameter of EnumChildWindows is a function pointer. This function will be called by EnumChildWindows, but you don't know when it is called, the incoming of the code is a function of defining the enumchildProc, how to control this callback function is your business. The code here is the title of acquiring each sub-window