So here I was debugging my super awesome stop watch, and I was debugging it using the win32 MessageBox function. If I wished to check whether my program is calling a function, I would put a message box in the function. To check whether the flow is going into a condition or not, I would put a message box. To check If  a window Message is recieved, you guessed it a message box. Basically, I was mimicking the Printf, Println to the console debugging, Which meant I had a lot of message boxes for debugging purposes.  I know this isn’t the most proper way of doing things, but I guess I like the simplicity of print statements i.e message box displays while debugging.

So the situation was that I had a lot of debugging code in my actual code. This code needed to be compiled and executed only when the project was running under the debug build, and not under release build. The simplest solution was to enclose all my debug code as follows

#ifdef _DEBUG
 MessageBox(...)
#endif

Whenever we are in the debug build, Visual Studio defines the _DEBUG Macro for us (Its under the project settings). Thus when we compile a debug build, my message boxes would work and during a release build they would never be compiled into the executable.

This was the simpleset solution, but the problem was my code started to look crowded. i.e every time I wanted to put a debug message box I had to type in at least three lines of code, thus increasing the size of my code. The other problem that I still faced was with the message box function itself. The typical message box function looks something like this

MessageBox(NULL, L"Caption", L"Message", MB_OK|MB_CANCEL|MB_ICONEXCLAMATION);

Now as far as debugging was concerned, I always wanted a message box with just MB_OK button, and didn’t care about the icon displays. But I still had to type the entire message box call each time I wanted to have a message box. This is where pre processer macros helped out a lot. To reduce the message box call, I ended up with a macro as follows

#define POPINFO(X, Y) { MessageBox(NULL, L#X, L#Y, MB_OK); }

So now I just replaced all my MessageBox calls with POPINFO calls, for example

POPINFO(Constructor, Inside Constructor of Application);

This had a very nice side effect, I no longer had to enclose my strings with a L”..”.
I further refined this macro to take into consideration the _DEBUG flag as follows

#ifdef POPINFOENABLE
    #ifndef POPINFO
        #define POPINFO(X, Y) { MessageBox(NULL, L#X, L#Y, MB_OK); }
    #endif
#else
    #ifndef POPINFO
        #define POPINFO(X, Y)
    #endif
#endif

Whenever I wanted to enable debug Message Boxes, I would define the POPINFOENABLE macro and whenever I didnt want them, I would not define it, or explicitly undef it. This was my solution to simplifying the use of MessageBox for debugging purposes. I hope everyone find it to be useful, and would love to hear how you go about debugging your windows apps.