<?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; Win32/MFC</title>
	<atom:link href="http://www.ucosoft.com/tag/mfc/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 catch the events when click on the app icon on taskbar</title>
		<link>http://www.ucosoft.com/events-when-click-ontaskbar.html</link>
		<comments>http://www.ucosoft.com/events-when-click-ontaskbar.html#comments</comments>
		<pubDate>Wed, 24 Sep 2008 07:55:05 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[message]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2008/09/24/events-when-click-ontaskbar.html</guid>
		<description><![CDATA[How to catch the events when you click on the application's icon on the taskbar? It&#8217;s the WM_NC class messages. For example, you can handle the WM_NCLBUTTONDBLCLK message. And you can alse reponsible the&#160; WM_SYSCOMMAND messages.&#160; In particular, the special cases of SC_MINIMIZE and SC_MAXIMIZE are what are called from the system menu, which is [...]]]></description>
			<content:encoded><![CDATA[<pre class="csharpcode">How to catch the events when you click on the application's icon on the taskbar?</pre>
<p><span id="more-110"></span></p>
<p>It&#8217;s the WM_NC class messages. For example, you can handle the WM_NCLBUTTONDBLCLK message.</p>
<p>And you can alse reponsible the&#160; WM_SYSCOMMAND messages.&#160; In particular, the special cases of SC_MINIMIZE and SC_MAXIMIZE are what are called from the system menu, which is what is available from the taskbar. </p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/message" title="message" rel="tag">message</a>, <a href="http://www.ucosoft.com/tag/mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/events-when-click-ontaskbar.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>The Simplest way to change the row height of CListCtrl</title>
		<link>http://www.ucosoft.com/the-simplest-way-to-change-the-row-height-of-clistctrl.html</link>
		<comments>http://www.ucosoft.com/the-simplest-way-to-change-the-row-height-of-clistctrl.html#comments</comments>
		<pubDate>Mon, 14 Jan 2008 01:41:38 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[Tips]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2008/01/14/the-simplest-way-to-change-the-row-height-of-clistctrl.html</guid>
		<description><![CDATA[In the post &#8220;How to change the row height of CListCtrl&#8220;, it gives 2 solution example how to change row height or CListCtrl. Hower, it is not the simplest way. The simplest way to change the row height in a CListCtrl is: Display an icon with the desired height. All other ways that I know [...]]]></description>
			<content:encoded><![CDATA[<p>In the post &#8220;<a href="http://www.ucosoft.com/2006/12/05/how-to-change-the-row-height-of-clistctrl.html">How to change the row height of CListCtrl</a>&#8220;, it gives 2 solution example how to change row height or CListCtrl. Hower, it is not the simplest way.</p>
<p>The <strong>simplest</strong> way to change the row height in a CListCtrl is:<br />
<blockquote>
<p>Display an icon with the desired height. </p>
</blockquote>
<p>All other ways that I know of require significant programming (such as <strong>owner draw</strong>, which is often too much work). </p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/clistctrl" title="CListCtrl" rel="tag">CListCtrl</a>, <a href="http://www.ucosoft.com/tag/tips" title="Tips" rel="tag">Tips</a>, <a href="http://www.ucosoft.com/tag/mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/the-simplest-way-to-change-the-row-height-of-clistctrl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Adding CTreeCtrl in CListCtrl</title>
		<link>http://www.ucosoft.com/how-to-adding-ctreectrl-in-clistctrl.html</link>
		<comments>http://www.ucosoft.com/how-to-adding-ctreectrl-in-clistctrl.html#comments</comments>
		<pubDate>Sun, 06 Jan 2008 23:09:57 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[CTreeCtrl]]></category>
		<category><![CDATA[Win32/MFC]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2008/01/07/how-to-adding-ctreectrl-in-clistctrl.html</guid>
		<description><![CDATA[In some case, you need such a control as the following figure: It&#8217;s a CListCtrl like control, but it binds a CTreeCtrl in the first column. But you can also consider it as a CTreeCtrl and each of the items has the list style. All roads lead to Rome. But in 1999, David Lantsman has [...]]]></description>
			<content:encoded><![CDATA[<p>In some case, you need such a control as the following figure:</p>
<p><img height="260" alt="treelist" src="http://www.ucosoft.com/wp-content/uploads/2008/01/windowslivewriterhowtoaddingctreectrlinclistctrl-d7fetreelist-3.jpg" width="476"> </p>
<p>It&#8217;s a CListCtrl like control, but it binds a CTreeCtrl in the first column. But you can also consider it as a CTreeCtrl and each of the items has the list style.</p>
<p>All roads lead to Rome. But in 1999, <b><a href="http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=64">David Lantsman</a></b> has already given a solution on CodeProject and named it CTreeList: <a href="http://www.codeproject.com/KB/tree/treelist.aspx" target="_blank">A TreeList Control</a>.</p>
<p>You can <a href="http://www.codeproject.com/KB/tree/treelist/treelist_demo.zip">Download demo project &#8211; 60 Kb</a> and <a href="http://www.codeproject.com/KB/tree/treelist/treelist_src.zip">Download source files &#8211; 21 Kb</a> from codeproject.</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/clistctrl" title="CListCtrl" rel="tag">CListCtrl</a>, <a href="http://www.ucosoft.com/tag/ctreectrl" title="CTreeCtrl" rel="tag">CTreeCtrl</a>, <a href="http://www.ucosoft.com/tag/mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-adding-ctreectrl-in-clistctrl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use an derived CListCtrl in CListView</title>
		<link>http://www.ucosoft.com/how-to-use-an-derived-clistctrl-in-clistview.html</link>
		<comments>http://www.ucosoft.com/how-to-use-an-derived-clistctrl-in-clistview.html#comments</comments>
		<pubDate>Mon, 22 Oct 2007 03:15:01 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[CListView]]></category>
		<category><![CDATA[CView]]></category>
		<category><![CDATA[Win32/MFC]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/10/22/how-to-use-an-derived-clistctrl-in-clistview.html</guid>
		<description><![CDATA[Sometime you use CListView and need to extend the functionality of the CListCtrl of the view. For example, you want to overwrite the handler function of the NM_CUSTOMDRAW or WM_SIZE message. So the problem is: How to tell CListView to use your own CListCtrl? OK, you are on the wrong way now. The CListView does [...]]]></description>
			<content:encoded><![CDATA[<p>Sometime you use CListView and need to extend the functionality of the CListCtrl of the view. For example, you want to overwrite the handler function of the NM_CUSTOMDRAW or WM_SIZE message. So the problem is: <strong>How to tell CListView to use your own CListCtrl?</strong></p>
<p>OK, you are on the wrong way now.</p>
<p>The CListView does not use or contain the MFC <b>CListCtrl</b>, it only wraps a subclassed SysListView32 control as a CCtrlView, in the other hand, the view is the control. </p>
<p>If all you&#8217;ve done in your custom <b>CListCtrl</b> derived class is to handle the reflected NM_CUSTOMDRAW message, your best bet to get this working as a custom CListView is to derive a class from CListView and handle the reflected message for it just as you do in your <b>CListCtrl </b>derived implementation.</p>
<p>If you want get&nbsp; more custom control or you have already make an extended version of CList, It may be easier to derive a view class from CView and use your own CListCtrl in the view.</p>
<p>There are two articles about this topic on CodeGuru:</p>
<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/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/cview" title="CView" rel="tag">CView</a>, <a href="http://www.ucosoft.com/tag/mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-use-an-derived-clistctrl-in-clistview.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to set the backgroud color of CPropertyPage</title>
		<link>http://www.ucosoft.com/how-to-set-the-backgroud-color-of-cpropertypage.html</link>
		<comments>http://www.ucosoft.com/how-to-set-the-backgroud-color-of-cpropertypage.html#comments</comments>
		<pubDate>Thu, 18 Oct 2007 12:18:41 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Color]]></category>
		<category><![CDATA[CPropertyPage]]></category>
		<category><![CDATA[Win32/MFC]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/10/18/how-to-set-the-backgroud-color-of-cpropertypage.html</guid>
		<description><![CDATA[How to set the backgroud color of CPropertyPage? If you override OnCtlColor in your property page, then you can return a different background color and that seems to work with CStatic and other items. But what if you want is a background that&#8217;s not just a simple color? You&#8217;d like to be able to draw [...]]]></description>
			<content:encoded><![CDATA[<p>How to set the backgroud color of CPropertyPage?</p>
<p>If you override <strong>OnCtlColor</strong> in your property page, then you can return a different background color and that seems to work with CStatic and other items.</p>
<p>But what if you want is a background that&#8217;s not just a simple color? You&#8217;d like to be able to draw a background (maybe an watermark-style image) as your property page background and not have CStatic and other controls draw their own background. you would have though the transparent option in the CStatic class would do this when set from the dialog editor, but it doesn&#8217;t seem to.</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/color" title="Color" rel="tag">Color</a>, <a href="http://www.ucosoft.com/tag/cpropertypage" title="CPropertyPage" rel="tag">CPropertyPage</a>, <a href="http://www.ucosoft.com/tag/mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-set-the-backgroud-color-of-cpropertypage.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to select the item of ListView(CListCtrl)</title>
		<link>http://www.ucosoft.com/how-to-select-the-item-of-listviewclistctrl.html</link>
		<comments>http://www.ucosoft.com/how-to-select-the-item-of-listviewclistctrl.html#comments</comments>
		<pubDate>Thu, 18 Oct 2007 12:07:30 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[CListCtrl]]></category>
		<category><![CDATA[Win32/MFC]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/10/18/how-to-select-the-item-of-listviewclistctrl.html</guid>
		<description><![CDATA[Use CListCtrl::SetItemState with LVIS_SELECTED Tags: CListCtrl, Win32/MFC]]></description>
			<content:encoded><![CDATA[<p>Use CListCtrl::SetItemState with LVIS_SELECTED</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/clistctrl" title="CListCtrl" rel="tag">CListCtrl</a>, <a href="http://www.ucosoft.com/tag/mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/how-to-select-the-item-of-listviewclistctrl.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intermittent work in UI thread</title>
		<link>http://www.ucosoft.com/intermittent-work-in-ui-thread-2.html</link>
		<comments>http://www.ucosoft.com/intermittent-work-in-ui-thread-2.html#comments</comments>
		<pubDate>Tue, 16 Oct 2007 08:27:33 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/10/16/intermittent-work-in-ui-thread-2.html</guid>
		<description><![CDATA[Pedro Ferreira I&#8217;m trying to create a UI thread to do constant background work, but I&#8217;m having some design problems. The thread needs to fetch records from a database. do some processing on each record and, when there are no more records, sleep for 1 minute before check the database again. The process will be [...]]]></description>
			<content:encoded><![CDATA[<ul><strong>Pedro Ferreira</strong></ul>
<p>I&#8217;m trying to create a UI thread to do constant background work, but I&#8217;m having some design problems. </p>
<p>The thread needs to fetch records from a database. do some processing on each record and, when there are no more records, sleep for 1 minute before check the database again. The process will be controlled with thread messages (to start, pause, query&#8230;). </p>
<p>My problem is where should I put the processing work. I need it to be responsive between cycles, where the process waits for 1 minute, so I can stop it in that period. My only idea is using OnIdle to do the work.<br />
  But then, how should I make it real idle when waiting for 1 minute? </p>
<p>Could anyone give some hints on what is the way to go? </p>
<ul><strong>Scott McPhillips [VC++ MVP]</strong></ul>
<p>You can&#8217;t use Sleep and still be responsive to messages.  Instead of using Sleep you could use SetTimer in the main thread and post a message to the thread, or SetTimer to a hidden window within the thread, or you could use a loop within the thread and use MsgWaitForMultipleObjects within the loop. </p>
<p>MsgWaitForMultipleObjects has a timeout parameter that gives you the sleep period, but it also returns early if a message or event comes along.</p>
<ul><strong>Almond and Joseph M. Newcomer [MVP]</strong></ul>
<p>I would be strongly disinclined to use MsgWaitForMultipleObjects.  You don&#8217;t gain anything by using it over using WM_TIMER, and it requires that you have to write your own message pump, always a dangerous proposition.</p>
<ul><strong>BUT, SOME MORE DISCUSSION ABOUT THE UI THREAD AND WORKER THREAD&#8230;</strong></ul>
<ul><strong>Almond </strong></ul>
<p>Do not use UI threads for this kind of thing.</p>
<ul><strong>David</strong></ul>
<p>I would create a worker thread (not a UI thread) unless you need a UI thread for some specific purpose not apparent in this description.  The worker thread would do it&#8217;s work and then do a WaitForSingleObject() with a timeout of 1 minute (60000 ms), which causes WaitForSingleObject() to return when either the main thread sets an event for starting, pausing, querying, etc. or the 1 minute has elapsed.  If you need separate events each for starting, pausing, querying, etc. use WaitForMultipleObjects() instead of WaitForSingleObject().</p>
<ul><strong>Joseph M. Newcomer [MVP]</strong></ul>
<p>UI threads are actually ideal for this sort of thing.  Don&#8217;t be confused by the phrase &#8216;UI&#8217; meaning something with windows; think of it as &#8220;a thread with a built-in queuing mechanism&#8221;.  They&#8217;re really very good for things that require timed events as the OP described.</p>
<p>There are some advantages to UI threads; for example, a UI thread has a built-in queue.<br />
Also, for some kinds of interfacing require a message pump to deal with event handling.  I don&#8217;t do databases so I don&#8217;t know if databases have this requirement, but there are On-Anything handlers involved in the database interface, then a UI thread is required.</p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/message" title="message" rel="tag">message</a>, <a href="http://www.ucosoft.com/tag/sdk" title="sdk" rel="tag">sdk</a>, <a href="http://www.ucosoft.com/tag/thread" title="thread" rel="tag">thread</a>, <a href="http://www.ucosoft.com/tag/mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/intermittent-work-in-ui-thread-2.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Intermittent work in UI thread</title>
		<link>http://www.ucosoft.com/intermittent-work-in-ui-thread.html</link>
		<comments>http://www.ucosoft.com/intermittent-work-in-ui-thread.html#comments</comments>
		<pubDate>Tue, 16 Oct 2007 08:23:59 +0000</pubDate>
		<dc:creator>support</dc:creator>
				<category><![CDATA[Win32/MFC]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[sdk]]></category>
		<category><![CDATA[thread]]></category>

		<guid isPermaLink="false">http://www.ucosoft.com/2007/10/16/intermittent-work-in-ui-thread.html</guid>
		<description><![CDATA[Pedro Ferreira said: I&#8217;m trying to create a UI thread to do constant background work, but I&#8217;m having some design problems. The thread needs to fetch records from a database. do some processing on each record and, when there are no more records, sleep for 1 minute before check the database again. The process will [...]]]></description>
			<content:encoded><![CDATA[<p><strong><u>Pedro Ferreira said:</u></strong></p>
<p>I&#8217;m trying to create a UI thread to do constant background work, but I&#8217;m having some design problems.
<p>The thread needs to fetch records from a database. do some processing on each record and, when there are no more records, sleep for 1 minute before check the database again. The process will be controlled with thread messages (to start, pause, query&#8230;).
<p>My problem is where should I put the processing work. I need it to be <br />responsive between cycles, where the process waits for 1 minute, so I <br />can stop it in that period. My only idea is using OnIdle to do the work. <br />&nbsp; But then, how should I make it real idle when waiting for 1 minute?
<p>Could anyone give some hints on what is the way to go?
<p><strong><u>Scott McPhillips [VC++ MVP]</u></strong>
<p>You can&#8217;t use Sleep and still be responsive to messages.&nbsp; Instead of using Sleep you could use SetTimer in the main thread and post a message to the thread, or SetTimer to a hidden window within the thread, or you could use a loop within the thread and use MsgWaitForMultipleObjects within the loop.
<p>MsgWaitForMultipleObjects has a timeout parameter that gives you the sleep period, but it also returns early if a message or event comes along.
<p><strong><u>Almond and Joseph M. Newcomer [MVP]</u></strong>
<p>I would be strongly disinclined to use MsgWaitForMultipleObjects.&nbsp; You don&#8217;t gain anything by using it over using WM_TIMER, and it requires that you have to write your own message pump, always a dangerous proposition.
<p><strong><u>BUT, SOME MORE DISCUSSION ABOUT THE UI THREAD AND WORKER THREAD&#8230;</u></strong>
<p><strong><u>Almond </u></strong>
<p>Do not use UI threads for this kind of thing.
<p><strong><u>David</u></strong>
<p>I would create a worker thread (not a UI thread) unless you need a UI thread for some specific purpose not apparent in this description.&nbsp; The worker thread would do it&#8217;s work and then do a WaitForSingleObject() with a timeout of 1 minute (60000 ms), which causes WaitForSingleObject() to return when either the main thread sets an event for starting, pausing, querying, etc. or the 1 minute has elapsed.&nbsp; If you need separate events each for starting, pausing, querying, etc. use WaitForMultipleObjects() instead of WaitForSingleObject().
<p><strong><u>Joseph M. Newcomer [MVP]</u></strong>
<p>UI threads are actually ideal for this sort of thing.&nbsp; Don&#8217;t be confused by the phrase &#8216;UI&#8217; meaning something with windows; think of it as &#8220;a thread with a built-in queuing mechanism&#8221;.&nbsp; They&#8217;re really very good for things that require timed events as the OP described.
<p>There are some advantages to UI threads; for example, a UI thread has a built-in queue. <br />Also, for some kinds of interfacing require a message pump to deal with event handling.&nbsp; I don&#8217;t do databases so I don&#8217;t know if databases have this requirement, but there are On-Anything handlers involved in the database interface, then a UI thread is required. </p>

	Tags: <strong><a href="http://www.ucosoft.com/tag/message" title="message" rel="tag">message</a>, <a href="http://www.ucosoft.com/tag/sdk" title="sdk" rel="tag">sdk</a>, <a href="http://www.ucosoft.com/tag/thread" title="thread" rel="tag">thread</a>, <a href="http://www.ucosoft.com/tag/mfc" title="Win32/MFC" rel="tag">Win32/MFC</a></strong><br />
]]></content:encoded>
			<wfw:commentRss>http://www.ucosoft.com/intermittent-work-in-ui-thread.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

