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

  1. // dlltrace.cpp : Defines the class behaviors for the application.
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. // This version of hello demonstrates communication with
  14. // a dynamic link library (DLL) implemented with the _USRDLL
  15. //version of the Microsoft Foundation Classes.
  16.  
  17. #include <afxwin.h>
  18. #include "resource.h"
  19. #include "traceapi.h"
  20.  
  21. // Note: This application doesn't really serve any useful purpose in
  22. //  either debug or release builds (it does not modify AFX.INI like
  23. //  the TRACER application does).  In debug builds, it is possible to
  24. //  tell that calling the dialog box actually changes the flags, since
  25. //  TRACE output is either enabled or disabled.  In release builds,
  26. //  the tracing facility of MFC is disabled unconditionally, so there
  27. //  is no way to tell that the flags have been changed, except for
  28. //  the fact that they are retained across calls to display the dialog
  29. //  box.
  30.  
  31. #ifndef _DEBUG
  32. static BOOL afxTraceEnabled;
  33. static int afxTraceFlags;
  34. #endif
  35.  
  36. /////////////////////////////////////////////////////////////////////////////
  37. // CMainWindow
  38.  
  39. class CMainWindow : public CFrameWnd
  40. {
  41. public:
  42.     CMainWindow();
  43.  
  44.     //{{AFX_MSG(CMainWindow)
  45.     afx_msg void OnPaint();
  46.     afx_msg void OnAbout();
  47.     afx_msg void OnTraceFlags();
  48.     //}}AFX_MSG
  49.  
  50.     DECLARE_MESSAGE_MAP()
  51. };
  52.  
  53. BEGIN_MESSAGE_MAP(CMainWindow, CFrameWnd)
  54.     //{{AFX_MSG_MAP(CMainWindow)
  55.     ON_WM_PAINT()
  56.     ON_COMMAND(ID_APP_ABOUT, OnAbout)
  57.     ON_COMMAND(ID_TRACE_FLAGS, OnTraceFlags)
  58.     //}}AFX_MSG_MAP
  59. END_MESSAGE_MAP()
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62.  
  63. CMainWindow::CMainWindow()
  64. {
  65.     VERIFY(Create(NULL, _T("Hello Foundation Application"),
  66.         WS_OVERLAPPEDWINDOW, rectDefault, NULL,
  67.         MAKEINTRESOURCE(IDR_MAINMENU)));
  68. }
  69.  
  70. void CMainWindow::OnPaint()
  71. {
  72.     CString s = "Hello, Windows! (with DLL support)";
  73.     CPaintDC dc(this);
  74.     CRect rect;
  75.  
  76.     GetClientRect(rect);
  77.     dc.SetTextAlign(TA_BASELINE | TA_CENTER);
  78.     dc.SetBkMode(TRANSPARENT);
  79.     dc.TextOut(rect.right / 2, rect.bottom / 2, s);
  80. }
  81.  
  82. void CMainWindow::OnAbout()
  83. {
  84.     CDialog(IDD_ABOUTBOX).DoModal();
  85. }
  86.  
  87. void CMainWindow::OnTraceFlags()
  88. {
  89.     struct TracerData data;
  90.     data.bEnabled = afxTraceEnabled;
  91.     data.flags = afxTraceFlags;
  92.  
  93.     TRACE0("Calling Tracer DLL\n");
  94.     if (PromptTraceFlags(this->m_hWnd, &data))
  95.     {
  96.         TRACE0("Changing trace flags\n");
  97.         afxTraceEnabled = data.bEnabled;
  98.         afxTraceFlags = data.flags;
  99.         TRACE0("Changed trace flags\n");
  100.     }
  101. }
  102.  
  103. /////////////////////////////////////////////////////////////////////////////
  104. // CTheApp
  105.  
  106. class CTheApp : public CWinApp
  107. {
  108. public:
  109.     virtual BOOL InitInstance();
  110.     virtual BOOL PreTranslateMessage(MSG* pMsg);
  111.     virtual BOOL OnIdle(LONG lCount);
  112. };
  113.  
  114. BOOL CTheApp::InitInstance()
  115. {
  116.     // standard initialization of a main window
  117.     Enable3dControls();
  118.  
  119.     m_pMainWnd = new CMainWindow;
  120.     m_pMainWnd->ShowWindow(m_nCmdShow);
  121.     m_pMainWnd->UpdateWindow();
  122.     return TRUE;
  123. }
  124.  
  125. BOOL CTheApp::PreTranslateMessage(MSG* pMsg)
  126. {
  127.     // special filter for DLL
  128.     if (CWinApp::PreTranslateMessage(pMsg))
  129.         return TRUE;
  130.  
  131.     return FilterDllMsg(pMsg);
  132. }
  133.  
  134. BOOL CTheApp::OnIdle(LONG lCount)
  135. {
  136.     if (CWinApp::OnIdle(lCount))
  137.         return TRUE;
  138.  
  139.     ProcessDllIdle();
  140.     return FALSE;   // no more for me to do
  141. }
  142.  
  143. CTheApp NEAR theApp; // application object
  144.  
  145. /////////////////////////////////////////////////////////////////////////////
  146.