<?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; Visual C++</title>
	<atom:link href="http://weseetips.com/category/visual-c/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 check whether the thread is alive or dead?</title>
		<link>http://weseetips.com/2010/03/04/how-to-check-whether-the-thread-is-alive-or-dead/</link>
		<comments>http://weseetips.com/2010/03/04/how-to-check-whether-the-thread-is-alive-or-dead/#comments</comments>
		<pubDate>Thu, 04 Mar 2010 16:39:18 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[check thread active]]></category>
		<category><![CDATA[GetExitCodeThread()]]></category>
		<category><![CDATA[STILL_ACTIVE]]></category>
		<category><![CDATA[thread active]]></category>
		<category><![CDATA[thread alive]]></category>
		<category><![CDATA[thread dead]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=1368</guid>
		<description><![CDATA[In multi-threaded environments, sometimes we need to check whether a given thread is alive or not. But how can we check it? Picture courtesy &#8211; Erica Marshall You can use the function &#8211; GetExitCodeThread(). If thread is alive, the function returns STILL_ACTIVE. Have a look at the code snippet. // Checks whether given thread is [...]]]></description>
			<content:encoded><![CDATA[<p>In multi-threaded environments, sometimes we need to check whether a given thread is alive or not. But how can we check it?</p>
<p><img class="alignnone size-full wp-image-1371" title="Thread-Alive" src="http://weseetips.com/wp-content/uploads/2010/03/Thread-Alive.jpg" alt="" width="500" height="333" /></p>
<p>Picture courtesy &#8211; <a href="http://www.flickr.com/photos/erica_marshall/2739537285/" target="_blank">Erica Marshall</a></p>
<p><img class="alignnone size-full wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.com/wp-content/uploads/2008/03/icon_howcanidoit.jpg" alt="" width="220" height="32" /><br />
You can use the function &#8211; <a href="http://msdn.microsoft.com/en-us/library/ms683190%28VS.85%29.aspx" target="_blank">GetExitCodeThread()</a>. If thread is alive, the function returns STILL_ACTIVE. Have a look at the code snippet.</p>
<pre>// Checks whether given thread is alive.
bool IsThreadAlive(const HANDLE hThread, bool&amp; bAlive )
{
 // Read thread's exit code.
 DWORD dwExitCode = 0;
 if( GetExitCodeThread(hThread, &amp;dwExitCode))
 {
 // if return code is STILL_ACTIVE,
 // then thread is live.
 bAlive = (dwExitCode == STILL_ACTIVE);
 return true;
 }

 // Check failed.
 return false;
}

void main()
{
 bool bAlive = false;
 if( IsThreadAlive( GetCurrentThread(), bAlive))
 {
 // IsThreadAlive is success.
 // Now check whether thread is alive.
 // It should, because its our main thread. <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />
 if( bAlive)
 {
 std::cout &lt;&lt; "Thread Alive!!!";
 }
 }
}
</pre>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2010/03/04/how-to-check-whether-the-thread-is-alive-or-dead/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>How to Tokenize String? Different Tricks in Trade!</title>
		<link>http://weseetips.com/2010/02/11/how-to-tokenize-string-different-tricks-in-trade/</link>
		<comments>http://weseetips.com/2010/02/11/how-to-tokenize-string-different-tricks-in-trade/#comments</comments>
		<pubDate>Thu, 11 Feb 2010 18:07:12 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[C++ string tokenize]]></category>
		<category><![CDATA[CStringT::Tokenize()]]></category>
		<category><![CDATA[istringstream]]></category>
		<category><![CDATA[split string]]></category>
		<category><![CDATA[string]]></category>
		<category><![CDATA[stringstream]]></category>
		<category><![CDATA[strtok()]]></category>
		<category><![CDATA[tokenize]]></category>
		<category><![CDATA[tokenize string]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=1350</guid>
		<description><![CDATA[I still remember my first project which I did seven years back. In that I got a task to split a string which contains ids separated by slash. I wrote a big snippet of string parser code by using pointers. But now when i see the following tricks, i feel &#8211; how childish was my [...]]]></description>
			<content:encoded><![CDATA[<p>I still remember my first project which I did seven years back. In that I got a task to split a string which contains ids separated by slash. I wrote a big snippet of string parser code by using pointers. But now when i see the following tricks, i feel &#8211; how childish was my first code snippet.</p>
<p><img class="alignnone size-full wp-image-1355" title="StrTokenize" src="http://weseetips.com/wp-content/uploads/2010/02/StrTokenize.jpg" alt="" width="540" height="383" /></p>
<p><img class="alignnone size-full wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.com/wp-content/uploads/2008/03/icon_howcanidoit.jpg" alt="" width="220" height="32" /><br />
Some of the tricks are as follows.</p>
<p><span style="text-decoration: underline;"><strong>1) strtok()</strong></span></p>
<p>If you want plain api and no object oriented fanciness, then strtok is for you. Download the source from <a href="http://weseetips.com/wp-content/uploads/2010/02/StrTok.zip">here</a>.</p>
<pre>#include "string.h"
...

// String to be splitted.
char String[] = "Long.Live_Visual.C++";

// Seperators.
char Seperators[] = "._";

// Start Tokenizing.
char* Token = strtok(String, Seperators);

// Loop until end.
while(Token != NULL)
{
 cout &lt;&lt; Token &lt;&lt; endl;

 // Tokenize the remaning string.
 Token = strtok(0, Seperators);
};
</pre>
<p><span style="text-decoration: underline;"><strong>2) istringstream</strong></span><br />
C++ Streams are good option for string splitup. But it has only one drawback &#8211; one one delimiter can be specified. Download the source from <a href="http://weseetips.com/wp-content/uploads/2010/02/StringStream.zip">here</a>.</p>
<pre>#include "iostream"
#include "sstream"
#include "string"
...

string String = "Long.Live.Visual.C++";
char Seperator = '.';

// Create input string stream.
istringstream StrStream(String);
string Token;

while(getline(StrStream, Token, Seperator))
{
 cout &lt;&lt; Token &lt;&lt; endl;
}
</pre>
<p><span style="text-decoration: underline;"><strong>3) CString::Tokenize()</strong></span></p>
<p>Wanna MFC way? Then CString::Tokenize() is for you. Download the source from <a href="http://weseetips.com/wp-content/uploads/2010/02/CString.zip">here</a>.</p>
<pre>// String.
CString String = _T("long.live_Visual.C++");

// Token seperators.
CString Seperator = _T("._");
int Position = 0;
CString Token;

// Get first token.s
Token = String.Tokenize(Seperator, Position);

while(!Token.IsEmpty())
{
 wcout &lt;&lt; Token.GetBuffer() &lt;&lt; endl;
 Token.ReleaseBuffer();

 // Get next token.
 Token = String.Tokenize(Seperator, Position);
}
</pre>
<p><img class="alignnone size-full wp-image-18" title="Icon Note" src="http://weseetips.com/wp-content/uploads/2008/03/icon_note.jpg" alt="" width="94" height="32" /><br />
Do you know any other mind blowing tokenizing tricks? Then, share with us.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2010/02/11/how-to-tokenize-string-different-tricks-in-trade/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to set Focus to Different Control on Dialog Startup?</title>
		<link>http://weseetips.com/2010/02/08/how-to-set-focus-to-different-control-on-dialog-startup/</link>
		<comments>http://weseetips.com/2010/02/08/how-to-set-focus-to-different-control-on-dialog-startup/#comments</comments>
		<pubDate>Mon, 08 Feb 2010 17:50:49 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[MFC]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[CWnd::SetFocus()]]></category>
		<category><![CDATA[set control focus]]></category>
		<category><![CDATA[set focus]]></category>
		<category><![CDATA[SetFocus OnInitDialog]]></category>
		<category><![CDATA[VC++]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=1323</guid>
		<description><![CDATA[Do you want to set the focus to another control on displaying Dialog? Or tried SetFocus() to another control in OnInitDialog() and want to know why its not working? The answer for your &#8216;Focus&#8217; question is here. If you are setting the default focus to another control in dialog, then OnInitDialog() should return FALSE. Have [...]]]></description>
			<content:encoded><![CDATA[<p>Do you want to set the focus to another control on displaying Dialog? Or tried SetFocus() to another control in OnInitDialog() and want to know why its not working? The answer for your &#8216;Focus&#8217; question is here.</p>
<p><img class="alignnone size-full wp-image-1325" title="SetFocus" src="http://weseetips.com/wp-content/uploads/2010/02/SetFocus.jpg" alt="" width="400" height="267" /></p>
<p><img class="alignnone size-full wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.com/wp-content/uploads/2008/03/icon_howcanidoit.jpg" alt="" width="220" height="32" /></p>
<p>If you are setting the default focus to another control in dialog, then OnInitDialog() should return FALSE. Have a look at the code snippet below.</p>
<pre>BOOL CStartupFocusDlg::OnInitDialog()
{
 ...
 // Set focus to your control.
 CWnd* pWnd = GetDlgItem(IDC_EDIT2);
 pWnd-&gt;SetFocus();

 // return TRUE;  // Wizard Generated code.
 // Return FALSE if you set focus to different control
 return FALSE;
}
</pre>
<p><img class="alignnone size-full wp-image-18" title="Icon Note" src="http://weseetips.com/wp-content/uploads/2008/03/icon_note.jpg" alt="" width="94" height="32" /><br />
Download the <a href="http://weseetips.com/wp-content/uploads/2010/02/StartupFocus.zip" target="_blank">Sample</a>, if you want to see it in action. Please note that sample is compiled in Visual C++ 2008.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2010/02/08/how-to-set-focus-to-different-control-on-dialog-startup/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>How to Set Dialog as TopMost Window?</title>
		<link>http://weseetips.com/2009/10/11/how-to-set-dialog-to-topmost-window/</link>
		<comments>http://weseetips.com/2009/10/11/how-to-set-dialog-to-topmost-window/#comments</comments>
		<pubDate>Sun, 11 Oct 2009 15:01:25 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[Always on top]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[HWND_TOPMOST]]></category>
		<category><![CDATA[set topmost window]]></category>
		<category><![CDATA[SetWindowPos()]]></category>
		<category><![CDATA[topmost window]]></category>
		<category><![CDATA[VC++]]></category>
		<category><![CDATA[window at top]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=1190</guid>
		<description><![CDATA[I always wondered about popularity of Winamp. It has rich custom drawn UI, which made it stand out of the crowd. Did you noticed its &#8220;Always on top&#8221; feature and wondered about how its implemented? Its time to reveal the secret &#8211; How winamp implemented that feature &#8211; Staying at the top? You can use [...]]]></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 always wondered about <span style="color:#0000ff;">popularity of Winamp</span>. It has <span style="color:#0000ff;">rich custom drawn UI</span>, which made it stand out of the crowd. Did you noticed its<span style="color:#0000ff;"> &#8220;Always on top&#8221; feature </span>and wondered about how its implemented? Its time to reveal the secret &#8211; How winamp implemented that feature &#8211; <span style="color:#0000ff;"><strong>Staying at the top</strong>?</span></p>
<p><img class="alignnone size-full wp-image-1191" title="SetTopMostWindow" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/10/settopmostwindow.jpg" alt="SetTopMostWindow" width="300" height="325" /></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 &#8211; <strong>SetWindowPos()</strong> with <strong>HWND_TOPMOST</strong> flag. Have a look at the code snippet.</p>
<pre>void CRabbitDlg::OnSetTopmost()
{
    // Set window position to topmost window.
    ::SetWindowPos( GetSafeHwnd(),
                    HWND_TOPMOST,
                    0, 0, 0, 0,
                    SWP_NOMOVE | SWP_NOREDRAW | SWP_NOSIZE );
}</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 />
Single line of code. But wowing feature. isn&#8217;t it?</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/10/11/how-to-set-dialog-to-topmost-window/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to Watch this Pointer &#8211; The Wizards Way!</title>
		<link>http://weseetips.com/2009/07/30/how-to-watch-this-pointer-the-wizards-way/</link>
		<comments>http://weseetips.com/2009/07/30/how-to-watch-this-pointer-the-wizards-way/#comments</comments>
		<pubDate>Thu, 30 Jul 2009 15:39:15 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[VC++ Debugging Tips]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[ECX]]></category>
		<category><![CDATA[this]]></category>
		<category><![CDATA[this pointer]]></category>
		<category><![CDATA[VC++]]></category>
		<category><![CDATA[watch window]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=1171</guid>
		<description><![CDATA[How to watch the this pointer? Just add &#8216;this&#8217; to watch window. Everyone does like that. Isn&#8217;t it? But how Visual C++ wizards watch &#8216;this&#8217; pointer? The secret is, visual C++ compiler passes this pointer via ECX register. So add (ClassName*)(@ECX) to watch window will give you this pointer. Have a look at the screenshot. [...]]]></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 />
How to watch the this pointer? Just add <span style="color:#0000ff;">&#8216;this&#8217;</span> to watch window. Everyone does like that. Isn&#8217;t it? But how <span style="color:#0000ff;">Visual C++ wizards</span> watch <span style="color:#0000ff;">&#8216;this&#8217;</span> pointer? <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-1172" title="thiswizardway" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/07/thiswizardway.jpg" alt="thiswizardway" width="442" height="350" /></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 />
The secret is, visual C++ compiler passes <span style="color:#0000ff;"><em><strong>this </strong></em></span>pointer via <span style="color:#0000ff;"><em>ECX</em> </span>register. So add <span style="color:#0000ff;"><strong>(ClassName*)(@ECX)</strong></span> to watch window will give you this pointer. Have a look at the screenshot.</p>
<p><img class="alignnone size-full wp-image-1173" title="thiswizardway2" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/07/thiswizardway2.jpg" alt="thiswizardway2" width="510" height="382" /></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 />
Interesting, the internals of Visual C++. 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 Audiance &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/07/30/how-to-watch-this-pointer-the-wizards-way/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>How to get the CPU Name String?</title>
		<link>http://weseetips.com/2009/06/21/how-to-get-the-cpu-name-string/</link>
		<comments>http://weseetips.com/2009/06/21/how-to-get-the-cpu-name-string/#comments</comments>
		<pubDate>Sun, 21 Jun 2009 18:29:49 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[C++ cpu name]]></category>
		<category><![CDATA[c++ get cpu name]]></category>
		<category><![CDATA[C++ get processor name]]></category>
		<category><![CDATA[CPU brand string]]></category>
		<category><![CDATA[cpu name]]></category>
		<category><![CDATA[Cpu name string]]></category>
		<category><![CDATA[get Cpu name]]></category>
		<category><![CDATA[get processor name]]></category>
		<category><![CDATA[intrin.h]]></category>
		<category><![CDATA[processor name]]></category>
		<category><![CDATA[VC++]]></category>
		<category><![CDATA[VC++ cpu name]]></category>
		<category><![CDATA[VC++ get cpu name]]></category>
		<category><![CDATA[VC++ get processor name]]></category>
		<category><![CDATA[__cpuid]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=1163</guid>
		<description><![CDATA[While taking the System properties, you have noticed the processor name string. For instance, in my laptop it is &#8211; &#8220;Intel(R) Core(TM)2 Duo CPU T5250 @ 1.50GHz&#8220;. Ever though about how to get this processor name string? Image Courtesy &#8211; Wallpaper Mania. You can use the function &#8211; __cpuid(), which generates the instruction &#8211; cpuid. [...]]]></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" /></p>
<p>While taking the System properties, you have noticed the processor name string. For instance, in my laptop it is &#8211; &#8220;<span style="color: #0000ff;">Intel(R) Core(TM)2 Duo CPU     T5250  @ 1.50GHz</span>&#8220;. Ever though about <span style="color: #0000ff;">how to get this processor name string</span>?</p>
<p><img class="alignnone size-full wp-image-1166" title="cpuid" src="http://weseetips.wordpress.com/files/2009/06/cpuid.jpg" alt="cpuid" width="400" height="300" /></p>
<p>Image Courtesy &#8211; <a href="http://piczzmania.blogspot.com/">Wallpaper Mania</a>.</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" /></p>
<p>You can use the function &#8211; <span style="color: #0000ff;"><strong>__cpuid()</strong></span>, which generates the instruction &#8211; cpuid. Have a look at the code snippet. Code taken and modified from MSDN.</p>
<pre>#include &lt;iostream&gt;
#include &lt;intrin.h&gt;

using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
    // Get extended ids.
    int CPUInfo[4] = {-1};
    __cpuid(CPUInfo, 0x80000000);
    unsigned int nExIds = CPUInfo[0];

    // Get the information associated with each extended ID.
    char CPUBrandString[0x40] = { 0 };
    for( unsigned int i=0x80000000; i&lt;=nExIds; ++i)
    {
        __cpuid(CPUInfo, i);

        // Interpret CPU brand string and cache information.
        if  (i == 0x80000002)
        {
            memcpy( CPUBrandString,
            CPUInfo,
            sizeof(CPUInfo));
        }
        else if( i == 0x80000003 )
        {
            memcpy( CPUBrandString + 16,
            CPUInfo,
            sizeof(CPUInfo));
        }
        else if( i == 0x80000004 )
        {
            memcpy(CPUBrandString + 32, CPUInfo, sizeof(CPUInfo));
        }
}

    cout &lt;&lt; "Cpu String: " &lt;&lt; CPUBrandString;
}</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 />
You can get a lot of information about cpu by using __cpuid. Have a look at the <a href="http://msdn.microsoft.com/en-us/library/hskdteyh(VS.80).aspx">MSDN Documentation</a>.</p>
<p><img class="alignnone size-medium wp-image-53" title="intermediateseries" src="http://weseetips.wordpress.com/files/2008/03/intermediateseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audiance &#8211; Intermeidate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2009/06/21/how-to-get-the-cpu-name-string/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to Change the Icon of MFC application?</title>
		<link>http://weseetips.com/2009/04/05/how-to-change-the-icon-of-mfc-application/</link>
		<comments>http://weseetips.com/2009/04/05/how-to-change-the-icon-of-mfc-application/#comments</comments>
		<pubDate>Sun, 05 Apr 2009 17:53:12 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[C++]]></category>
		<category><![CDATA[C++ icon]]></category>
		<category><![CDATA[change application icon]]></category>
		<category><![CDATA[change exe icon]]></category>
		<category><![CDATA[change icon]]></category>
		<category><![CDATA[set application icon]]></category>
		<category><![CDATA[set icon]]></category>
		<category><![CDATA[set mfc icon]]></category>
		<category><![CDATA[VC++]]></category>
		<category><![CDATA[VC++ set icon]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=982</guid>
		<description><![CDATA[When you create an MFC application, did you notice the icon of executable? Yes! its that same old icon. But I&#8217;ve seen other application with different icon. Well, how to set the icon of executable to give a new face for it? Image Courtesy &#8211; Flickr The secret is, windows will choose the first icon [...]]]></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 />
When you create an MFC application, did you notice the icon of executable? Yes! its that same old icon. But I&#8217;ve seen other application with different icon. Well, <span style="color:#0000ff;">how to set the icon of executable to give a <strong><span style="text-decoration:underline;">new face</span></strong> for it?</span> <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-986" title="setappicon" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/04/setappicon.jpg" alt="setappicon" width="450" height="259" /><br />
Image Courtesy &#8211; <a href="http://farm1.static.flickr.com/102/283474196_9bb98ca5cb_o.jpg">Flickr</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 />
The secret is, <span style="color:#0000ff;">windows will choose the first icon present in executable as exe icon.</span> By default for an MFC application, IDR_MAINFRAME will be the icon resource name and it have the lowest resource value &#8211; 128. Follow the steps to add an icon and make set it the first one in executable.</p>
<p>1. Import a new icon by using resource editor.</p>
<p><img class="alignnone size-full wp-image-983" title="setappicon1" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/04/setappicon1.jpg" alt="setappicon1" width="361" height="286" /></p>
<p>2. Let the icon be IDR_ICON1.<br />
3. Now open resource.h and you can see, IDR_MAINFRAME which is the mfc icon, have lowest resource id.</p>
<p><img class="alignnone size-full wp-image-984" title="setappicon2" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/04/setappicon2.jpg" alt="setappicon2" width="449" height="137" /><br />
4. Now edit the resource.h to make IDI_ICON1 as lowest resource id.</p>
<p><img class="alignnone size-full wp-image-985" title="setappicon3" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/04/setappicon3.jpg" alt="setappicon3" width="449" height="141" /><br />
5. Now clean and build your application and check the application icon. Wow! its changed!!!</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 />
The point is, the <span style="color:#0000ff;">icon should be the first icon in executable</span>. You can set icon value even to zero. It will work!</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/04/05/how-to-change-the-icon-of-mfc-application/feed/</wfw:commentRss>
		<slash:comments>6</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 blink LED&#039;s in Keyboard?</title>
		<link>http://weseetips.com/2009/03/12/how-to-blink-leds-in-keyboard/</link>
		<comments>http://weseetips.com/2009/03/12/how-to-blink-leds-in-keyboard/#comments</comments>
		<pubDate>Thu, 12 Mar 2009 17:53:13 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Visual C++]]></category>
		<category><![CDATA[blink keyboard LED]]></category>
		<category><![CDATA[enable capsLock]]></category>
		<category><![CDATA[enable NumLock]]></category>
		<category><![CDATA[enable scrollLock]]></category>
		<category><![CDATA[keybd_event()]]></category>
		<category><![CDATA[send keyboard input]]></category>
		<category><![CDATA[SendInput()]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=924</guid>
		<description><![CDATA[Do you remember those golden DOS days, where we access the video RAM directly and set the status of NumLock, ScrollLock etc and blink the LED of keyboard. Now in modern windows environment we are no more allowed to access the video RAM directly. But is there any way to blink the keyboard LEDs as [...]]]></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 />
Do you <span style="color:#0000ff;">remember those golden DOS days</span>, where <span style="color:#0000ff;">we access the video RAM directly</span> and set the status of NumLock, ScrollLock etc <span style="color:#0000ff;">and blink the LED of keyboard.</span> Now <span style="color:#0000ff;">in modern windows environment</span> we are <span style="color:#0000ff;">no more allowed to access the video RAM directly.</span> But is there any way to blink the keyboard LEDs as we did before?</p>
<p><img class="alignnone size-full wp-image-930" title="keyboardblinking" src="http://siteground205.com/~weseetip/wp-content/uploads/2009/03/keyboardblinking.jpg" alt="keyboardblinking" width="492" height="378" /></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. The trick is to <span style="color:#0000ff;">send NumLock keystroke event</span> by using <span style="color:#0000ff;"><strong>keybd_input()</strong></span> function. See the sample code snippet from MSDN.</p>
<pre>// Set NUMLOCK Status.
void SetNumLock( BOOL bState )
{
    BYTE keyState[256];

    GetKeyboardState((LPBYTE)&amp;keyState);
    if( (bState &amp;&amp; !(keyState[VK_NUMLOCK] &amp; 1)) ||
        (!bState &amp;&amp; (keyState[VK_NUMLOCK] &amp; 1)) )
    {
        // Simulate a key press
        keybd_event( VK_NUMLOCK,
                     0x45,
                     KEYEVENTF_EXTENDEDKEY | 0,
                     0 );

        // Simulate a key release
        keybd_event( VK_NUMLOCK,
                     0x45,
                     KEYEVENTF_EXTENDEDKEY | KEYEVENTF_KEYUP,
                     0);
    }
}

// Blink NUMLOCK.
void BlinkNumLock()
{
    // Blink status.
    bool bBlink = false;

    // Blink the NUMLOCK periodically.
    while( true )
    {
        SetNumLock( bBlink );
        bBlink = !bBlink;
        Sleep( 100 );
    }
}</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" /></p>
<p>You can also use <span style="color:#0000ff;"><strong>SendInput()</strong></span>, which is the latest version of keybd_event() to simulate keystrokes.</p>
<p>And one more thing, I was searching for an image for this post, but couldn&#8217;t find a suitable one. And <span style="text-decoration:underline;"><span style="color:#0000ff;">this image is suggested by my wife.</span></span> <img src='http://weseetips.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' />  How is it? <span style="color:#0000ff;">Did you like it? She would like to hear from you</span> <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-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/12/how-to-blink-leds-in-keyboard/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
	</channel>
</rss>

