home *** CD-ROM | disk | FTP | other *** search
/ Troubleshooting Netware Systems / CSTRIAL0196.BIN / attach / msj / v10n10 / cppq1195.exe / TRACEWIN.H < prev    next >
C/C++ Source or Header  |  1995-10-01  |  2KB  |  79 lines

  1. ////////////////////////////////////////////////////////////////
  2. // TRACEWIN Copyright 1995 Microsoft Systems Journal. 
  3. // If this program works, it was written by Paul DiLascia.
  4. // If not, I don't know who wrote it.
  5. //
  6. // TRACEWIN header file. Include this file in any application you want to
  7. // use TRACEWIN. #include-ing this file will make diagnostic output go
  8. // to the TRACEWIN applet if it is running.
  9. //
  10. // You should only #include this file one place in your app.
  11. // 
  12. // You must also call CMfxTrace::Init as the first thing in your app's 
  13. // InitInstance function.
  14. //
  15. //
  16. #define TRACEWND_CLASSNAME "MfxTraceWindow"
  17. #define TRACEWND_MESSAGE   "*WM_TRACE_MSG"
  18.  
  19. #ifdef _DEBUG
  20.  
  21. class CMfxTrace : public CFile {
  22.     static CMfxTrace theTracer;    // one-and-only tracing object
  23.     CMfxTrace();                        // private constructor
  24. public:
  25.     virtual void Write(const void* lpBuf, UINT nCount);
  26.     static void Init();
  27. };
  28.  
  29. // The one and only tracer
  30. CMfxTrace CMfxTrace::theTracer;
  31.  
  32. //////////////////
  33. // Constructor installs itself as file afxDump
  34. //
  35. CMfxTrace::CMfxTrace()
  36. {
  37.     ASSERT(this==&theTracer);
  38. }
  39.  
  40. /////////////////
  41. // Initialize tracing. Replace global afxDump.m_pFile with me.
  42. //
  43. void CMfxTrace::Init()
  44. {
  45.     if (afxDump.m_pFile == NULL) {
  46.         afxDump.m_pFile = &theTracer;
  47.     } else if (afxDump.m_pFile != &theTracer) {
  48.         TRACE("afxDump is already using a file: TRACEWIN not installed.\n");
  49.     }
  50. }
  51.  
  52. //////////////////
  53. // Override Write function to Write to TRACEWIN applet instead of file.
  54. //
  55. void CMfxTrace::Write(const void* lpBuf, UINT nCount)
  56. {
  57.     if (!afxTraceEnabled)
  58.         return;
  59.  
  60.     CWnd *pTraceWnd = CWnd::FindWindow(TRACEWND_CLASSNAME, NULL);
  61.     if (pTraceWnd) {
  62.         static UINT WM_TRACE_MSG = RegisterWindowMessage(TRACEWND_MESSAGE);
  63.  
  64.         // Found Trace window: send message there as a global atom.
  65.         // Delete atom after use.
  66.         //
  67.         ATOM atom = GlobalAddAtom((LPCSTR)lpBuf);
  68.         pTraceWnd->SendMessage(WM_TRACE_MSG, (WPARAM)atom);
  69.         GlobalDeleteAtom(atom);
  70.  
  71.     } else {
  72.         // No trace window: do normal debug thing
  73.         //
  74.         ::OutputDebugString((LPCSTR)lpBuf);    
  75.     }
  76. }
  77.  
  78. #endif // _DEBUG
  79.