Classification:
Code Implementation window minimized, maximized, closed
var hwnd:hwnd;//handle
PostMessage (Hwnd,wm_syscommand, sc_minimize,0); Minimization of
PostMessage (Hwnd,wm_syscommand, sc_maximize,0);//maximized
PostMessage (Hwnd,wm_syscommand, sc_close,0);//Close
The resource is freed when the window is minimized
PostMessage (Hwnd,wm_syscommand, sc_minimize,0) is more useful than ShowWindow (hwnd,sw_minimize)
When you control other applications, you often need to wait until a feature finishes, such as:
Open a window and wait until the window ends
We can use SendMessage at this time.
If you still need to set the window's interface after opening this window, such as the value of edit and so on, such as:
Open a window--control property of a controlling window
This time, we need postmessage.
Using a hook program to intercept the message, using SendMessage to send the message to the main handler for processing, but the main handler has not completed the task, the set Hook program entered a stopped state, can not handle
WM_PAINT,
Wm_move,
....... and other basic information,
Must wait SendMessage sends the message to complete, can continue to run, the whole interface is blank, the hook message is set to postmessage Send Message form, the problem solves!
I checked the MSDN definition of these two APIs,
PostMessage just put the message in the queue, regardless of whether the other program is processing to return, and then continue to execute;
SendMessage must wait for other programs to process the message before returning and continuing.
The return value of PostMessage indicates whether the PostMessage function is executed correctly;
The return value of SendMessage, however, indicates the return value after the message was processed by another program.
The most important thing to use these two send message functions is to see if your program wants to focus on the hysteresis of the message, PostMessage will cause the message to lag, while SendMessage will not, but if the SendMessage message processing fails, it will cause the program to stop!
1, PostMessage only put the message in the queue, regardless of whether the other program is processed to return, and then continue to execute, this is an asynchronous message delivery function. The SendMessage must wait for the other program to finish processing the message before returning, continue execution, this is a synchronous message delivery function. Also, the return value of PostMessage indicates that the PostMessage function was executed correctly, and the return value of SendMessage represents the return value of the message after the other program processed it. We should all understand this point.
2, if PostMessage sends a message within the same thread, the message is first placed in the thread's message queue and then dispatch through the message loop to the target window. When SendMessage sends a message, the system calls the target window's message handler directly and returns the result. SendMessage sends a message in the same thread and does not enter the thread message queue. If it is within a different thread. Better use PostThreadMessage instead of PostMessage, he works very well. SendMessage sends a message to the message queue of the thread that the destination window belongs to, and then waits for the thread to send the message (in fact, he should still be doing some monitoring work, such as monitoring the QS_SENDMESSAGE flag) until the target window finishes processing and the result is returned, and the line friend to send the message continues to run. This is the general case of SendMessage, in fact, the process is much more complex. For example, when the thread that sends the message detects a different window SendMessage a message arrives, he calls the window processing (re-entry) directly and returns the processing result (this process does not require support for getmessage in the message loop).
3, msdn:if you send a message with the range below Wm_user to the asynchronous message functions (PostMessage, Sendnotifyme Ssage, and Sendmessagecallback), its message parameters can not include pointers. Otherwise, the operation would fail.
If the message code being sent is below Wm_user (not a custom message) and the message parameter has pointers, then postmessage,sendnotifymessage,sendmessagecallback these asynchronous message send functions will fail. It is best not to use PostMessage to send messages with pointer parameters.
Delphi Code Implementation window minimized, maximize, turn off message sending