Home | Gaming | Programming | Play Online | Contact | Keyword Query
Games++ Games & Game Programming

GAMES++
Games++ Home
Games++ Gaming
Games++ Programming
Beta Testing Games
Free Online Games
Hints & Cheats

BROWSER UTILITIES
E-mail This Page
Add to Favorites

SITE SEARCH

Web Games++

AFFILIATES
Cheat Codes
Trickster Wiki
Game Ratings
Gameboy Cheats
PlayStation Cheats
BlackBerry Games
Photoshop Tutorials
Illustrator Tutorials
ImageReady Tutorials

ADVERTISEMENT

Custom Debug Monitor

Visual C++ Programming

By Daniel Chirca

Source Code: CustomDebug.zip 45 KB

Environment: Visual C++ 6 (SP3)

Many times I wanted to have an easy way to get the same functionality in Microsoft Visual C++ that Visual Basic provides, i.e. to insert into the source code some debug messages and have them displayed at runtime into a separated, dedicated window (...the "Immediate" window in Visual Basic).

I have checked the existing solutions/workarounds (like MsgTracer, TraceWindow, ...), but none seemed enough flexible and very easy to use. So, I have decided to implement my own solution.

I have created a small utility, named Debug.exe, which is a mainly a messaging monitor window, where all the debugging messages sent from your application are displayed at runtime.

In order to use this utility, you need to follow these easy steps:

  1. Add CDebug.cpp and CDebug.h to your Visual C++ project.
  2. Declare a global instance of the CDebug class:

    CDebug Debug;
    
  3. Wherever you need in your source code to send (debug) messages, use one of the following functions:

    Debug.printf0(/* message */)
    Debug.printf1(/* message */)
    Debug.printf2(/* message */)
    Debug.printf3(/* message */)
    
    1. the last digit (0, 1, 2 or 3) means the level of the message (you can customize what levels you want to intercept in the Debug window).
    2. the syntax/arguments are the same as for the printf function... It will also accept a CString as first argument, in addition to LPTSTR and LPCTSTR.

  4. Run Debug.exe and customize, through "Options" how do you want to handle the arriving messages. (One nice idea might be to add the Debug.exe utility to the "Tools" IDE menu)
  5. Run your Visual C++ application.

Example Usage

//YourApp.cpp implementation file
 
#ifndef CDEBUG
 #include "CDebug.h"
#endif
extern CDebug Debug;
 
//....your code...
 
//...A function that uses the Debug facility...
//At runtime, the Debug.exe utility should be running in order
//to catch these messages...
BOOL CWOA_GridCtrl::IsRunMode()
{
 BOOL bIsRunMode;
 bIsRunMode = AmbientUserMode();
 
 Debug.Printf1("IsRunMode returns ", bIsRunMode);                                        
 return bIsRunMode;
}

About the Author: Daniel Chirca

Copyright © 1998-2007, Games++ All rights reserved. | Privacy Policy