It’s my Birthday!!!

25 04 2008

Birthday Icon

Do you know what’s special today???
Yes! its my 25th Birthday. Its a bit more special.
Its the first and last b’day on which my age and day are the same – 25!!!

Its too late now. But i’m in a good mood to tell some stories. Do you know that the number 25 is special to me. Might be a coincidence – this blog took birth on March 25th. And more over that, my fathers birthday is on March 25th. My first b’day after starting this blog, which is on 25 – made me 25 years old. I’m pretty imaginative. huh? πŸ˜‰

Do you know, whats the inspiration for me to start this blog? I was an ordinary guy who finish my work and reach home early. One day as a part for technical activities, my project lead asked me to send technical tips to group members. But one condition – One tip per day! To be honest, at first – i tried to escape, because i felt its a burden.

From next day onwards, i searched the net for Visual C++ tips, found a lot, i copied and send it to team members as mails. But later on, i realize that the thing which i felt as a burden is slowly becoming a passion. I’m learning a lot, my technical skills are getting sharpened. I stopped the art of copy-pasting and began to work hard and find interesting tips myself. (None of the items in this blog are copy-pastes πŸ™‚ ) I began to dig MSDN during late nights. Began to read a lot of books and articles out of them, searching for a spark for an innovative idea. Still the quest goes on…

Then several other persons requested me to include them in the mailing list for daily tips. The list began to grow! After that i got onsite assignment to Europe and the daily tips was stopped for a while. Now after coming back, i though of restarting it even more stronger. And thats how this blog took birth. previously only a group of persons enjoy my tips, now by being online, it reach all over the world! If any of my efforts made your life easier, then i am happy that my efforts have meaning!

I’ll continue my quest – quality tips per day. Watch on and thanks for all visitors who motivates me by visiting frequently and by listining me. Thanks For all your support!

For WeSeeTips


How to find whether a GUI application is freezed or is not responding?

25 04 2008

It’s common that windows citizens usually hang after long run. πŸ˜‰ Sometimes your application was meant to run for long period but stop responding after days or months. So how to automatically restart it if it gets hang? One method is to schedule a polling application which checks the application periodically. But how to determine whether an application is hung?

You can send WM_NULL message to the application window by using the api – SendMessageTimeout(). The WM_NULL does nothing. It can be used for poll the window. If an appliaction window is hung, it may not be able to process the WM_NULL message. If we use SendMessage(), since its a blocking call out caller thread too will be blocked.

So we should use SendMessageTimeout() in which we can specify a timeout. In SendMessageTimeout() we can specify a flag – SMTO_ABORTIFHUNG which returns immedietly if the targeted application is hung. So SendMessageTimeout() is perfect for our purpouse. See the sample code snippet below.

DWORD Result = 0;
LRESULT Return = 0;

// Handle of application window.
// Get it by using FindWindowEx function.
// Here for compilation, i get the handle of my dialog.
HWND hWnd = GetSafeHwnd(); 

// Send the NULL message to the window.
// SMTO_ABORTIFHUNG is specified to return immediately,
// if the process is hung.
Return = ::SendMessageTimeout( hWnd, // Window Handle
                               WM_NULL, // Message
                               0,       // WParam
                               0,       // LParam
                               SMTO_ABORTIFHUNG, // Flags
                               500,              // Timeout
                               &Result );        // Result

// Check whether the WM_NULL message is processed.
if( !Return )
    // Since the WM_NULL message is not processed,
    // the targeted window is hung. Forget about it!

Customize it according to your wish.

Just like null checking the pointer, you can check, whether a window is perfect by sending WM_NULL message.

Targeted Audience – Intermediate.

STL valarray – An easy way to manipulate values.

25 04 2008

Assume you need to find the sum of 100 integers. You can create an array or use some STL containers, fill the values and by iterating you can find the sum. Instead of that you can use valarray container for storing any value type and do a number of mathematical operations for all items in just a function call.

See the code snippet for how to use valarray.

// Integer array of 10 members.
valarray<int> IntegerArray( 10 );

// Filling the array.
for( int nIndex = 0; nIndex < 10; ++nIndex )
    IntegerArray[ nIndex ] = nIndex;

// I need to get the sum of all number.
int nSum = IntegerArray.sum();

If you want to manipulate bulk amount of numbers, better use valarray.

The valarray contains only sum() and misc functions are its member function. Still they are useful, if you want to keep bulk amount of numerals.

Targeted Audience – Beginners.