<?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; Document</title>
	<atom:link href="http://www.ucosoft.com/tag/document/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ucosoft.com</link>
	<description>Free Source Code and Program Tips</description>
	<lastBuildDate>Thu, 22 Jul 2010 05:17:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</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 />
]]></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>

