<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx</link><description>Depends on what kind of message.</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#150959</link><pubDate>Tue, 08 Jun 2004 14:47:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:150959</guid><dc:creator>Jack Mathews</dc:creator><description>Here's a dumb question I just thought about.  What happens when you thread 1 sends a message to thread 2, and thread 2, in the handler, decides to terminate itself?  Or same with sending a process that terminates itself?  &lt;br&gt;&lt;br&gt;What's the return value of SendMessage to the caller?</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#150961</link><pubDate>Tue, 08 Jun 2004 14:50:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:150961</guid><dc:creator>Doug</dc:creator><description>Just one of the reasons why GUI code and multi-threaded applications is hard.&lt;br&gt;&lt;br&gt;It is amusing when you break in the debugger and see your code in the call stack 3 or 4 times, with Win32 code interspersed between them.  Can make for some real entertaining bugs...</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#150963</link><pubDate>Tue, 08 Jun 2004 14:59:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:150963</guid><dc:creator>Doug</dc:creator><description>This is also one of the reasons why MsgWaitForMultipleObjects() is not particularly useful.  You really cannot control what happens on your thread.  Dialogs are one of the places that you can't get into the Message Queue processing.&lt;br&gt;&lt;br&gt;Is there a way to get control of the Sleep that SendMessage puts the thread into?  At least then you could process other events while you are waiting on the other thread....&lt;br&gt;</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#151014</link><pubDate>Tue, 08 Jun 2004 16:09:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:151014</guid><dc:creator>asdf</dc:creator><description>LRESULT BlockingSendMessage(HWND hwnd, UINT msg, WPARAM wp, LPARAM lp)&lt;br&gt;{&lt;br&gt;	LRESULT ret;&lt;br&gt;	SendMessageTimeout(hwnd, msg, wp, lp, SMTO_BLOCK, INFINITE, &amp;amp;ret);&lt;br&gt;	return ret;&lt;br&gt;}&lt;br&gt;&lt;br&gt;Doug: you can poll SendMessageTimeout in a PeekMessage style message loop to do what you want.</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#151020</link><pubDate>Tue, 08 Jun 2004 16:16:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:151020</guid><dc:creator>Simon Cooke [exMSFT]</dc:creator><description>Doug:&lt;br&gt;1. MsgWaitForMultipleObjects isn't really for GUI programming. It's great if you have worker threads that you want to drive using a message pump though. &lt;br&gt;&lt;br&gt;2. Controlling the Sleep? Sure! You have three options that I can think of:&lt;br&gt;a. Use PostMessage instead of SendMessage, then you won't sleep at all.&lt;br&gt;b. Use SendMessageTimeout so that you can expire if you're waiting too long.&lt;br&gt;c. Use SendReply from the thread you're responding to the SendMessage call in, so you can wake up your other thread as soon as possible, and still continue running if you need to.</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#151102</link><pubDate>Tue, 08 Jun 2004 18:21:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:151102</guid><dc:creator>Seth McCarus</dc:creator><description>Simon, do you mean ReplyMessage in item c?&lt;br&gt;</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#151116</link><pubDate>Tue, 08 Jun 2004 18:45:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:151116</guid><dc:creator>Simon Cooke [exMSFT]</dc:creator><description>Seth: Yep, thanks for catching that one. :) That's what I get for replying before I get my latte :)</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#151563</link><pubDate>Wed, 09 Jun 2004 08:55:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:151563</guid><dc:creator>Centaur</dc:creator><description>&amp;gt; a. Use PostMessage instead of SendMessage, then&lt;br&gt;&amp;gt; you won't sleep at all.&lt;br&gt;&lt;br&gt;But then, if you want your message answered, you have to invent another way to get your reply than the message return value, for example, by having the other thread post the reply to you.</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#151761</link><pubDate>Wed, 09 Jun 2004 15:26:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:151761</guid><dc:creator>Simon Cooke [exMSFT]</dc:creator><description>Centaur: &lt;br&gt;Sure, but if you don't want to sleep at all, that means that you want to be completely asynchronous anyway. So you'd need something like that.</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#151762</link><pubDate>Wed, 09 Jun 2004 15:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:151762</guid><dc:creator>Raymond Chen</dc:creator><description>SendMessageCallback.</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#153950</link><pubDate>Fri, 11 Jun 2004 23:32:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:153950</guid><dc:creator>Jason Doucette</dc:creator><description>Raymond,&lt;br&gt;&lt;br&gt;Is this similar to the reason why, when you call MessageBox(), the program continues to run (i.e. other messages, such as WM_PAINT and WM_TIMER, are handled while the user is still reading the dialog box)?&lt;br&gt;&lt;br&gt;When I first starting Windows programming, this caught me off guard - since, even though I knew Windows was a multitasking / multithreading environment, my sample application only had one thread, and the code that appears immediately after the call to MessageBox() is not run until it returns - yet other parts of my program were running.  Then, they were causing this same code to be run, calling MessageBox() multiple times, displaying hundreds of dialogs, until the application finally crashed.</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#153972</link><pubDate>Sat, 12 Jun 2004 00:29:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:153972</guid><dc:creator>Raymond Chen</dc:creator><description>No that is another issue entirely - the modal message loop. Clearly messages are dispatched while the dialog box is up - you rely on it every time you yourself call DialogBox!&lt;br&gt;&lt;br&gt;(Tearing apart dialog boxes is a month-long subject that I hope to cover in little pieces. It took me three months just to write the first week's worth!)</description></item><item><title>re: When can a thread receive window messages?</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#172501</link><pubDate>Sat, 03 Jul 2004 17:39:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:172501</guid><dc:creator>Raymond Chen</dc:creator><description>Commenting on this entry has been closed.</description></item><item><title>re: The various ways of sending a message</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#266808</link><pubDate>Fri, 19 Nov 2004 19:52:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:266808</guid><dc:creator>The Old New Thing</dc:creator><description /></item><item><title>blog of this week</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#581308</link><pubDate>Sat, 22 Apr 2006 18:26:11 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:581308</guid><dc:creator>flyingxu</dc:creator><description>TrackBack From:&lt;a rel="nofollow" target="_new" href="http://www.cppblog.com/flyingxu/archive/2006/04/22/6088.html"&gt;http://www.cppblog.com/flyingxu/archive/2006/04/22/6088.html&lt;/a&gt;</description></item><item><title>blog of this week</title><link>http://blogs.msdn.com/oldnewthing/archive/2004/06/08/150929.aspx#581309</link><pubDate>Sat, 22 Apr 2006 18:28:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:581309</guid><dc:creator>flyingxu</dc:creator><description>TrackBack From:&lt;a rel="nofollow" target="_new" href="http://www.cppblog.com/flyingxu/archive/0001/01/01/6088.html"&gt;http://www.cppblog.com/flyingxu/archive/0001/01/01/6088.html&lt;/a&gt;</description></item></channel></rss>