This situation is so commonplace there’s a features titled PostQuitMessage to help you blog post WM_End. PostMessage usually works better if you want so you can replicate a demand or enter in feel of the send WM_Command otherwise among the cello otherwise mouse texts (that’s usually dicey, in addition). So it is valid just like the “real” input incidents constantly can be found in sequences regarding relevant texts (particularly keydown/keyup pairs) as well as your software could get befuddled if you try so you’re able to processes a different type in content in the exact middle of one of these sequences. Blog post works better when simulating type in. Often you must fool around with PostMessage to acquire doing a beneficial quirk or insect to end unlimited recursion. Such, imagine their WM_SETFOCUS handler (OnSetFocus) decides that the new interest window is not ideal for certain reasoning and you have adjust the focus to another window.
For many who telephone call SetFocus from the inside your OnSetFocus handler, Windows quickly directs several other WM_SETFOCUS messagea€”while you are nonetheless control the first one to!
The result is unlimited regress until their heap blows up. To cease it infelicity, you could potentially post a contact to yourselfa€”MYWM_SWITCHFOCUSa€”therefore OnSetFocus can also be end before you techniques the message to switch the main focus. This is exactly those types of advice that’s simpler to know inside practice than simply on paper. What is very important to consider is the fact Windows wouldn’t let you SetFocus within a great WM_SETFOCUS handler. Because SendMessage calls the latest window proc personally, it will take an HWND. Just how else does it see and therefore content proc to name? However, PostMessage contributes the message for the content waiting line, that’s on the a bond otherwise processes, not a screen.
// blog post message to help you me personally
PostMessage(NULL, WM_HI_THERE_Good looking, . );
That’s, it attempts to become sweet giving for every single app a chance so you can perish gracefully, in case a software cannot react over time, ExitWindowsEx kills the fresh new application in any event
In case your HWND are NULL, PostMessage postings the content to the current running thread’s message waiting line. In practice, this particular aspect is not terribly of use because most times we would like to post a contact to some other bond (maybe with PostThreadMessage); however, discover constantly uncommon activities when it is smoother to share to oneself without a screen. (If you believe of any, delight tell me.) If you consider you are beginning to know when to use SendMessage and you can PostMessage, you’ll find three far more message-sending properties you should know throughout the: SendMessageCallback, SendNotifyMessage, and you may SendMessageTimeout. These types of services are useful on heady arena of Win32A® and you may multithreading. Inside the Win32, if you call SendMessage the bond was banned before the address thread processes the message. If the target thread are itself banned for almost all almost every other reason, SendMessage never ever production. Oops. SendNotifyMessage, SendMessageTimeout, and you may SendMessageCallback was formulated to work with this condition. SendNotifyMessage really works such as SendMessage in the event your target windows falls under (was developed by the) the current thread; it works like PostMessage should your windows belongs to another type of bond. SendMessageTimeout is comparable, but it allows you to establish a max time to wait a little for others bond to respond. As well crappy, therefore unfortunate. SendMessageTimeout delays, although not forever. As you you will guess, SendMessageCallback requires an excellent callback means. They directs the message and yields immediately; Mae hong son in Thailand bride in the event that message has been canned, Screen calls their setting. SendMessageCallback is available in convenient whenever you would want to explore PostMessage, however you wish to know in the event that content might have been addressed. Look at it as the PostMessage having money acknowledgment. PostMessage, SendMessageTimeout, and you can SendNotifyMessage are all a great candidates to make use of if you would like to help you transmit an email to most useful-height windows that with HWND_TOPMOST as HWND. It’s an awful idea to utilize HWND_TOPMOST which have SendMessage as the you to definitely deceased processes can bring your software so you can a stop. Shape dos sumong the various content-giving characteristics. Whew!