How to disable the boot screen of Windows?

30 04 2008

For products, we usually disable windows boot screen, to hide from user that, internally windows is being used as operating system. So how can you do it?

Just follow the steps below.

  1. Take Start > Run, and execute msconfig.exe.
  2. in the msconfig application, take boot tab.
  3. Now check the /NOGUIBOOT option.
  4. click ok and restart the machine

Wow!!! no windows logo while booting up!!!

Targeted Audience – Beginners.

CRT Debug support – The Magic Memory values.

29 04 2008

Memory corruptions are every programmer’s nightmare. But Debug Heap provides some facility in debug build to help you to get rid of those memory corrupting problems. Depending to the type of memory allocation we have done, the debug heap will fill some magic value for the allocated memory contents. Take care that, this will be available only in debug build. Please see below.

  1. 0xCD – The memory locations filled with this magic number are allocated in heap and is not initialized.
  2. 0xFD – This magic number is known as “NoMansLand”. The debug heap will fill the boundary of the allocated memory block will this value. If you are rewriting this value, then it means, you are beyond an allocated memory block.
  3. 0xCC – The memory locations filled with this magic number means, it’s allocated in stack but not initialized. You can see this when you a variable on stack and look at its memory location. You can use /GZ compiler option to get the same feature in release build.
  4. 0xDD – The memory locations filled with this magic number are Released heap memory.

Regarding the 4th one – 0xDD, when I tried, the deleted memory locations are filled with 0xFEEE. I’ve to check it further. as per documentation its 0xDD.

Targeted Audience – Intermediate.

How to enable tooltip for your dialog controls?

28 04 2008

Have a number of controls in your dialog. May be a single line of tooltip will add beauty to it. So how can you add tooltips for the controls in your dialog? Its easy. Just follow the steps.

Basically you’ve to enable tooltips by calling EnableToolTips() and then handle the TTN_NEEDTEXT message in your dialog. When its time to show a tooltip, windows will send you the TTN_NEEDTEXT message with control’ handle and you’ve to specify the tooltip text to be shown. From handle you can get Dialog control ID. Once you have the control ID, you can specify which tooltip have to be shown for that control. See it step by step. I assume you use MFC. Eventhough you follow the tradition style, just go through the steps, you can easily grasp it.

1) Call EnableToolTips() in yout dialog initialize function. The best place is in dialog initialization routine – CDialog::OnInitDialog().
2) Now add message handler for TTN_NEEDTEXT in messagemap. The following codesnippet enables tooltip notification for all controls in your dialog.


3) Now declare the tooltip handler in your header as follows.

afx_msg BOOL OnToolTipNotify( UINT id,
                              NMHDR* pNMHDR,
                              LRESULT* pResult );

4) Now define the tooltip handler in your cpp file as follows

BOOL CDialogDlg::OnToolTipNotify( UINT id,
                                  NMHDR * pNMHDR,
                                  LRESULT * pResult )
    // Get the tooltip structure.

    // Actually the idFrom holds Control's handle.
    UINT CtrlHandle = pNMHDR->idFrom;

    // Check once again that the idFrom holds handle itself.
    if (pTTT->uFlags & TTF_IDISHWND)
        // Get the control's ID.
        UINT nID = ::GetDlgCtrlID( HWND( CtrlHandle ));

        // Now you have the ID. depends on control,
        // set your tooltip message.
        switch( nID )
        case IDC_BUTTON1:
                // Set the tooltip text.
                pTTT->lpszText = _T("First Button");

        case IDC_BUTTON2:
            // Set the tooltip text.
            pTTT->lpszText = _T("Second Button");

            // Set the tooltip text.
            pTTT->lpszText = _T("Tooltips everywhere!!!");

        return TRUE;

    // Not handled.
    return FALSE;

Targeted Audience – Beginners.

How to change the desktop wallpaper, programmatically.

27 04 2008

