<?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; How-to</title>
	<atom:link href="http://www.ucosoft.com/tag/how-to/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 get ClistCtrl item text of another process</title>
		<link>http://www.ucosoft.com/get-clistctrl-item-text-of-another-process.html</link>
		<comments>http://www.ucosoft.com/get-clistctrl-item-text-of-another-process.html#comments</comments>
		<pubDate>Wed, 24 Sep 2008 08:19:30 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Injection]]></category>
		<category><![CDATA[Process]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2008/09/24/get-clistctrl-item-text-of-another-process.html</guid>
		<description><![CDATA[Question: In some app like WinSpy/Spy++ to make adjustments to list controls. It can correctly set an app&#8217;s list control&#8217;s modes, alignments, sorting, styles, and extended styles. It can also get the widths of the columns and count of items. The problem is that you cannot seem to get the columns&#8217; names or the item]]></description>
			<content:encoded><![CDATA[<p><strong>Question:</strong></p>
<p>In some app like WinSpy/Spy++ to make adjustments to list controls. It can correctly set an app&#8217;s list control&#8217;s modes, alignments,    <br />sorting, styles, and extended styles. It can also get the widths of the columns and count of items. </p>
<p>The problem is that you cannot seem to get the columns&#8217; names or the item text. The app uses code like this, where lc is a pointer to the target app&#8217;s list control: </p>
<p>&#160; lc-&gt;GetColumnWidth();    <br />&#160; lc-&gt;GetItemCount();     <br />&#160; lc-&gt;ModifyStyle();     <br />&#160; lc-&gt;SetExtendedStyle();     <br />&#160; lc-&gt;GetHeaderCtrl()-&gt;GetItemCount(); </p>
<p>That all works fine, but when you try something like this, it doesn&#8217;t work: </p>
<p>&#160; TCHAR colname[256]=_T(&quot;&quot;);    <br />&#160; LVCOLUMN lvcol;     <br />&#160; ZeroMemory(&amp;lvcol, sizeof(lvcol));     <br />&#160; lvcol.mask=LVCF_TEXT;     <br />&#160; lvcol.cchTextMax=sizeof(colname)-1;     <br />&#160; lvcol.pszText=colname;     <br />&#160; lc-&gt;GetColumn(col, &amp;lvcol); </p>
<p>GetColumn may return TRUE or FALSE, but the LVCOLUMN structure remains unchanged. If you tried using that same code in a test app to get the name of a column from that app&#8217;s own list control and it worked. It only seems to fail when use it from a different app.</p>
<p><strong><u>Solution:</u></strong></p>
<p>Well, there is no surprise here; in fact, if there is any surprise, it is that you did not manage to totally crash the target app (I presume that lc is a CListCtrl::FromHandle of an HWND in another process). </p>
<p>Think about this case:</p>
<p>you are passing the address of a data structure in YOUR process as a LPARAM-sized value to some totally different process, where that LPARAM value is completely and utterly meaningless. </p>
<p>David Ching did a remote-sendmessage DLL some time ago.&#160; This essentially does DLL injection of the code so it is running in the target process; you can google for this by looking for SendMessageRemote.</p>
<p><a href="http://www.dcsoft.com/private/sendmessageremote.cpp">http://www.dcsoft.com/private/sendmessageremote.cpp</a></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/clistctrl" title="CListCtrl" rel="tag">CListCtrl</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/injection" title="Injection" rel="tag">Injection</a>, <a href="http://www.ucosoft.com/tag/process" title="Process" rel="tag">Process</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />

	<ul class="st-related-posts">
	<li><a href="http://www.ucosoft.com/ucogrid-a-great-grid-control-of-mfc.html" title="ucoGrid, a great grid control of MFC (November 26, 2006)">ucoGrid, a great grid control of MFC</a> (18)</li>
	<li><a href="http://www.ucosoft.com/the-simplest-way-to-change-the-row-height-of-clistctrl.html" title="The Simplest way to change the row height of CListCtrl (January 14, 2008)">The Simplest way to change the row height of CListCtrl</a> (0)</li>
	<li><a href="http://www.ucosoft.com/sscanf-with-cstring.html" title="sscanf with CString (March 20, 2007)">sscanf with CString</a> (3)</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/simple-code-to-create-an-emf-or-bitmap-file-from-existed-draw-code.html" title="Simple code to create an EMF or Bitmap file from existed draw code (December 16, 2006)">Simple code to create an EMF or Bitmap file from existed draw code</a> (0)</li>
	<li><a href="http://www.ucosoft.com/simple-cedit-validation.html" title="Simple CEdit Validation (June 27, 2007)">Simple CEdit Validation</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/how-to-use-an-derived-clistctrl-in-clistview.html" title="How to use an derived CListCtrl in CListView (October 22, 2007)">How to use an derived CListCtrl in CListView</a> (2)</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-sendpost-message-to-cdocument.html" title="How to send/post message to CDocument? (October 24, 2007)">How to send/post message to CDocument?</a> (2)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/get-clistctrl-item-text-of-another-process.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to subclass CTreeCtrl in CTreeView?</title>
		<link>http://www.ucosoft.com/how-to-subclass-ctreectrl-in-ctreeview.html</link>
		<comments>http://www.ucosoft.com/how-to-subclass-ctreectrl-in-ctreeview.html#comments</comments>
		<pubDate>Thu, 25 Oct 2007 03:16:23 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CTreeCtrl]]></category>
		<category><![CDATA[CTreeView]]></category>
		<category><![CDATA[CView]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[Subclass]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/10/25/how-to-subclass-ctreectrl-in-ctreeview.html</guid>
		<description><![CDATA[Another title: How to use a derived CTreeCtrl in a CTreeView? It is similar with this article: &#8220;How to use an derived CListCtrl in CListView&#8221; or &#8220;How do I subclass the CListCtrl part of a CListView Class?&#8220;. Just like CListView, there is no CTreeCtrl to subclass in CTreeView. The CTreeView is the subclass of the]]></description>
			<content:encoded><![CDATA[<p>Another title:</p>
<p><strong>How to use a derived CTreeCtrl in a CTreeView?</strong></p>
<p>It is similar with this article: &#8220;<a href="http://www.ucosoft.com/2007/10/22/how-to-use-an-derived-clistctrl-in-clistview.html">How to use an derived CListCtrl in CListView</a>&#8221; or &#8220;<a href="http://www.ucosoft.com/2007/10/22/how-do-i-subclass-the-clistctrl-part-of-a-clistview-class.html">How do I subclass the CListCtrl part of a CListView Class?</a>&#8220;.</p>
<p>Just like CListView, there is no CTreeCtrl to subclass in CTreeView. The CTreeView is the subclass of the WC_TREEVIEW common control. If you need some extra feature in the CTreeView, the best way is like the method mentioned in the previous two articles:</p>
<p>Forget CTreeView and derive your own view CMyView from CView, and bond your CMyTreeCtrl in the view. Now you got the full control of the tree.</p>
<p>These two articles may be helpful to you:&nbsp;
<ul>
<li><a href="http://www.codeguru.com/doc_view/custom_view.shtml">http://www.codeguru.com/doc_view/custom_view.shtml</a> </li>
<li><a href="http://www.codeguru.com/doc_view/Control2View.shtml">http://www.codeguru.com/doc_view/Control2View.shtml</a> </li>
</ul>

	Tags: <strong><a href="http://www.ucosoft.com/tag/ctreectrl" title="CTreeCtrl" rel="tag">CTreeCtrl</a>, <a href="http://www.ucosoft.com/tag/ctreeview" title="CTreeView" rel="tag">CTreeView</a>, <a href="http://www.ucosoft.com/tag/cview" title="CView" rel="tag">CView</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/subclass" title="Subclass" rel="tag">Subclass</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/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/how-to-use-an-derived-clistctrl-in-clistview.html" title="How to use an derived CListCtrl in CListView (October 22, 2007)">How to use an derived CListCtrl in CListView</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-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>
	<li><a href="http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html" title="How to send/post message to CDocument? (October 24, 2007)">How to send/post message to CDocument?</a> (2)</li>
	<li><a href="http://www.ucosoft.com/how-to-program-to-retrieve-the-authenticode-information.html" title="How to retrieve the authenticode information (December 31, 2006)">How to retrieve the authenticode information</a> (3)</li>
	<li><a href="http://www.ucosoft.com/how-to-read-the-graphics-card-ram-capacity.html" title="How to read the graphics card RAM capacity (December 18, 2006)">How to read the graphics card RAM capacity</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-read-sectors-of-a-physical-drive-under-win32.html" title="How to read sectors of a physical drive under Win32? (January 15, 2007)">How to read sectors of a physical drive under Win32?</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-hook-the-file-related-event.html" title="How to hook the file related event (June 22, 2007)">How to hook the file related event</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-subclass-ctreectrl-in-ctreeview.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<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>
		<item>
		<title>How to sort items of CListCtrl or CListView?</title>
		<link>http://www.ucosoft.com/how-to-sort-items-of-clistctrl-or-clistview.html</link>
		<comments>http://www.ucosoft.com/how-to-sort-items-of-clistctrl-or-clistview.html#comments</comments>
		<pubDate>Mon, 22 Oct 2007 06:23:02 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CallBack]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[CListView]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[SetItemData]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/10/22/how-to-sort-items-of-clistctrl-or-clistview.html</guid>
		<description><![CDATA[How to sort the items of a CListCtrl or CListView(CReportView)? First, when you add items, you need to call SetItemData to attach an data structure(an integer or a pointer) to the item. Then, define a callback sort function. int CALLBACK SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort); And here, the prarameters lParam1 and lParam2 are the]]></description>
			<content:encoded><![CDATA[<p>How to sort the items of a CListCtrl or CListView(CReportView)?</p>
<p>First, when you add items, you need to call <strong>SetItemData </strong>to attach an data structure(an integer or a pointer) to the item.</p>
<p>Then, define a callback sort function. </p>
<pre>int CALLBACK SortFunc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort);</pre>
<p>And here, the prarameters lParam1 and lParam2 are the data structure you set in <strong>SetItemData</strong>. With the parameters, you can get the item content and calculate the sort order. Please notice, the parameters are <strong>NOT</strong> the item index.</p>
<p>Last, you can reponse the message <strong>HDN_ITEMCLICK</strong> or <strong>LVN_COLUMNCLICK</strong>, and call CListCtrl::SortItems with the callback function.</p>
<p>The examples from the CListCtrl::SortItems in MSDN is obsolescent, you&#8217;d better refer to the KB article:</p>
<p>250614 HOWTO: <a href="http://support.microsoft.com/?id=250614">Sort Items in a CListCtrl in Report View</a></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/callback" title="CallBack" rel="tag">CallBack</a>, <a href="http://www.ucosoft.com/tag/clistctrl" title="CListCtrl" rel="tag">CListCtrl</a>, <a href="http://www.ucosoft.com/tag/clistview" title="CListView" rel="tag">CListView</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/setitemdata" title="SetItemData" rel="tag">SetItemData</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/the-simplest-way-to-change-the-row-height-of-clistctrl.html" title="The Simplest way to change the row height of CListCtrl (January 14, 2008)">The Simplest way to change the row height of CListCtrl</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/moving-selection-of-clistctrl.html" title="Moving selection of CListCtrl (December 3, 2006)">Moving selection of CListCtrl</a> (0)</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-sendpost-message-to-cdocument.html" title="How to send/post message to CDocument? (October 24, 2007)">How to send/post message to CDocument?</a> (2)</li>
	<li><a href="http://www.ucosoft.com/how-to-select-the-item-of-listviewclistctrl.html" title="How to select the item of ListView(CListCtrl) (October 18, 2007)">How to select the item of ListView(CListCtrl)</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-program-to-retrieve-the-authenticode-information.html" title="How to retrieve the authenticode information (December 31, 2006)">How to retrieve the authenticode information</a> (3)</li>
	<li><a href="http://www.ucosoft.com/how-to-read-the-graphics-card-ram-capacity.html" title="How to read the graphics card RAM capacity (December 18, 2006)">How to read the graphics card RAM capacity</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-sort-items-of-clistctrl-or-clistview.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Set the head backgroud color of CPropertyPage</title>
		<link>http://www.ucosoft.com/set-the-head-backgroud-color-of-cpropertypage.html</link>
		<comments>http://www.ucosoft.com/set-the-head-backgroud-color-of-cpropertypage.html#comments</comments>
		<pubDate>Thu, 18 Oct 2007 13:35:07 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[CPropertyPage]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/10/18/set-the-head-backgroud-color-of-cpropertypage.html</guid>
		<description><![CDATA[How to set the head backgroud color of CPropertyPage? In the DrawItem function the TextOut position is pretty half-hearted, and looks a bit better (to my eyes) if you do it something like this instead. void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDIS) { CDC* pDC = CDC::FromHandle(lpDIS->hDC); CRect rc(lpDIS->rcItem); TCHAR szTabText[255]; TC_ITEM tci; tci.cchTextMax = sizeof(szTabText)-1; tci.pszText = szTabText;]]></description>
			<content:encoded><![CDATA[<p>How to set the head backgroud color of CPropertyPage?</p>
<p>In the DrawItem function the TextOut position is pretty half-hearted, and looks a bit better (to my eyes) if you do it something like this instead.</p>
<p> <coolcode lang="cpp" linenum="no"><br />
void CMyTabCtrl::DrawItem(LPDRAWITEMSTRUCT lpDIS)<br />
    {<br />
        CDC* pDC = CDC::FromHandle(lpDIS->hDC);<br />
        CRect rc(lpDIS->rcItem);<br />
        TCHAR szTabText[255];<br />
        TC_ITEM tci; </p>
<p>        tci.cchTextMax = sizeof(szTabText)-1;<br />
        tci.pszText = szTabText;<br />
        tci.mask = TCIF_TEXT; </p>
<p>        GetItem(lpDIS->itemID, &#038;tci); </p>
<p>        pDC->SaveDC(); </p>
<p>        pDC->SetBkColor(RGB(0,0,0));<br />
        pDC->SetTextColor(RGB(255,255,255)); </p>
<p>        if (!lpDIS->itemState &#038; ODS_SELECTED)<br />
            rc.OffsetRect(4,3);<br />
        else<br />
        {<br />
            pDC->FillSolidRect(&#038;rc, RGB(0,0,0));<br />
            rc.OffsetRect(6,4);<br />
        } </p>
<p>        pDC->TextOut(rc.left, rc.top, szTabText);<br />
        pDC->RestoreDC(-1);<br />
    } </p>
<p></coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/cpropertypage" title="CPropertyPage" rel="tag">CPropertyPage</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</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/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>
	<li><a href="http://www.ucosoft.com/how-to-set-the-backgroud-color-of-cpropertypage.html" title="How to set the backgroud color of CPropertyPage (October 18, 2007)">How to set the backgroud color of CPropertyPage</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html" title="How to send/post message to CDocument? (October 24, 2007)">How to send/post message to CDocument?</a> (2)</li>
	<li><a href="http://www.ucosoft.com/how-to-program-to-retrieve-the-authenticode-information.html" title="How to retrieve the authenticode information (December 31, 2006)">How to retrieve the authenticode information</a> (3)</li>
	<li><a href="http://www.ucosoft.com/how-to-read-the-graphics-card-ram-capacity.html" title="How to read the graphics card RAM capacity (December 18, 2006)">How to read the graphics card RAM capacity</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-read-sectors-of-a-physical-drive-under-win32.html" title="How to read sectors of a physical drive under Win32? (January 15, 2007)">How to read sectors of a physical drive under Win32?</a> (0)</li>
	<li><a href="http://www.ucosoft.com/how-to-hook-the-file-related-event.html" title="How to hook the file related event (June 22, 2007)">How to hook the file related event</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/set-the-head-backgroud-color-of-cpropertypage.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to translate among CString,string and char array</title>
		<link>http://www.ucosoft.com/how-to-translate-among-cstringstring-and-char-array.html</link>
		<comments>http://www.ucosoft.com/how-to-translate-among-cstringstring-and-char-array.html#comments</comments>
		<pubDate>Fri, 22 Jun 2007 03:56:19 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[Win32/MFC]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/06/22/how-to-translate-among-cstringstring-and-char-array.html</guid>
		<description><![CDATA[In MFC program, you&#8217;d better try to avoid using std::string. There is no compelling reason to use it in MFC, and it leads to confusion. There are some standard method to translate among Cstring ,string and char[]. // Suppose CString str; std::string s; char buf[SIZE]; // from CString to std::string s = str; // from]]></description>
			<content:encoded><![CDATA[<p>In MFC program, you&#8217;d better try to avoid using std::string.  There is no compelling reason to use it in MFC, and it leads to confusion.</p>
<p>There are some standard method to translate among Cstring ,string and char[].<br />
<coolcode lang="cpp" linenum="no"><br />
// Suppose<br />
CString str;<br />
std::string s;<br />
char buf[SIZE];</p>
<p>// from CString to std::string<br />
s = str;</p>
<p>// from std::string to CString<br />
str = s.c_str();</p>
<p>// to char[]<br />
_tcscpy(buf, str);<br />
_tcscpy(buf, s.c_str());</p>
<p>// from char[]<br />
str = buf;<br />
s = buf;<br />
</coolcode><br />
Also, beware of unicode. If UNICODE is defined, you should convert between unicode and ansi versions. Better to use TCHAR instead of char and std::basic_string<TCHAR> instead of std::string. </p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</a>, <a href="http://www.ucosoft.com/tag/stl" title="STL" rel="tag">STL</a>, <a href="http://www.ucosoft.com/tag/string" title="string" rel="tag">string</a>, <a href="http://www.ucosoft.com/tag/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />

	<ul class="st-related-posts">
	<li><a href="http://www.ucosoft.com/ucogrid-a-great-grid-control-of-mfc.html" title="ucoGrid, a great grid control of MFC (November 26, 2006)">ucoGrid, a great grid control of MFC</a> (18)</li>
	<li><a href="http://www.ucosoft.com/stack-vs-heap.html" title="Stack vs. Heap (January 12, 2008)">Stack vs. Heap</a> (1)</li>
	<li><a href="http://www.ucosoft.com/sscanf-with-cstring.html" title="sscanf with CString (March 20, 2007)">sscanf with CString</a> (3)</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/simple-code-to-create-an-emf-or-bitmap-file-from-existed-draw-code.html" title="Simple code to create an EMF or Bitmap file from existed draw code (December 16, 2006)">Simple code to create an EMF or Bitmap file from existed draw code</a> (0)</li>
	<li><a href="http://www.ucosoft.com/simple-cedit-validation.html" title="Simple CEdit Validation (June 27, 2007)">Simple CEdit Validation</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/moving-selection-of-clistctrl.html" title="Moving selection of CListCtrl (December 3, 2006)">Moving selection of CListCtrl</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-translate-among-cstringstring-and-char-array.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to hook the file related event</title>
		<link>http://www.ucosoft.com/how-to-hook-the-file-related-event.html</link>
		<comments>http://www.ucosoft.com/how-to-hook-the-file-related-event.html#comments</comments>
		<pubDate>Fri, 22 Jun 2007 03:29:35 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[File]]></category>
		<category><![CDATA[hook]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/06/22/how-to-hook-the-file-related-event.html</guid>
		<description><![CDATA[How to hook the file related event? It depends on what you need to do when such an event takes places. If what you just want to be notified, FindFirstChangeNotification and ReadDirectoryChanges are enough. If you need to intercept adn affect the operation somehow, I have heard it can be done with a kenerl-level driver(Filesystem]]></description>
			<content:encoded><![CDATA[<p>How to hook the file related event?</p>
<p>It depends on what you need to do when such an event takes places. If what you just want to be notified, <B>FindFirstChangeNotification</B> and <B>ReadDirectoryChanges</B> are enough.</p>
<p>If you need to intercept adn affect the operation somehow, I have heard it can be done with a kenerl-level driver(Filesystem Driver), but I have no experience about it.</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/api" title="API" rel="tag">API</a>, <a href="http://www.ucosoft.com/tag/file" title="File" rel="tag">File</a>, <a href="http://www.ucosoft.com/tag/hook" title="hook" rel="tag">hook</a>, <a href="http://www.ucosoft.com/tag/how-to" title="How-to" rel="tag">How-to</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/ucospy.html" title="ucoSpy,a system enhancement tool like spy++ (November 22, 2006)">ucoSpy,a system enhancement tool like spy++</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/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>
	<li><a href="http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html" title="How to send/post message to CDocument? (October 24, 2007)">How to send/post message to CDocument?</a> (2)</li>
	<li><a href="http://www.ucosoft.com/how-to-launch-an-application-with-admin-privileges-in-vista.html" title="How to launch an Application with Admin privileges in VISTA (March 8, 2007)">How to launch an Application with Admin privileges in VISTA</a> (0)</li>
	<li><a href="http://www.ucosoft.com/get-clistctrl-item-text-of-another-process.html" title="How to get ClistCtrl item text of another process (September 24, 2008)">How to get ClistCtrl item text of another process</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-hook-the-file-related-event.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to read sectors of a physical drive under Win32?</title>
		<link>http://www.ucosoft.com/how-to-read-sectors-of-a-physical-drive-under-win32.html</link>
		<comments>http://www.ucosoft.com/how-to-read-sectors-of-a-physical-drive-under-win32.html#comments</comments>
		<pubDate>Mon, 15 Jan 2007 15:44:52 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[win32]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/74.html</guid>
		<description><![CDATA[How to read the sectors of physical drive under win32? The API ReadFile is most useful function, and with it, you can read the physical sectors directly. Here is a sample function, BOOL ReadSectors(&#8230;) BOOL ReadSectors( BYTE bDrive, //drive index DWORD dwStartSector, //start sector WORD wSectors, //sectors number LPBYTE lpSectBuff) { ã€€if (bDrive == 0)]]></description>
			<content:encoded><![CDATA[<p><P>How to read the sectors of physical drive under win32? </p>
<p>The API ReadFile is most useful function, and with it, you can read the physical sectors directly.</p>
<p>Here is a sample function, <b>BOOL ReadSectors(&#8230;)</B><br />
</P><br />
<coolcode lang="cpp" linenum="no" download="ReadSector.cpp"><br />
BOOL ReadSectors(<br />
    BYTE bDrive,  //drive index<br />
    DWORD dwStartSector, //start sector<br />
    WORD wSectors,         //sectors number<br />
    LPBYTE lpSectBuff)<br />
{<br />
ã€€if (bDrive == 0) return 0;<br />
ã€€char devName[] = &#8220;\\\\.\\A:&#8221;;<br />
ã€€devName[4] =&#8217;A&#8217; + bDrive &#8211; 1;<br />
ã€€HANDLE hDev = CreateFile(devName, GENERIC_READ,<br />
                         FILE_SHARE_WRITE, NULL,<br />
                         OPEN_EXISTING, 0, NULL);<br />
ã€€if (hDev == INVALID_HANDLE_VALUE) return 0;<br />
ã€€SetFilePointer(hDev, 512 * dwStartSector,<br />
            0, FILE_BEGIN);<br />
ã€€DWORD dwCB;<br />
ã€€BOOL bRet = ReadFile(hDev, lpSectBuff,<br />
                 512 * wSectors, &#038;dwCB, NULL);<br />
ã€€CloseHandle(hDev);<br />
ã€€return bRet;<br />
}<br />
</coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/api" title="API" rel="tag">API</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/sdk" title="sdk" rel="tag">sdk</a>, <a href="http://www.ucosoft.com/tag/win32" title="win32" rel="tag">win32</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/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/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>
	<li><a href="http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html" title="How to send/post message to CDocument? (October 24, 2007)">How to send/post message to CDocument?</a> (2)</li>
	<li><a href="http://www.ucosoft.com/how-to-launch-an-application-with-admin-privileges-in-vista.html" title="How to launch an Application with Admin privileges in VISTA (March 8, 2007)">How to launch an Application with Admin privileges in VISTA</a> (0)</li>
	<li><a href="http://www.ucosoft.com/get-clistctrl-item-text-of-another-process.html" title="How to get ClistCtrl item text of another process (September 24, 2008)">How to get ClistCtrl item text of another process</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-read-sectors-of-a-physical-drive-under-win32.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to get a fixed code for serial number(2)</title>
		<link>http://www.ucosoft.com/how-to-get-a-fixed-code-for-serial-number2.html</link>
		<comments>http://www.ucosoft.com/how-to-get-a-fixed-code-for-serial-number2.html#comments</comments>
		<pubDate>Thu, 11 Jan 2007 00:41:45 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[API]]></category>
		<category><![CDATA[How-to]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[serial number]]></category>
		<category><![CDATA[shareware]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/73.html</guid>
		<description><![CDATA[I have post an article about &#8220;How to get a fixed code for serial number&#8221; at http://www.ucosoft.com/archives/51.html. In that article, I suggest you&#160;try WMI class to retrieve &#160;some hardware ID. But there is some limitation of this method. The WMI redist package is not always available on user&#8217;s system, for example, Windows NT4 and Windows]]></description>
			<content:encoded><![CDATA[<p>I have post an article about &#8220;How to get a fixed code for serial number&#8221; at <a href="http://www.ucosoft.com/archives/51.html">http://www.ucosoft.com/archives/51.html</a>. In that article, I suggest you&nbsp;try <a href="http://www.ucosoft.com/archives/60.html">WMI class</a> to retrieve &nbsp;some hardware ID. But there is some limitation of this method.</p>
<p>The WMI redist package is not always available on user&#8217;s system, for example, Windows NT4 and Windows 95/98.&nbsp; And the <a href="http://en.wikipedia.org/wiki/Volume_serial_number">Volume Serial Number of HDD</a> can be easily changed while the&nbsp;CPU ID is not always available. </p>
<p>As <em>Walter Wang</em> said, the manufacturer of harddisk&nbsp;stored a unique Firmware Serial Number in the harddisk when it&#8217;s built. It doesn&#8217;t change with Operating System Changes or HDD formatting. So I should serve your purpose.</p>
<p>For source code example on how to retrieve this HDD Firmware Serial Number using DeviceIoControl, you can refer to following <a href="http://www.winsim.com/diskid32/diskid32.html">this article</a>. It support IDE, SATA and SCSI drive type.</p>
<p><a href="http://www.winsim.com/diskid32/diskid32.html">http://www.winsim.com/diskid32/diskid32.html</a></p>
<p>
Local download: <span id="more-73"></span><a href="http://www.ucosoft.com/wp-content/download/diskid32.zip">diskid32.zipp</a><br />
Simple output of diskid32:
</p>
<p><coolcode lang="cpp" linenum="no"><br />
Primary Controller &#8211; Master drive</p>
<p>Drive Model Number________________: ST380011A<br />
Drive Serial Number_______________: 3JV6TBXW<br />
Drive Controller Revision Number__: 3.04<br />
Controller Buffer Size on Drive___: 2097152 bytes<br />
Drive Type________________________: Fixed<br />
Drive Size________________________: 76264796672 bytes</p>
<p>Trying to read the drive IDs using the SCSI back door</p>
<p>Primary Controller &#8211; Master drive</p>
<p>Drive Model Number________________: ST380011A<br />
Drive Serial Number_______________: 3JV6TBXW<br />
Drive Controller Revision Number__: 3.04<br />
Controller Buffer Size on Drive___: 2097152 bytes<br />
Drive Type________________________: Fixed<br />
Drive Size________________________: 76264796672 bytes</p>
<p>Trying to read the drive IDs using physical access wi</p>
<p>**** STORAGE_DEVICE_DESCRIPTOR for drive 0 ****<br />
Vendor Id = (<br />
Product Id = ST380011A<br />
Product Revision = 3.04<br />
Serial Number = 3JV6TBXW</p>
<p>Hard Drive Serial Number__________: 3JV6TBXW<br />
Hard Drive Model Number___________: ST380011A<br />
Computer ID_______________________: 652190462<br />
MAC Address: 00-FF-5B-FE-6B-20<br />
MAC Address: 00-0C-76-74-DA-50<br />
</coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/api" title="API" rel="tag">API</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/sdk" title="sdk" rel="tag">sdk</a>, <a href="http://www.ucosoft.com/tag/serial-number" title="serial number" rel="tag">serial number</a>, <a href="http://www.ucosoft.com/tag/shareware" title="shareware" rel="tag">shareware</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/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/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>
	<li><a href="http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html" title="How to send/post message to CDocument? (October 24, 2007)">How to send/post message to CDocument?</a> (2)</li>
	<li><a href="http://www.ucosoft.com/how-to-launch-an-application-with-admin-privileges-in-vista.html" title="How to launch an Application with Admin privileges in VISTA (March 8, 2007)">How to launch an Application with Admin privileges in VISTA</a> (0)</li>
	<li><a href="http://www.ucosoft.com/get-clistctrl-item-text-of-another-process.html" title="How to get ClistCtrl item text of another process (September 24, 2008)">How to get ClistCtrl item text of another process</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-get-a-fixed-code-for-serial-number2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Draw Bitmap from a bmp File?</title>
		<link>http://www.ucosoft.com/how-to-draw-bitmap-from-a-bmp-file.html</link>
		<comments>http://www.ucosoft.com/how-to-draw-bitmap-from-a-bmp-file.html#comments</comments>
		<pubDate>Fri, 05 Jan 2007 07:06:52 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[Bitmap]]></category>
		<category><![CDATA[Cpp]]></category>
		<category><![CDATA[How-to]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/archives/72.html</guid>
		<description><![CDATA[How to load a bitmap from bmp file and draw it in DC? There are two main steps: Load the bitmap from the file to a memory DC. Paint the content of the memory DC to the one which display the bitmap. In MFC, there is no API to load a bitmap directly from a]]></description>
			<content:encoded><![CDATA[<p>How to load a bitmap from bmp file and draw it in DC?</p>
<p>There are two main steps:</p>
<ul>
<li>Load the bitmap from the file to a memory DC.</li>
<li>Paint the content of the memory DC to the one which display the bitmap.</li>
</ul>
<p>In MFC, there is no API to load a bitmap directly from a file, but you can use a Win32 API: <strong>LoadImage</strong>.<br />
Here is the delaration of LoadImage.</p>
<p><coolcode lang="cpp" linenum="no"><br />
HANDLE LoadImage(<br />
HINSTANCE hinst, //handle to instance, if load from file, it should be NULL<br />
LPCTSTR lpszName, //image resource name or the image file path<br />
UINT uType, //image type<br />
//1. IMAGE_BITMAP<br />
//2. IMAGE_CURSOR<br />
//3. IMAGE_ICON<br />
int cxDesired, //desired width<br />
int cyDesired, //desired height<br />
UINT fuLoad //load options<br />
);<br />
</coolcode></p>
<p>After this,&nbsp; the following steps are similar with loading a bitmap from resource. Here is a short example.</p>
<p><span id="more-72"></span><br />
<coolcode lang="cpp" linenum="no" download="ShowBmp_demo.cpp"><br />
CClientDC dc(this);<br />
CDC *mdc=new CDC;<br />
mdc->CreateCompatibleDC(&#038;dc);</p>
<p>CBitmap bitmap;<br />
//CBitmap is devived from CGdiObject<br />
//It has a handle:m_hObject, which can obtained with LoadImage<br />
bitmap.m_hObject=(HBITMAP)::LoadImage(<br />
   NULL,<br />
   &#8220;b1.bmp&#8221;,<br />
   IMAGE_BITMAP,<br />
   500,<br />
   400,<br />
   LR_LOADFROMFILE);</p>
<p>mdc->SelectObject(bitmap);<br />
CRect rect;<br />
GetClientRect(&#038;rect);<br />
//BitBlt()<br />
dc.BitBlt(0,0,rect.right,rect.bottom,mdc,0,0,SRCCOPY);</p>
<p>//release mdc<br />
delete mdc;<br />
</coolcode></p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/bitmap" title="Bitmap" rel="tag">Bitmap</a>, <a href="http://www.ucosoft.com/tag/cpp" title="Cpp" rel="tag">Cpp</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/win32mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />

	<ul class="st-related-posts">
	<li><a href="http://www.ucosoft.com/ucogrid-a-great-grid-control-of-mfc.html" title="ucoGrid, a great grid control of MFC (November 26, 2006)">ucoGrid, a great grid control of MFC</a> (18)</li>
	<li><a href="http://www.ucosoft.com/sscanf-with-cstring.html" title="sscanf with CString (March 20, 2007)">sscanf with CString</a> (3)</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/moving-selection-of-clistctrl.html" title="Moving selection of CListCtrl (December 3, 2006)">Moving selection of CListCtrl</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>
	<li><a href="http://www.ucosoft.com/how-to-sendpost-message-to-cdocument.html" title="How to send/post message to CDocument? (October 24, 2007)">How to send/post message to CDocument?</a> (2)</li>
	<li><a href="http://www.ucosoft.com/how-to-program-to-retrieve-the-authenticode-information.html" title="How to retrieve the authenticode information (December 31, 2006)">How to retrieve the authenticode information</a> (3)</li>
	<li><a href="http://www.ucosoft.com/how-to-read-the-graphics-card-ram-capacity.html" title="How to read the graphics card RAM capacity (December 18, 2006)">How to read the graphics card RAM capacity</a> (0)</li>
</ul>

]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-draw-bitmap-from-a-bmp-file.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
