<?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>Visual C++ Tips &#187; Codeproject</title>
	<atom:link href="http://weseetips.com/category/codeproject/feed/" rel="self" type="application/rss+xml" />
	<link>http://weseetips.com</link>
	<description>Gold mine of Visual C++ tricks!</description>
	<lastBuildDate>Thu, 11 Mar 2010 09:09:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=</generator>
		<item>
		<title>How to Delete Duplicate entries from STL containers?</title>
		<link>http://weseetips.com/2009/04/16/how-to-delete-duplicate-entries-from-stl-containers/</link>
		<comments>http://weseetips.com/2009/04/16/how-to-delete-duplicate-entries-from-stl-containers/#comments</comments>
		<pubDate>Thu, 16 Apr 2009 17:43:36 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[C++ unique]]></category>
		<category><![CDATA[delete duplicate entries]]></category>
		<category><![CDATA[remove duplicate entries]]></category>
		<category><![CDATA[set]]></category>
		<category><![CDATA[sort]]></category>
		<category><![CDATA[std::set]]></category>
		<category><![CDATA[std::sort]]></category>
		<category><![CDATA[std::unique]]></category>
		<category><![CDATA[unique]]></category>
		<category><![CDATA[Visual C++]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=996</guid>
		<description><![CDATA[If you want to remove duplicate items, you can go for stl::set. But what to do if you want to delete duplicate data from other containers? Picture Courtesy &#8211; Squidoo You can use std::unique() algorithm to remove adjacent duplicate items. So at first, sort your data, then call std::unique(). Now all the duplicate data will [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.wordpress.com/files/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
If you want to remove duplicate items, you can go for <a title="stl::set" href="http://weseetips.com/2008/05/08/seek-uniqueness-use-stl-set/">stl::set</a>. But <span style="color:#0000ff;">what to do if you want to delete duplicate data from other containers?</span></p>
<p><span style="color:#0000ff;"><img class="alignnone size-full wp-image-997" title="removeduplicate" src="http://weseetips.wordpress.com/files/2009/04/removeduplicate.jpg" alt="removeduplicate" width="510" height="309" /><br />
<span style="color:#000000;">Picture Courtesy &#8211; <a href="http://www.squidoo.com/demotivator">Squidoo</a></span><br />
</span></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.wordpress.com/files/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You can use <span style="color:#0000ff;">std::unique() </span>algorithm <span style="color:#0000ff;">to remove <span style="text-decoration:underline;"><strong>adjacent duplicate items</strong></span></span>. So at first, <span style="color:#0000ff;">sort your data, then call std::unique()</span>. Now <span style="color:#0000ff;">all the duplicate data will be rearranged to end of container</span>. Now <span style="color:#0000ff;">delete the unwanted range of duplicate data.</span> Have a look at code snippet below.</p>
<pre>#include &lt;vector&gt;
#include &lt;string&gt;
#include &lt;algorithm&gt;

using namespace std;

int main(int argc, char* argv[])
{
    // Election list.
    vector&lt;string&gt; ElectionList;
    ElectionList.push_back( "Sam" );
    ElectionList.push_back( "John" );
    ElectionList.push_back( "Ron" );
    ElectionList.push_back( "Sam" );
    ElectionList.push_back( "John" );

    // Sort the list to make same items be together.
    sort( ElectionList.begin(), ElectionList.end());

    // Rearrange unique items to front.
    vector&lt;string&gt;::iterator Itr = unique(
        ElectionList.begin(),
        ElectionList.end());

    // Delete the duplicate range.
    ElectionList.erase( Itr, ElectionList.end());
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.wordpress.com/files/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Take care that <span style="color:#0000ff;">std::unique() just removes the adjacent duplicate entries</span>. It wont remove the entire duplicate entries present in the container.<span style="color:#0000ff;"> That&#8217;s why we need to sort the container at first</span>, which will arrange all duplicate entries to adjacent  locations. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.wordpress.com/files/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/04/16/how-to-delete-duplicate-entries-from-stl-containers/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to measure Performance by using High Resolution Timer in Visual C++?</title>
		<link>http://weseetips.com/2009/03/31/how-to-measure-performance-by-using-high-resolution-timer-in-visual-c/</link>
		<comments>http://weseetips.com/2009/03/31/how-to-measure-performance-by-using-high-resolution-timer-in-visual-c/#comments</comments>
		<pubDate>Tue, 31 Mar 2009 17:13:04 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[high resolution stop watch]]></category>
		<category><![CDATA[high resolution timer]]></category>
		<category><![CDATA[measure perfomance]]></category>
		<category><![CDATA[QueryPerformanceCounter]]></category>
		<category><![CDATA[QueryPerformanceFrequency]]></category>
		<category><![CDATA[stop watch]]></category>
		<category><![CDATA[timer]]></category>
		<category><![CDATA[VC++]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=969</guid>
		<description><![CDATA[Ever had a performance tweaking project? The first thing you need is a high resolution stop watch to measure performance of different code blocks. But is there a high resolution stop watch? You can use QueryPerformanceCounter(). You can get the performance counter frequency &#8211; i.e. ticks per second by calling QueryPerformanceFrequency(). Have a look at [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
Ever had a performance tweaking project? The first thing you need is a <span style="color:#0000ff;">high resolution stop watch to measure performance of different code blocks.</span> But is there a high resolution stop watch?</p>
<p><img class="alignnone size-full wp-image-970" title="highperformancetimer" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/03/highperformancetimer.jpg" alt="highperformancetimer" width="509" height="304" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You can use <span style="color:#0000ff;"><strong>QueryPerformanceCounter()</strong></span>. You can get the performance counter frequency &#8211; i.e. ticks per second by calling <strong><span style="color:#0000ff;">QueryPerformanceFrequency()</span></strong>. Have a look at the sample CStopWatch class.</p>
<pre>// Stop watch class.
class CStopWatch
{
public:
    // Constructor.
    CStopWatch()
    {
        // Ticks per second.
        QueryPerformanceFrequency( &amp;liPerfFreq );
    }

    // Start counter.
    void Start()
    {
        liStart.QuadPart = 0;
        QueryPerformanceCounter( &amp;liStart );
    }

    // Stop counter.
    void Stop()
    {
        liEnd.QuadPart = 0;
        QueryPerformanceCounter( &amp;liEnd );
    }

    // Get duration.
    long double GetDuration()
    {
        return ( liEnd.QuadPart - liStart.QuadPart) /
                long double( liPerfFreq.QuadPart );
    }

private:
    LARGE_INTEGER liStart;
    LARGE_INTEGER liEnd;
    LARGE_INTEGER liPerfFreq;
};

int main()
{
    // Stop watch object.
    CStopWatch timer;

    // Start timer.
    timer.Start();

    // ZZzzzzz... for few seconds.
    Sleep( 3000 );
    timer.Stop();

    // Get the duration. Duration is in seconds.
    long double duration = timer.GetDuration();

    return 0;
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Even if the sample app slept for 3 seconds, in high resolution timer, the duration is 2.9xxx seconds. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Can you guess why?</p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audiance &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/03/31/how-to-measure-performance-by-using-high-resolution-timer-in-visual-c/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Set Console Text Color?</title>
		<link>http://weseetips.com/2009/03/29/how-to-set-console-text-color/</link>
		<comments>http://weseetips.com/2009/03/29/how-to-set-console-text-color/#comments</comments>
		<pubDate>Sun, 29 Mar 2009 18:09:16 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[change console background color]]></category>
		<category><![CDATA[change console text color]]></category>
		<category><![CDATA[set console text color]]></category>
		<category><![CDATA[set text color]]></category>
		<category><![CDATA[SetConsoleTextAttribute()]]></category>
		<category><![CDATA[SetConsoleTextColor]]></category>
		<category><![CDATA[SetTextColor]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=963</guid>
		<description><![CDATA[Getting bored with the black and white console? Did you ever wish to change the text or background color of console? Image Courtesy &#8211; reginadowntown. Yes! You can use the api &#8211; SetConsoleTextAttribute(). See the code snippet below. // Set text color as Yellow with white background. SetConsoleTextAttribute( GetStdHandle( STD_OUTPUT_HANDLE ), FOREGROUND_INTENSITY &#124; // Set [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
Getting bored with the black and white console? Did you ever wish to <span style="color:#0000ff;">change the text or background color of console?</span></p>
<p><img class="alignnone size-full wp-image-964" title="setconsoletextcolor" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/03/setconsoletextcolor.jpg" alt="setconsoletextcolor" width="510" height="499" /><br />
Image Courtesy &#8211; <a href="http://www.reginadowntown.ca/events.php">reginadowntown</a>.</p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Yes! You can use the api &#8211; <span style="color:#0000ff;"><strong>SetConsoleTextAttribute()</strong></span>. See the code snippet below.</p>
<pre>// Set text color as Yellow with white background.
SetConsoleTextAttribute(
    GetStdHandle( STD_OUTPUT_HANDLE ),
    FOREGROUND_INTENSITY              | // Set Text color
    FOREGROUND_RED | FOREGROUND_GREEN | // Text color as Yellow.
    BACKGROUND_INTENSITY              | // Set Background color
    BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE ); // White Bg.</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Please note that you can mix red/green/blue constants to make new colors. Have fun. <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/03/29/how-to-set-console-text-color/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>How to Pass Array by Reference?</title>
		<link>http://weseetips.com/2009/03/15/how-to-pass-array-by-reference/</link>
		<comments>http://weseetips.com/2009/03/15/how-to-pass-array-by-reference/#comments</comments>
		<pubDate>Sun, 15 Mar 2009 10:44:55 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[array by ref]]></category>
		<category><![CDATA[array by reference]]></category>
		<category><![CDATA[array reference]]></category>
		<category><![CDATA[error C2234]]></category>
		<category><![CDATA[error C2234: '' : arrays of references are illegal]]></category>
		<category><![CDATA[pass array by ref]]></category>
		<category><![CDATA[pass array by reference]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=940</guid>
		<description><![CDATA[We used to use arrays, a lot. But did you ever tried how to pass array by reference to another function? Yes. Its a bit tricky. Receiving arrays by reference have special syntax. The arrayname and &#38; symbol should be enclosed in parenthesis. And you should specify the size of array. Have a look at [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
We used to use arrays, a lot. But did you ever tried <span style="color:#0000ff;">how to pass array by reference </span>to another function? Yes. Its a bit tricky.</p>
<p><img class="alignnone size-full wp-image-941" title="arraybyreference" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/03/arraybyreference.jpg" alt="arraybyreference" width="500" height="471" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Receiving arrays by reference have special syntax. The <span style="color:#0000ff;"><strong>arrayname</strong> </span>and<span style="color:#0000ff;"> <strong>&amp;</strong></span> symbol <span style="color:#0000ff;">should be enclosed in parenthesis.</span> And <span style="color:#0000ff;">you should specify the size of array</span>. Have a look at the following code snippet.</p>
<pre>// Receive Array by reference.
void GetArray( int (&amp;Array) [10] )
{
}

// Test array by reference.
void CRabbitDlgDlg::TestArray()
{
    // Pass array by reference.
    int Array[10] = { 0 };
    GetArray( Array );
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Indeed, you can pass the array as pointer and then use it. But if you ever need to pass an array by reference, then remember this tip.</p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/03/15/how-to-pass-array-by-reference/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to set Font for Static Text Controls?</title>
		<link>http://weseetips.com/2009/03/04/how-to-set-font-for-static-text-controls/</link>
		<comments>http://weseetips.com/2009/03/04/how-to-set-font-for-static-text-controls/#comments</comments>
		<pubDate>Wed, 04 Mar 2009 17:57:04 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[CFont]]></category>
		<category><![CDATA[CFont::CreateFontIndirect()]]></category>
		<category><![CDATA[change dialog font]]></category>
		<category><![CDATA[change static font]]></category>
		<category><![CDATA[change static text font]]></category>
		<category><![CDATA[CWnd::GetFont()]]></category>
		<category><![CDATA[CWnd::SetFont()]]></category>
		<category><![CDATA[LOGFONT]]></category>
		<category><![CDATA[static font]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=894</guid>
		<description><![CDATA[By default, static text is displayed in normal fonts. And you don&#8217;t have any option to make it bold or italic or underline. Is there any way to enable these styles and change the font of the static text control? Yes! you can do it. First you&#8217;ve to get the current font of the text [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
<span style="color:#0000ff;"> By default, static text is displayed in normal fonts</span>. And you don&#8217;t have any option to make it bold or italic or underline. <span style="color:#0000ff;">Is there any way to </span>enable these styles and <span style="color:#0000ff;">change the font of the static text control?</span></p>
<p><img class="alignnone size-full wp-image-900" title="staticfont" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/03/staticfont.gif" alt="staticfont" width="500" height="262" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Yes! you can do it. First you&#8217;ve to <span style="color:#0000ff;">get the current font of the text control</span> and then <span style="color:#0000ff;">enable the styles you need </span>then <span style="color:#0000ff;">set it back.</span> Setting font is done in OnInitDialog() and new font is kept as member variable. See the code snippet below.</p>
<pre>BOOL CStaticFontDlg::OnInitDialog()
{
	...

    // Get current font.
    CFont* pFont = GetDlgItem( IDC_STATIC_ITALIC )-&gt;GetFont();
    LOGFONT LogFont = { 0 };
    pFont-&gt;GetLogFont( &amp;LogFont );

    // Create new font with underline style.
    LogFont.lfUnderline = TRUE;
    m_StaticFont.CreateFontIndirect( &amp;LogFont );

	// Sets the new font back to static text.
    GetDlgItem( IDC_STATIC_ITALIC )-&gt;SetFont( &amp;m_StaticFont );

	return TRUE;
}</pre>
<p>Now the static text will look like this.</p>
<p><img class="alignnone size-full wp-image-904" title="staticfont3" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/03/staticfont3.jpg" alt="staticfont3" width="301" height="161" /></p>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
<span style="color:#0000ff;">Don&#8217;t forget to change the Id of static text control from IDC_STATIC to something else.</span> Or else GetDlgItem() will return invalid handle.</p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audiance &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/03/04/how-to-set-font-for-static-text-controls/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Delete Pointers in Vector or Map in Single Line?</title>
		<link>http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/</link>
		<comments>http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/#comments</comments>
		<pubDate>Mon, 02 Mar 2009 19:11:12 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[deallocate map]]></category>
		<category><![CDATA[deallocate vector]]></category>
		<category><![CDATA[delete map]]></category>
		<category><![CDATA[delete vector]]></category>
		<category><![CDATA[for_each]]></category>
		<category><![CDATA[functional header file]]></category>
		<category><![CDATA[functor]]></category>
		<category><![CDATA[map]]></category>
		<category><![CDATA[memory leak map]]></category>
		<category><![CDATA[memory leak vector]]></category>
		<category><![CDATA[STL]]></category>
		<category><![CDATA[stl::map]]></category>
		<category><![CDATA[stl::vector]]></category>
		<category><![CDATA[template functor]]></category>
		<category><![CDATA[vector]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=881</guid>
		<description><![CDATA[If you have two or three STL containers which holds pointers in your class as members, then I&#8217;m sure that its destructor will be the worst readable one. For deallocating STL containers, we have to iterate through each container by for loop, then delete it. But is there any single line function call to delete [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
If you have two or three STL containers which holds pointers in your class as members, then I&#8217;m sure that its destructor will be the worst readable one. <span style="color:#0000ff;">For deallocating STL containers,</span> we have to <span style="color:#0000ff;">iterate through each container</span> by <span style="color:#0000ff;">for loop,</span> then <span style="color:#0000ff;">delete it.</span> But <span style="color:#0000ff;">is there any single line function call</span> to delete all pointers in vector or map,<strong> <span style="color:#0000ff;">just like chopping the top of a tray of eggs at once?</span></strong> <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="size-full wp-image-882 alignnone" title="deletestlcontainers" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/03/deletestlcontainers.jpg" alt="deletestlcontainers" width="430" height="310" /><br />
Picture Courtesy &#8211; <a title="elitalice.com" href="http://www.elitalice.com/wp-content/uploads/2007/04/eggs.jpg">elitalice.com</a></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You can use <span style="color:#0000ff;">for_each()</span> and <span style="color:#0000ff;">functors</span> to achieve this. Check out the code snippet.</p>
<p><span style="text-decoration:underline;"><strong>1) How to delete Vector of pointers in single line</strong></span></p>
<pre>// Necessary headers.
#include "functional"
#include "vector"
#include "algorithm"

using namespace std;

// Functor for deleting pointers in vector.
template&lt;class T&gt;
struct DeleteVectorFntor
{
    // Overloaded () operator.
    // This will be called by for_each() function.
    bool operator()(T x) const
    {
        // Delete pointer.
        delete x;
        return true;
    }
};

// Test Function.
void TestVectorDeletion()
{
    // Add 10 string to vector.
    vector&lt;CString*&gt; StringVector;
    for( int Index = 0; Index &lt; 10; ++Index )
    {
        StringVector.push_back( new CString("Hello"));
    }

    // Now delete the vector in a single  line.
    for_each( StringVector.begin(),
              StringVector.end(),
              DeleteVectorFntor&lt;CString*&gt;());
}</pre>
<p><span style="text-decoration:underline;"><strong>1) How to delete Map of pointers in single line</strong></span></p>
<pre>// Necessary headers.
#include "functional"
#include "map"
#include "algorithm"

using namespace std;

// Functor for deleting pointers in map.
template&lt;class A, class B&gt;
struct DeleteMapFntor
{
    // Overloaded () operator.
    // This will be called by for_each() function.
    bool operator()(pair&lt;A,B&gt; x) const
    {
        // Assuming the second item of map is to be
        // deleted. Change as you wish.
        delete x.second;
        return true;
    }
};

// Test function.
void TestMapDeletion()
{
    // Add 10 string to map.
    map&lt;int,CString*&gt; StringMap;
    for( int Idx = 0; Idx &lt; 10; ++Idx )
    {
        StringMap[Idx] = new CString("Hello");
    }

    // Now delete the map in a single  line.
    for_each( StringMap.begin(),
              StringMap.end(),
              DeleteMapFntor&lt;int,CString*&gt;());
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
STL is really a powerful toolkit. Isn&#8217;t it?</p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/03/02/how-to-delete-pointers-in-vector-or-map-in-single-line/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>gotoxy() function in Visual C++?</title>
		<link>http://weseetips.com/2009/03/01/gotoxy-function-in-visual-c/</link>
		<comments>http://weseetips.com/2009/03/01/gotoxy-function-in-visual-c/#comments</comments>
		<pubDate>Sun, 01 Mar 2009 18:39:49 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[C++ gotoxy()]]></category>
		<category><![CDATA[COORD]]></category>
		<category><![CDATA[ctime]]></category>
		<category><![CDATA[GetStdHandle()]]></category>
		<category><![CDATA[gotoxy()]]></category>
		<category><![CDATA[gotoxy() function]]></category>
		<category><![CDATA[SetConsoleCursorPosition()]]></category>
		<category><![CDATA[time()]]></category>
		<category><![CDATA[time_t]]></category>
		<category><![CDATA[turbo C++ gotoxy]]></category>
		<category><![CDATA[visual C++ gotoxy]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=874</guid>
		<description><![CDATA[I often feel nostalgic about the gotoxy() function in old Turbo C++. The gotoxy() is used to &#8220;jump&#8221; to any point of the console screen. I used that function to create nice menu effects. But unfortunately in visual C++, gotoxy() is not available. But is there any other api which can be used instead of [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
I often <span style="color:#0000ff;">feel nostalgic</span> about the <span style="color:#0000ff;">gotoxy() function in old Turbo C++</span>. The gotoxy() is used to <strong>&#8220;jump&#8221;</strong> to any point of the console screen. I used that function to create nice menu effects. But unfortunately <span style="color:#0000ff;">in visual C++, gotoxy() is not available.</span> But is there any other api which can be used instead of gotoxy()?</p>
<p><img class="alignnone size-full wp-image-875" title="gotoxy1" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/03/gotoxy1.jpg" alt="gotoxy1" width="510" height="429" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You can use <span style="color:#0000ff;">SetConsoleCursorPosition()</span>. Check out the following sample program. It reads an integer in loop and prints the time in the right hand corner of console. Just a demonstration of Visual C++&#8217;s gotoxy().</p>
<p><img class="alignnone size-full wp-image-876" title="gotoxy2" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/03/gotoxy2.jpg" alt="gotoxy2" width="509" height="292" /></p>
<pre>#include "iostream"
#include "time.h"
#include "windows.h"

using namespace std;

// Set current cursor position.
void GotoXY( HANDLE StdOut, SHORT x, SHORT y )
{
    // Set the cursor position.
    COORD Cord;
    Cord.X = x;
    Cord.Y = y;
    SetConsoleCursorPosition( StdOut, Cord );
}

// Print time at the upper right corner of console.
void PrintTime()
{
    // Get handle to console output buffer.
    HANDLE hStdout = GetStdHandle( STD_OUTPUT_HANDLE );

    // Get current screen information.
    CONSOLE_SCREEN_BUFFER_INFO ScreenBufferInfo = { 0 };
    GetConsoleScreenBufferInfo( hStdout, &amp;ScreenBufferInfo );

    // Set the cursor position to upper-right of console.
    GotoXY( hStdout, 50, 0 );

    // Get time and display it.
    time_t tim=time(NULL);
    char *s=ctime(&amp;tim);
    cout &lt;&lt; s;

    // Reset cursor back to position.
    GotoXY( hStdout,
            ScreenBufferInfo.dwCursorPosition.X,
            ScreenBufferInfo.dwCursorPosition.Y );
}

void main(int argc, char* argv[])
{
    // Just to provide enough space.
    cout &lt;&lt; endl &lt;&lt; endl;

    while( true )
    {
        // Print the time.
        PrintTime();

        // Read a value.
        int a;
        cout &lt;&lt; "Enter number: ";
        cin &gt;&gt; a;
    }
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Yes! After a short break, <span style="color:#0000ff;">I&#8217;m back</span>. <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  You&#8217;ll soon have a happy news from me, within a week. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' />  Keep watching.</p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audience &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/03/01/gotoxy-function-in-visual-c/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>How to restrict the tree control labels to be integer?</title>
		<link>http://weseetips.com/2009/01/18/how-to-restrict-the-tree-control-labels-to-be-integer/</link>
		<comments>http://weseetips.com/2009/01/18/how-to-restrict-the-tree-control-labels-to-be-integer/#comments</comments>
		<pubDate>Sun, 18 Jan 2009 20:40:09 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[CTreeCtrl GetEditControl()]]></category>
		<category><![CDATA[CTreeCtrl label int]]></category>
		<category><![CDATA[ES_NUMBER]]></category>
		<category><![CDATA[GetEditControl()]]></category>
		<category><![CDATA[ModifyStyle()]]></category>
		<category><![CDATA[OnBeginlabeleditTreectrl()]]></category>
		<category><![CDATA[restrict tree control label as int]]></category>
		<category><![CDATA[tree control label edit]]></category>
		<category><![CDATA[tree control label integer]]></category>
		<category><![CDATA[tree label as int]]></category>
		<category><![CDATA[TVN_BEGINLABELEDIT]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=858</guid>
		<description><![CDATA[Tree Controls supports label editing and by default it accepts all kind of chars for label. But is there any trick to restrict the input label to be an integer? Yes. You can. When user starts editing tree control will send a notification message - TVN_BEGINLABELEDIT. At first you have to handle the message and [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
Tree Controls supports label editing and by default it accepts all kind of chars for label. <span style="color:#0000ff;">But is there any trick to restrict the input label to be an integer?</span></p>
<p><img class="alignnone size-full wp-image-860" title="limittreeinputasint" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/01/limittreeinputasint.jpg" alt="limittreeinputasint" width="334" height="500" /></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Yes. You can. When user starts editing tree control will send a notification message -<span style="color:#0000ff;"> TVN_BEGINLABELEDIT</span>. At first you have to <span style="color:#0000ff;">handle the message </span>and in the message handler, you can <span style="color:#0000ff;">get the label edit control by calling GetEditControl()</span>. Then set the edit control style to ES_NUMBER. Then the label edit control of tree, will allow only integers as input. Have a look at the code snippet.</p>
<pre>// Message Map.
BEGIN_MESSAGE_MAP(CRabbitDlg, CDialog)
	...
	ON_NOTIFY(TVN_BEGINLABELEDIT, IDC_TREECTRL, OnBeginlabeleditTreectrl)
END_MESSAGE_MAP()

// Begin Label edit - Message Handler.
void CRabbitDlg::OnBeginlabeleditTreectrl(NMHDR* pNMHDR,
					  LRESULT* pResult)
{
    // Get the edit control which of tree control and set
    // its style to number only.
    CEdit* pEdit = m_TreeCtrl.GetEditControl();
    if( pEdit )
    {
        // Allow only numbers
        pEdit-&gt;ModifyStyle( 0, ES_NUMBER );
    }

    *pResult = 0;
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Feel the power!</p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/01/18/how-to-restrict-the-tree-control-labels-to-be-integer/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Start the ScreenSaver Programmatically?</title>
		<link>http://weseetips.com/2009/01/07/how-to-start-the-screensaver-programmatically/</link>
		<comments>http://weseetips.com/2009/01/07/how-to-start-the-screensaver-programmatically/#comments</comments>
		<pubDate>Wed, 07 Jan 2009 21:25:22 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[DefWindowProc()]]></category>
		<category><![CDATA[SC_SCREENSAVE]]></category>
		<category><![CDATA[start screen saver]]></category>
		<category><![CDATA[start screensaver]]></category>
		<category><![CDATA[windows screensaver]]></category>
		<category><![CDATA[WM_SYSCOMMAND]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=848</guid>
		<description><![CDATA[I&#8217;ve installed an aquarium screensaver and It works perfectly when i go to check the flames of stove. But from yesterday onwards, the screensaver is crashing due to some reasons. Well, i just thought about &#8211; is there any way to start the screensaver programmatically and see the crash once again? Picture Courtesy &#8211; fordesigner [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
I&#8217;ve installed an aquarium screensaver and It works perfectly when i go to check the flames of stove. <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  But from yesterday onwards, the screensaver is crashing due to some reasons. Well, i just thought about &#8211; <span style="color:#0000ff;">is there any way to start the screensaver programmatically</span> and see the crash once again? <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-full wp-image-853" title="startscreensaver" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/01/startscreensaver.jpg" alt="startscreensaver" width="425" height="282" /><br />
Picture Courtesy &#8211; <a title="fordesigner" href="http://www.fordesigner.com/maps//3034-0.htm">fordesigner</a></p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
Basically you have to <span style="color:#0000ff;">send a WM_SYSCOMMAND </span>to any of the windows <span style="color:#0000ff;">with wParam as SC_SCREENSAVE.</span> And what really happens in background is, <span style="text-decoration:underline;"><span style="color:#0000ff;">the default window proc will get the message and will start the screen saver.</span></span> So you can call the <span style="color:#0000ff;">DefWindowProc()</span> directly to start the screensaver. Have a look at the code snippet.</p>
<pre>// Start the screen-saver
DefWindowProc( WM_SYSCOMMAND, SC_SCREENSAVE, 0 );</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
It was really a nice screensaver. May be I&#8217;ll reinstall it to see it again. <img src='http://weseetips.com/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p><img class="alignnone size-medium wp-image-51" title="beginnerseries" src="http://weseetips.files.wordpress.com/2008/03/beginnerseries.jpg?w=215" alt="" width="215" height="32" /><br />
Targeted Audiance &#8211; Beginners.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/01/07/how-to-start-the-screensaver-programmatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Print the CView directly to Printer?</title>
		<link>http://weseetips.com/2009/01/06/how-to-print-the-cview-directly-to-printer/</link>
		<comments>http://weseetips.com/2009/01/06/how-to-print-the-cview-directly-to-printer/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 22:15:40 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[MFC]]></category>
		<category><![CDATA[CFrameWnd]]></category>
		<category><![CDATA[CView::OnCmdMsg()]]></category>
		<category><![CDATA[document/view print]]></category>
		<category><![CDATA[GetActiveView()]]></category>
		<category><![CDATA[ID_FILE_PRINT]]></category>
		<category><![CDATA[ID_FILE_PRINT_DIRECT]]></category>
		<category><![CDATA[mdi print]]></category>
		<category><![CDATA[print CView]]></category>
		<category><![CDATA[print document]]></category>
		<category><![CDATA[print view]]></category>
		<category><![CDATA[sdi print]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=836</guid>
		<description><![CDATA[MFC&#8217;s Document/View framework have built-in printing support for applications. If you create one SDI or MDI application, you can take the print by using the File-&#62;Print menu. But the menu handling and print functionality is buried deep inside mfc framework. Well, how to take the print of current view by your own? Picture Courtesy &#8211; [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" title="Icon Description" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
<span style="color:#0000ff;"> MFC&#8217;s Document/View framework have built-in printing support for applications.</span> If you create one SDI or MDI application, you can take the print by using the File-&gt;Print menu. But the menu handling and print functionality is buried deep inside mfc framework. <span style="color:#0000ff;">Well, how to take the print of current view by your own?</span></p>
<p><img class="alignnone size-full wp-image-841" title="printview" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/01/printview.jpg" alt="printview" width="510" height="367" /><br />
Picture Courtesy &#8211; <a href="http://www.daycad.com/">DayCad</a>.</p>
<p><img class="alignnone size-medium wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You have to call <span style="color:#0000ff;">CView::OnCmdMsg()</span> by passing <span style="color:#0000ff;">ID_FILE_PRINT</span> or <span style="color:#0000ff;">ID_FILE_PRINT_DIRECT</span>. If ID_FILE_PRINT is passed, the printer dialog will be shown and for ID_FILE_PRINT_DIRECT, the print will be taken directly with default printer parameters. Have a look at the code snippet.</p>
<pre>// Get the active view.
CFrameWnd* pFrameWnd = (CFrameWnd*)AfxGetApp()-&gt;GetMainWnd();
CView* pView = pFrameWnd-&gt;GetActiveView();

if( pView != NULL )
{
    // Send Print message.
    // If you want to print directly, then change ID_FILE_PRINT
    // to ID_FILE_PRINT_DIRECT.
    pView-&gt;OnCmdMsg( ID_FILE_PRINT, 0, 0, 0 );
}</pre>
<p><img class="alignnone size-medium wp-image-18" title="Icon Note" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
Its interesting to know MFC internals. isn&#8217;t it?</p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.files.wordpress.com/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/01/06/how-to-print-the-cview-directly-to-printer/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

