<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Code Library &#187; SendMessage</title>
	<atom:link href="http://www.ucosoft.com/tag/sendmessage/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ucosoft.com</link>
	<description>Free Source Code and Program Tips</description>
	<lastBuildDate>Mon, 19 Jul 2010 04:51:18 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>How to send/post message to CDocument?</title>
		<link>http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html</link>
		<comments>http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html#comments</comments>
		<pubDate>Wed, 24 Oct 2007 05:46:52 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Document]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[PostMessage]]></category>
		<category><![CDATA[SendMessage]]></category>
		<category><![CDATA[Window]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/10/24/how-to-sendpost-message-to-cdocument.html</guid>
		<description><![CDATA[Sometime you need to send/post message to CDoumnet, but CDocument is not a window, and it can&#8217;t receive message. How do that? There are 3 solutions: Solution 1: Send the message to the main window. Send/Post the message to the main frame or the view, and then call some functions of the document. But if]]></description>
			<content:encoded><![CDATA[<p>Sometime you need to send/post message to CDoumnet, but CDocument is not a window, and it can&#8217;t receive message. How do that?</p>
<p>There are 3 solutions:</p>
<p><strong>Solution 1: Send the message to the main window.</strong></p>
<p> Send/Post the message to the main frame or the view, and then call some functions of the document.</p>
<p>But if in a MDI app, it does not work, because the routing becomes too complex. Typically, you can send message to a view, but that has risks if there are multiple views on the same document and the one you post message to has been closed. </p>
<p><strong>Solution 2: Use WM_COMMAND message.</strong></p>
<p>A document can&#8217;t recerive a message, but it can recerives the commands through MFC&#8217;s command mechanism. Then you can use ::PostMessage to post WM_COMMAND message, and repose it in the document.</p>
<p>Solution 3:</p>
<p>Create an invisible top-level window in the CDocument, that represents its message sink. You send/post message to it. Thus will eliminate the complex route policy between the main frame and the views and you don&#8217;t worry about the view closing.</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/document" title="Document" rel="tag">Document</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a>, <a href="http://www.ucosoft.com/tag/message" title="message" rel="tag">message</a>, <a href="http://www.ucosoft.com/tag/postmessage" title="PostMessage" rel="tag">PostMessage</a>, <a href="http://www.ucosoft.com/tag/sendmessage" title="SendMessage" rel="tag">SendMessage</a>, <a href="http://www.ucosoft.com/tag/window" title="Window" rel="tag">Window</a></strong><br />

	<ul class="st-related-posts">
	<li><a href="http://www.ucosoft.com/write-and-read-binary-data-in-variant.html" title="Write and read binary data in VARIANT (November 22, 2006)">Write and read binary data in VARIANT</a> (0)</li>
	<li><a href="http://www.ucosoft.com/what-is-the-usage-of-wm_null.html" title="What is the usage of WM_NULL? (November 23, 2006)">What is the usage of WM_NULL?</a> (0)</li>
	<li><a href="http://www.ucosoft.com/solution-crash-in-release-build-with-self-defined-message.html" title="Solution: Crash in Release build with self-defined message (November 28, 2006)">Solution: Crash in Release build with self-defined message</a> (0)</li>
	<li><a href="http://www.ucosoft.com/set-the-head-backgroud-color-of-cpropertypage.html" title="Set the head backgroud color of CPropertyPage (October 18, 2007)">Set the head backgroud color of CPropertyPage</a> (0)</li>
	<li><a href="http://www.ucosoft.com/intermittent-work-in-ui-thread-2.html" title="Intermittent work in UI thread (October 16, 2007)">Intermittent work in UI thread</a> (0)</li>
	<li><a href="http://www.ucosoft.com/intermittent-work-in-ui-thread.html" title="Intermittent work in UI thread (October 16, 2007)">Intermittent work in UI thread</a> (0)</li>
	<li><a href="http://www.ucosoft.com/install-global-hook-without-dll.html" title="Install global hook without dll (January 3, 2007)">Install global hook without dll</a> (2)</li>
	<li><a href="http://www.ucosoft.com/how-to-translate-among-cstringstring-and-char-array.html" title="How to translate among CString,string and char array (June 22, 2007)">How to translate among CString,string and char array</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-subclass-ctreectrl-in-ctreeview.html" title="How to subclass CTreeCtrl in CTreeView? (October 25, 2007)">How to subclass CTreeCtrl in CTreeView?</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-sort-items-of-clistctrl-or-clistview.html" title="How to sort items of CListCtrl or CListView? (October 22, 2007)">How to sort items of CListCtrl or CListView?</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>
