<?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; Windows APIs</title>
	<atom:link href="http://weseetips.com/category/windows-apis/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 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 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 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 Load Bitmap and Access the Bitmap Data?</title>
		<link>http://weseetips.com/2008/12/28/how-to-load-bitmap-and-access-the-bitmap-data/</link>
		<comments>http://weseetips.com/2008/12/28/how-to-load-bitmap-and-access-the-bitmap-data/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 17:23:49 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[access bitmap data]]></category>
		<category><![CDATA[BITMAP]]></category>
		<category><![CDATA[bitmap image processing]]></category>
		<category><![CDATA[bitmap pixels]]></category>
		<category><![CDATA[bitmap processing]]></category>
		<category><![CDATA[CBitmap]]></category>
		<category><![CDATA[get bitmap data]]></category>
		<category><![CDATA[get bitmap pixels]]></category>
		<category><![CDATA[GetBitmap()]]></category>
		<category><![CDATA[GetBitmapBits()]]></category>
		<category><![CDATA[how to access bitmap data]]></category>
		<category><![CDATA[how to load bitmap]]></category>
		<category><![CDATA[how to process bitmap]]></category>
		<category><![CDATA[load bitmap file]]></category>
		<category><![CDATA[LoadImage()]]></category>
		<category><![CDATA[SetBitmapBits()]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=763</guid>
		<description><![CDATA[While doing image processing, you will be loading the bitmap, access each pixel, process it and set it back. You can get/set each pixel by calling functions which is time consuming. Well, It will be nice if its possible to access the entire bitmap buffer and process it. Since access the data by pointers is [...]]]></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 />
While doing image processing, you will be loading the bitmap, access each pixel, process it and set it back. You can get/set each pixel by calling functions which is time consuming. Well, <span style="color:#0000ff;">It will be nice if its possible to access the entire bitmap buffer and process it.</span> Since access the data by pointers is so fast compared to get/set each pixel by function calls. But how to load the bitmap, <strong>cut it</strong> and access the bitmap data? <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-770" title="accessbitmapdata2" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/12/accessbitmapdata2.jpg" alt="accessbitmapdata2" width="464" height="390" /></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 <span style="color:#0000ff;">load the bitmap by</span> using <span style="color:#0000ff;">LoadImage()</span> and can call <span style="color:#0000ff;">GetBitmapBits()</span> to <span style="color:#0000ff;">access the pixel data</span> of bitmap. After processing, you can call <span style="color:#0000ff;">SetBitmapBits()</span> to <span style="color:#0000ff;">set the processed data back to bitmap.</span> Check the code snippet below.</p>
<pre>// Load and process the bitmap data.
void LoadAndProcessBitmap( TCHAR* pBitmapPath )
{
    // Load the image bitmapt.
    HBITMAP hBitmap = 0;
    hBitmap = (HBITMAP)LoadImage( NULL,
                                  pBitmapPath,
                                  IMAGE_BITMAP,
                                  0,
                                  0,
                                  LR_LOADFROMFILE | LR_DEFAULTSIZE);

    // Access bitmap data.
    CBitmap Bitmap;
    Bitmap.Attach( hBitmap );

    // Calculate buffer for bitmap bits.
    BITMAP BitmapInfo = { 0 };
    Bitmap.GetBitmap( &amp;BitmapInfo );

    // Calculate the size of required buffer.
    DWORD BitmapImageSize = BitmapInfo.bmHeight *
        BitmapInfo.bmWidth *
        ( BitmapInfo.bmBitsPixel / 8 );

    // Allocate memory.
    BYTE* pBitmapData = new BYTE[ BitmapImageSize ];
    ZeroMemory( pBitmapData, BitmapImageSize );

    // Get bitmap data.
    Bitmap.GetBitmapBits( BitmapImageSize, pBitmapData );

    // Now access and process bitmap data
    // as you wish!

    // Now after processing, set the bitmap data back.
    Bitmap.SetBitmapBits( BitmapImageSize, pBitmapData );

    // Now you can use the processed bitmap for your purpose.
    // For instance, save to disk, display in your dialog etc.

    // Delete bitmap data after use.
    delete pBitmapData;
    pBitmapData = 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 />
Here I&#8217;ve used <span style="color:#0000ff;">CBitmap for ease.</span> But this one can be done with pure windows apis as well.</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/2008/12/28/how-to-load-bitmap-and-access-the-bitmap-data/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>How to use Interlocked Singly Linked Lists?</title>
		<link>http://weseetips.com/2008/12/21/how-to-use-interlocked-singly-linked-lists/</link>
		<comments>http://weseetips.com/2008/12/21/how-to-use-interlocked-singly-linked-lists/#comments</comments>
		<pubDate>Sun, 21 Dec 2008 21:26:15 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[InitializeSListHead()]]></category>
		<category><![CDATA[interlocked list]]></category>
		<category><![CDATA[interlocked singly linked list]]></category>
		<category><![CDATA[InterlockedFlushSList()]]></category>
		<category><![CDATA[InterlockedPopEntrySList()]]></category>
		<category><![CDATA[InterlockedPushEntrySList()]]></category>
		<category><![CDATA[linked list]]></category>
		<category><![CDATA[SLIST_ENTRY]]></category>
		<category><![CDATA[synchornized list]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=744</guid>
		<description><![CDATA[Well, STL can provide you almost all kind of containers you want. But only one problem exists &#8211; they are not thread safe. If multiple threads are accessing the container at once, you have to add synchronization to them, by using mutex or similar ones. Well, the good news is if you need a singly [...]]]></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 />
Well, <span style="color:#0000ff;">STL </span>can provide you almost all kind of <span style="color:#0000ff;">containers </span>you want. But only one problem exists &#8211; they <span style="color:#0000ff;">are not thread safe.</span> If multiple threads are accessing the container at once, you have to add synchronization to them, by using mutex or similar ones. Well, the good news is <span style="color:#0000ff;">if you need a singly linked list &#8211; windows have a built in one which is already synchonized</span>.</p>
<p><img class="alignnone size-full wp-image-749" title="singlylinkedlist" src="http://weseetips.wordpress.com/files/2008/12/singlylinkedlist.jpg" alt="singlylinkedlist" width="360" height="360" /></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 />
First of all you have to <span style="color:#0000ff;">declare a structure to hold your data.</span> Keep in mind that the <span style="color:#0000ff;">first member should be of type &#8211; </span><span style="color:#0000ff;"><strong>SLIST_ENTRY</strong></span><span style="color:#0000ff;">.</span> Then only the api&#8217;s can work with it. Then you have to <span style="color:#0000ff;">initialize the list by calling <strong>InitializeSListHead()</strong>.</span> You can <span style="color:#0000ff;">push and pop</span> elements by calling <span style="color:#0000ff;"><strong>InterlockedPushEntrySList()</strong> and <strong>InterlockedPopEntrySList()</strong>.</span> And can <span style="color:#0000ff;">flush it by calling <strong>InterlockedFlushSList()</strong></span>. Check the code snippet below. Its taken from MSDN and modified accordingly.</p>
<pre>typedef struct _LIST_DATA
{
    SLIST_ENTRY ItemEntry; // SLIST_ENTRY should be first.
    int Data;               // Your data.
} LIST_DATA, *PLIST_DATA;

int _tmain(int argc, _TCHAR* argv[])
{
    PSLIST_ENTRY FirstEntry, ListEntry;
    SLIST_HEADER ListHead;
    PLIST_DATA pListData = 0;

    // Initialize the list header.
    InitializeSListHead(&amp;ListHead);

    // Insert 10 items into the list.
    ULONG Count;
    for( Count = 0; Count &lt; 10; ++Count )
    {
        // pListData = (PLIST_DATA)malloc(sizeof(*pListData));
        pListData = new LIST_DATA;
        pListData-&gt;Data = Count;
        FirstEntry = InterlockedPushEntrySList(&amp;ListHead,
                       &amp;pListData-&gt;ItemEntry);
    }

    // Remove 10 items from the list.
    for( Count = 0; Count &lt; 10; ++Count )
    {
        ListEntry = InterlockedPopEntrySList(&amp;ListHead);
        pListData = (PLIST_DATA)( ListEntry );
        cout &lt;&lt; "Item : " &lt;&lt; pListData-&gt;Data &lt;&lt; endl;
        // free( pListData );
        delete pListData;
    }

    // Flush the list and verify that the items are gone.
    ListEntry = InterlockedFlushSList(&amp;ListHead);
    FirstEntry = InterlockedPopEntrySList(&amp;ListHead);

    if (FirstEntry != NULL)
    {
        printf("Error: List is not empty.");
    }
}</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 />
I think the best name will be Interlocked stack, since its using push and pop and behaves like stack. I can&#8217;t find why its named as a singly linked list. What do you think?</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/2008/12/21/how-to-use-interlocked-singly-linked-lists/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows File Protection &#8211; How to check whether the file is protected?</title>
		<link>http://weseetips.com/2008/12/15/windows-file-protection-how-to-check-whether-the-file-is-protected/</link>
		<comments>http://weseetips.com/2008/12/15/windows-file-protection-how-to-check-whether-the-file-is-protected/#comments</comments>
		<pubDate>Mon, 15 Dec 2008 20:29:55 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[check protected file]]></category>
		<category><![CDATA[check system file]]></category>
		<category><![CDATA[sfc]]></category>
		<category><![CDATA[sfc.h]]></category>
		<category><![CDATA[SfcGetNextProtectedFile]]></category>
		<category><![CDATA[SfcIsFileProtected]]></category>
		<category><![CDATA[SfcIsFileProtected vista]]></category>
		<category><![CDATA[system file check]]></category>
		<category><![CDATA[WFP]]></category>
		<category><![CDATA[windows file protection]]></category>
		<category><![CDATA[windows resource protection]]></category>
		<category><![CDATA[WRP]]></category>

		<guid isPermaLink="false">http://weseetips.com/?p=711</guid>
		<description><![CDATA[Windows have got a set of files which are essential to the working of system. Chances are lot that those files to be corrupted accidentally or intentionally. But windows have taken care about it and those files are under protection. So if your user selects the filename of a protected system file to save his [...]]]></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 />
<span style="color:#0000ff;"> Windows have got a set of files which are essential to the working of system.</span> Chances are lot that those files to be corrupted accidentally or intentionally. But windows have taken care about it and those files are under protection. So if your user selects the filename of a protected system file to save his data, its the duty of a responsible windows citizen  application to check whether its a system file and to warn the user. <span style="color:#0000ff;">Well, how to check whether the file is a protected system file?</span></p>
<p><span style="color:#0000ff;"><img class="alignnone size-full wp-image-716" title="windowsresourceprotection" src="http://weseetips.wordpress.com/files/2008/12/windowsresourceprotection.jpg" alt="windowsresourceprotection" width="479" height="383" /><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 could use the function &#8211; <span style="color:#0000ff;">SfcIsFileProtected()</span>. Check the code snippet.</p>
<pre>#include "Sfc.h"
...
// Check whether the file is protected or not.
WCHAR* pProtectedFile = L"C:\\Windows\\system32\\kernel32.dll";
BOOL bProtected = SfcIsFileProtected( NULL, pProtectedFile );</pre>
<p><span style="text-decoration:underline;"><strong>How to get the list of protected files?</strong></span><br />
Well, <span style="color:#0000ff;">iterating the protected file list </span>will be nice. isn&#8217;t it? You can use the function &#8211; <span style="color:#0000ff;">SfcGetNextProtectedFile()</span> for that. Check the code snippet below.</p>
<pre>// Get the protected file list - one by one.
PROTECTED_FILE_DATA ProtectedFileInfo = { 0 };
while( SfcGetNextProtectedFile( NULL, &amp;ProtectedFileInfo ))
{
    // Print the filename.
    cout &lt;&lt; ProtectedFileInfo.FileName &lt;&lt; endl;
}</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 />
Well, for some reason the <strong><span style="color:#0000ff;">SfcGetNextProtectedFile() is removed from vista.</span></strong> So <span style="color:#000000;">keep in mind that it will work only on XP and 2000 machines.</span> Well, don&#8217;t forget to include <span style="color:#0000ff;">sfc.lib </span>in your project settings. <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/2008/12/15/windows-file-protection-how-to-check-whether-the-file-is-protected/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to add font to system, programmatically?</title>
		<link>http://weseetips.com/2008/10/29/how-to-add-font-to-system-programmatically/</link>
		<comments>http://weseetips.com/2008/10/29/how-to-add-font-to-system-programmatically/#comments</comments>
		<pubDate>Wed, 29 Oct 2008 05:25:32 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[add new font]]></category>
		<category><![CDATA[AddFontResource]]></category>
		<category><![CDATA[fonts]]></category>
		<category><![CDATA[how to add font]]></category>
		<category><![CDATA[how to install font]]></category>
		<category><![CDATA[install font]]></category>
		<category><![CDATA[windows fonts]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=544</guid>
		<description><![CDATA[Diablo! It was my favorite game during my childhood. Chopping down monsters, bats&#8230; Wow!!! I love it. Every time when i start the program one thing that attracted me is its font.Later when I searched net, i found that there is a font named diablo. But what will happen if the font is not present [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-full wp-image-11" title="Icon Description" src="http://weseetips.wordpress.com/files/2008/03/icon_description.jpg" alt="" width="166" height="32" /><a title="Diablo!" href="http://en.wikipedia.org/wiki/Horadrim" target="_blank"><br />
Diablo</a>! It was <span style="color:#0000ff;">my favorite game</span> during my childhood. <span style="color:#0000ff;">Chopping down monsters</span>, bats&#8230; <span style="color:#0000ff;">Wow!!!</span> I love it. Every time <span style="color:#0000ff;">when i start the program</span> one thing that <span style="color:#0000ff;">attracted me is its font</span>.Later when I searched net, <span style="color:#0000ff;">i found</span> that <span style="color:#0000ff;">there is a font</span> named <span style="color:#0000ff;">diablo</span>. But <span style="color:#3366ff;">what will happen</span> if the <span style="color:#3366ff;">font is not present in the system</span>? The <span style="color:#3366ff;">game screen </span>will be <span style="color:#3366ff;">wired</span>? The application might be installing the font, if its not present in the system. But how to do it?</p>
<p><img class="alignnone size-full wp-image-547" title="addfont" src="http://weseetips.wordpress.com/files/2008/10/addfont.jpg" alt="" width="413" height="534" /></p>
<p><img class="alignnone size-full wp-image-12" title="Icon How Can I Do It?" src="http://weseetips.wordpress.com/files/2008/03/icon_howcanidoit.jpg" alt="" width="220" height="32" /><br />
Well, You can use the api &#8211; <span style="color:#0000ff;">AddFontResource()</span>. You have to provide the path of font file to be added to system. Have a look at the code snippet.</p>
<pre>// Path of font to be added.
CString csFontPath = _T( "C:\\Diablo.ttf" );

// Add font to system.
if( 0 == AddFontResource( csFontPath ))
{
   // Adding font to system failed.
}</pre>
<p><img class="alignnone size-full wp-image-18" title="Icon Note" src="http://weseetips.wordpress.com/files/2008/03/icon_note.jpg" alt="" width="94" height="32" /><br />
Well, the latest version of diablo is <a title="Diablo III" href="http://www.blizzard.com/diablo3/" target="_blank">Diablo III</a>. Its superb! Have a look at it. <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-53" title="intermediateseries" src="http://weseetips.wordpress.com/files/2008/03/intermediateseries.jpg" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Intermediate.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/10/29/how-to-add-font-to-system-programmatically/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>_chdir() pitfall &#8211; error while opening file.</title>
		<link>http://weseetips.com/2008/10/04/chdir-pitfall-error-while-opening-file/</link>
		<comments>http://weseetips.com/2008/10/04/chdir-pitfall-error-while-opening-file/#comments</comments>
		<pubDate>Sat, 04 Oct 2008 20:32:45 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Glorious Bugs]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[chdir()]]></category>
		<category><![CDATA[file not found]]></category>
		<category><![CDATA[file open pitfall]]></category>
		<category><![CDATA[GetModuleFileName()]]></category>
		<category><![CDATA[MAX_PATH]]></category>
		<category><![CDATA[PathRemoveFileSpec()]]></category>
		<category><![CDATA[SetCurrentDirectory()]]></category>
		<category><![CDATA[Shlwapi.lib]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=483</guid>
		<description><![CDATA[I still remember that bug! Because it grabbed my two days and delayed the delivery. Well, the story goes like this &#8211; It was during late summer of 2004. I was working in a DVD writer project. Internally we were using a third party DVD writer library named BHA Gold. Well, my project was a [...]]]></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 />
<span style="color:#0000ff;">I still remember that bug! </span>Because it <span style="color:#0000ff;">grabbed my two days</span> and <span style="color:#0000ff;">delayed the delivery.</span> Well, the story goes like this &#8211; <span style="color:#0000ff;">It was during late summer of 2004.</span> I was <span style="color:#0000ff;">working in a DVD writer project</span>. <span style="color:#0000ff;">Internally </span>we were using a <span style="color:#0000ff;">third party DVD writer library named BHA Gold</span>. Well, my project was a wrapper library for the BHA Gold library.</p>
<p>Well, the bug was this &#8211; <span style="color:#0000ff;">There is a config file in my project,</span> which <span style="color:#0000ff;">exist in the same folder</span>, together with exe. <span style="color:#0000ff;">Before writing DVD,</span> I&#8217;ve to <span style="color:#0000ff;">read some settings from the config file</span>. But the bug is this. During startup, I could open the file. <span style="color:#0000ff;">But if I write one DVD using BHA gold, then when i tried to open the same file once again, it shows error!</span></p>
<p><img class="alignnone size-full wp-image-496" title="filenotfound" src="http://weseetips.wordpress.com/files/2008/10/filenotfound.jpg" alt="" width="504" height="504" /></p>
<p><img class="alignnone size-medium wp-image-15" title="icon_underthehood" src="http://weseetips.wordpress.com/files/2008/03/icon_underthehood.jpg?w=208" alt="" width="208" height="32" /><br />
At last its been found that the culprit is the api &#8211; _<span style="color:#0000ff;">chdir()</span>. The <span style="color:#888888;"><span style="color:#0000ff;">DVD writing library</span> </span>was <span style="color:#0000ff;">calling this api internally </span>to <span style="color:#0000ff;">prepare the directory tree,</span> and <span style="color:#0000ff;">once this api is called, the default directory will be changed to the specified directory </span>and during <span style="color:#0000ff;">next time, while opening the setting file,</span> it shows an <span style="color:#0000ff;">error that &#8220;file not found&#8221;! Since the setting file does not exist in the new default directory.<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 />
Well, in such cases you could use the api &#8211; <span style="color:#0000ff;">SetCurrentDirectory()</span>. See the code snippet to set the current directory as exe&#8217;s folder path.</p>
<pre>#include "Shlwapi.h"
...
// Get the full path of current exe file.
TCHAR FilePath[MAX_PATH] = { 0 };
GetModuleFileName( 0, FilePath, MAX_PATH );

// Strip the exe filename from path and get folder name.
PathRemoveFileSpec( FilePath );    

// Set the current working directory.
SetCurrentDirectory( FilePath );</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 />
Don&#8217;t forget to add <span style="color:#0000ff;">Shlwapi.lib</span> to project settings. <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.wordpress.com/files/2008/03/advancedseries.jpg?w=248" alt="" width="248" height="32" /><br />
Targeted Audience &#8211; Advanced.</p>
]]></content:encoded>
			<wfw:commentRss>http://weseetips.com/2008/10/04/chdir-pitfall-error-while-opening-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to copy or move file with progress?</title>
		<link>http://weseetips.com/2008/08/28/how-to-copy-or-move-file-with-progress/</link>
		<comments>http://weseetips.com/2008/08/28/how-to-copy-or-move-file-with-progress/#comments</comments>
		<pubDate>Thu, 28 Aug 2008 18:06:57 +0000</pubDate>
		<dc:creator>Jijo Raj</dc:creator>
				<category><![CDATA[Codeproject]]></category>
		<category><![CDATA[Windows APIs]]></category>
		<category><![CDATA[CopyFileEx()]]></category>
		<category><![CDATA[MoveFileEx]]></category>
		<category><![CDATA[_WIN32_WINNT=0x0400]]></category>

		<guid isPermaLink="false">http://weseetips.wordpress.com/?p=429</guid>
		<description><![CDATA[In old Win98 days, File copying progress notification was horrific. Even if you have a lot of data to copy, it always says &#8211; you have 5 more minutes to finish. Well, how to copy or move file with accurate progress? You can use the api &#8211; CopyFileEx() for copying data with progress and MoveFileEx() [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignnone size-medium wp-image-11" src="http://weseetips.files.wordpress.com/2008/03/icon_description.jpg?w=166" alt="" width="166" height="32" /><br />
In<span style="color:#0000ff;"> old Win98 days</span>, <span style="color:#0000ff;">File copying progress</span> notification <span style="color:#0000ff;">was horrific</span>. Even if you have a lot of data to copy, <span style="color:#0000ff;">it always says</span> &#8211; you have<span style="color:#0000ff;"> 5 more minutes to finish</span>. <img src='http://weseetips.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' />  Well, how to copy or move file with accurate progress?</p>
<p><img class="alignnone size-full wp-image-432" src="http://siteground205.com/~weseetip/wp-content/uploads/2008/08/filecopywithprogress.jpg" alt="" width="416" height="244" /></p>
<p><img class="alignnone size-medium wp-image-12" src="http://weseetips.files.wordpress.com/2008/03/icon_howcanidoit.jpg?w=220" alt="" width="220" height="32" /><br />
You can use the api &#8211; <span style="color:#0000ff;">CopyFileEx() for copying data with progress</span> and <span style="color:#0000ff;">MoveFileEx() to move files with progress</span>. Both are more or less similar in usage. In both cases, just call the apis by providing the callback function pointer. <span style="color:#0000ff;">System will give callback notification for the progress</span>. See the code snippet of CopyFileEx().</p>
<pre>// Callback function for handling progress notification.
DWORD CALLBACK CopyProgressRoutine(
                          LARGE_INTEGER TotalFileSize,
                          LARGE_INTEGER TotalBytesTransferred,
                          LARGE_INTEGER StreamSize,
                          LARGE_INTEGER StreamBytesTransferred,
                          DWORD dwStreamNumber,
                          DWORD dwCallbackReason,
                          HANDLE hSourceFile,
                          HANDLE hDestinationFile,
                          LPVOID lpData )
{
    // Calculate the percentage here.
    double Percentage = ( double(TotalBytesTransferred.QuadPart) /
        double(TotalFileSize.QuadPart) ) * 100;

    // Continue the file copy. It can also be stopped.
    return PROGRESS_CONTINUE;
}

void CDlgDlg::OnCopy()
{
    // Copy the file.
    CopyFileEx( _T("c:\\Jijo\\Games.rar"),
                _T("c:\\Jijo\\GamesBackup.rar"),
                CopyProgressRoutine,
                0,
                FALSE,
                0 );
}</pre>
<p><img class="alignnone size-medium wp-image-18" src="http://weseetips.files.wordpress.com/2008/03/icon_note.jpg?w=94" alt="" width="94" height="32" /><br />
<span style="color:#0000ff;">CopyFIleEx()</span> and <span style="color:#0000ff;">MoveFileEx()</span> are available only from <span style="color:#0000ff;">Windows NT</span> <span style="color:#0000ff;">onwards</span>. So don&#8217;t forget to add <span style="color:#0000ff;">_WIN32_WINNT=0&#215;0400</span> to project settings.</p>
<p><img class="alignnone size-medium wp-image-51" 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/2008/08/28/how-to-copy-or-move-file-with-progress/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

