home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / ole / tstcon / tctrace.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-03-27  |  1.3 KB  |  70 lines

  1. #include "StdAfx.H"
  2. #include "TestCon.H"
  3.  
  4. #ifdef _DEBUG
  5. #define new DEBUG_NEW
  6. #undef THIS_FILE
  7. static char THIS_FILE[] = __FILE__;
  8. #endif
  9.  
  10. static int g_nTraceLevel = TRACELEVEL_NORMAL;
  11.  
  12. int GetTraceLevel()
  13. {
  14.    return( g_nTraceLevel );
  15. }
  16.  
  17. void SetTraceLevel( int nLevel )
  18. {
  19.    g_nTraceLevel = nLevel;
  20. }
  21.  
  22. void __cdecl TCControlTrace( int nLevel, CTestContainer98Item* pItem,
  23.    LPCTSTR pszFormat, ... )
  24. {
  25.    va_list args;
  26.    va_start( args, pszFormat );
  27.  
  28.    int nBuf;
  29.    TCHAR szBuffer[512];
  30.    CString strItemName;
  31.  
  32.    if( g_nTraceLevel < nLevel )
  33.    {
  34.       return;
  35.    }
  36.  
  37.    strItemName = pItem->GetDisplayName();
  38.    sprintf( szBuffer, "TestCon: %s: ", LPCTSTR( strItemName ) );
  39.    OutputDebugString( szBuffer );
  40.  
  41.    nBuf = _vstprintf( szBuffer, pszFormat, args );
  42.    ASSERT( nBuf < sizeof( szBuffer ) );
  43.  
  44.    OutputDebugString( szBuffer );
  45.  
  46.    va_end( args );
  47. }
  48.  
  49. void __cdecl TCTrace( int nLevel, LPCTSTR pszFormat, ... )
  50. {
  51.    va_list args;
  52.    va_start( args, pszFormat );
  53.  
  54.    int nBuf;
  55.    TCHAR szBuffer[512];
  56.  
  57.    if( g_nTraceLevel < nLevel )
  58.    {
  59.       return;
  60.    }
  61.  
  62.    nBuf = _vstprintf( szBuffer, pszFormat, args );
  63.    ASSERT( nBuf < sizeof( szBuffer ) );
  64.  
  65.    OutputDebugString( _T( "TestCon: " ) );
  66.    OutputDebugString( szBuffer );
  67.  
  68.    va_end( args );
  69. }
  70.