I bet at least once in your lifetime, you’ve used desktop wallpaper changing applications like webshots – which sets beautiful wallpaper to the desktop automatically after certain time intervals. When i started leaning windows programming, i wonder – how this application changes the wallpaper. The answer is – IActiveDesktop.

The IActiveDesktop is a com interface exposed by windows shell. You’ve to call the SetWallpaper() function and then apply the changes by calling ApplyChanges(). See the code snippet below.

#include "shlobj.h"

IActiveDesktop* pActiveDesktop = 0;

// Initialize COM.
::CoInitialize( 0 );

// Get the ActiveDesktop Interface.
hr = CoCreateInstance( CLSID_ActiveDesktop,
                       (void**) &pActiveDesktop );

// Check whether CoCreateInstance is success.
if( FAILED( hr ))
    // Creating ActiveDesktop interface pointer failed.
    AfxMessageBox( _T("Error Occurred!"));

// SetWallpaper() accepts the wallpaper path only as WideChar.
LPCWSTR strWallPaper = L"C:\\Autumn Leaves.jpg";

// Set the new wallpaper.
pActiveDesktop->SetWallpaper( strWallPaper, 0 );

// Apply changes to refresh desktop.
pActiveDesktop->ApplyChanges( AD_APPLY_ALL );

// Release the interface pointer.

// Uninitialize COM.

While compiling this, certainly you will hit the following error.

error C2065: 'IActiveDesktop' : undeclared identifier
error C2065: 'pActiveDesktop' : undeclared identifier
error C2106: '=' : left operand must be l-value

Don’t worry. Its a known issue. For solving this error, take StdAfx.h and include wininet.h header just before afxdisp.h. I assume you’re using MFC. See the sample below.

#include <afxwin.h>
#include <afxext.h>
#include "wininet.h"
#include <afxdisp.h>
#include <afxdtctl.h>

Keen to know more? See KB196342 for more details.

Trargeted Audience – Intermediate.

How to set the Minimum and Maximum window size while Resizing?

26 04 2008

In several applications, you might already seen, the dialog won’t resize after a particular limit. In other words those dialogs have a minimum and maximum dialog size even though they supports resizing. So how can we set the minimum – minimum size and maximum – maximum size of a dialog? 😉

You can utilize the message – WM_GETMINMAXINFO. This message is sent to the dialog to get the minimum and maximum window size. Pointer to struct MINMAXINFO is send as message params. We’ve set our required minimum and maximum window sizes in this MINMAXINFO struct. See the code snippet below. For easiness, I’ve implemented it in MFC.

Modify the message map as follows



Now add a function with the following signature to your dialog class.

void CDialogDlg::OnGetMinMaxInfo( MINMAXINFO FAR* pMinMaxInfo )
    // Preferred Maximum X & Y.
    const int MAX_SIZE_X = 750;
    const int MAX_SIZE_Y = 650;

    // Preferred Minimum X & Y.
    const int MIN_SIZE_X = 400;
    const int MIN_SIZE_Y = 350;

    // Set the maximum size. Used while maximizing.
    pMinMaxInfo->ptMaxSize.x = MAX_SIZE_X;
    pMinMaxInfo->ptMaxSize.y = MAX_SIZE_Y;

    // Set the Minimum Track Size. Used while resizing.
    pMinMaxInfo->ptMinTrackSize.x = MIN_SIZE_X;
    pMinMaxInfo->ptMinTrackSize.y = MIN_SIZE_Y;

    // Set the Maximum Track Size. Used while resizing.
    pMinMaxInfo->ptMaxTrackSize.x = MAX_SIZE_X;
    pMinMaxInfo->ptMaxTrackSize.y = MAX_SIZE_Y;

Now try to resize your dialog. Wowwww!!!

You can just handle it in the classic message proc also. All you should know is about the struct MINMAXINFO and its members.

Targeted Audience – Beginners.

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.