{"id":19533,"date":"2009-01-12T10:00:00","date_gmt":"2009-01-12T10:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2009\/01\/12\/how-does-postquitmessage-know-which-thread-to-post-the-quit-message-to\/"},"modified":"2009-01-12T10:00:00","modified_gmt":"2009-01-12T10:00:00","slug":"how-does-postquitmessage-know-which-thread-to-post-the-quit-message-to","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20090112-00\/?p=19533","title":{"rendered":"How does PostQuitMessage know which thread to post the quit message to?"},"content":{"rendered":"<p>Commenter bav016 asks <a href=\"http:\/\/blogs.msdn.com\/oldnewthing\/pages\/407234.aspx#534733\"> how functions like <code>PostQuitMessage<\/code> and <code>SetTimer(NULL)<\/code> know which thread the messages should go to<\/a>. Unlike some functions such as <code>InvalidateRect<\/code> which have a window handle parameter that lets you say which window you want to operate on, <code>PostQuitMessage<\/code> and <code>SetTimer(NULL)<\/code> don&#8217;t say which thread the <code>WM_QUIT<\/code> or <code>WM_TIMER<\/code> message should go to. How do they decide?<\/p>\n<p> The messages go to the current thread; that is, they are delivered to the thread that called the function in the first place. <\/p>\n<p> There are many functions which operate on an implicit message queue, and those cases, they operate on the message queue associated with the thread making the call. If you call <code>GetKeyState<\/code> you retrieve the calling thread&#8217;s keyboard state. If you call <code>GetMessage<\/code> you retrieve messages from the calling thread&#8217;s message queue. If you call <code>InSendMessage<\/code>, you are told about the calling thread&#8217;s message processing state. If you call <code>GetQueueStatus<\/code> you retrieve information about the calling thread&#8217;s msesage queue. You get the idea. <\/p>\n<p> If you want these functions to operate on a thread different from the one that is executing, you&#8217;ll have to ask that thread to make the call for you. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Commenter bav016 asks how functions like PostQuitMessage and SetTimer(NULL) know which thread the messages should go to. Unlike some functions such as InvalidateRect which have a window handle parameter that lets you say which window you want to operate on, PostQuitMessage and SetTimer(NULL) don&#8217;t say which thread the WM_QUIT or WM_TIMER message should go to. [&hellip;]<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[25],"class_list":["post-19533","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-code"],"acf":[],"blog_post_summary":"<p>Commenter bav016 asks how functions like PostQuitMessage and SetTimer(NULL) know which thread the messages should go to. Unlike some functions such as InvalidateRect which have a window handle parameter that lets you say which window you want to operate on, PostQuitMessage and SetTimer(NULL) don&#8217;t say which thread the WM_QUIT or WM_TIMER message should go to. [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=19533"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/19533\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=19533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=19533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=19533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}