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

  1. // tracer.cpp : MFC Windows trace control 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. #include "stdafx.h"
  14. #include "resource.h"
  15. #include <afxwin.h>
  16.  
  17. /////////////////////////////////////////////////////////////////////////////
  18. // Dialog class
  19.  
  20. class CPromptDlg : public CDialog
  21. {
  22. public:
  23.     CPromptDlg();
  24.     //{{AFX_DATA(CPromptDlg)
  25.     enum { IDD = IDD_PROMPT };
  26.     BOOL    m_bEnabled;
  27.     BOOL    m_b0;
  28.     BOOL    m_b1;
  29.     BOOL    m_b2;
  30.     BOOL    m_b3;
  31.     BOOL    m_b4;
  32.     BOOL    m_b5;
  33.     BOOL    m_b6;
  34.     //}}AFX_DATA
  35.  
  36.     void Save();
  37.     virtual void DoDataExchange(CDataExchange* pDX);
  38.  
  39.     //{{AFX_MSG(CPromptDlg)
  40.     afx_msg void OnPaint();
  41.     //}}AFX_MSG
  42.     DECLARE_MESSAGE_MAP()
  43.  
  44. protected:
  45.     HICON   m_hIcon;
  46. };
  47.  
  48. BEGIN_MESSAGE_MAP(CPromptDlg, CDialog)
  49.     //{{AFX_MSG_MAP(CPromptDlg)
  50.     ON_WM_PAINT()
  51.     //}}AFX_MSG_MAP
  52. END_MESSAGE_MAP()
  53.  
  54. static TCHAR BASED_CODE szSection[] = _T("Diagnostics");
  55.  
  56. CPromptDlg::CPromptDlg()
  57.     : CDialog(CPromptDlg::IDD)
  58. {
  59.     m_bEnabled = AfxGetApp()->GetProfileInt(szSection, _T("TraceEnabled"), 1);
  60.     UINT nFlags = AfxGetApp()->GetProfileInt(szSection, _T("TraceFlags"), 0);
  61.     //{{AFX_DATA_INIT(CPromptDlg)
  62.     m_b0 = (nFlags & 1) != 0;
  63.     m_b1 = (nFlags & 2) != 0;
  64.     m_b2 = (nFlags & 4) != 0;
  65.     m_b3 = (nFlags & 8) != 0;
  66.     m_b4 = (nFlags & 0x10) != 0;
  67.     m_b5 = (nFlags & 0x20) != 0;
  68.     m_b6 = (nFlags & 0x40) != 0;
  69.     //}}AFX_DATA_INIT
  70.  
  71.     m_hIcon = AfxGetApp()->LoadIcon(AFX_IDI_STD_FRAME);
  72. }
  73.  
  74. void CPromptDlg::DoDataExchange(CDataExchange* pDX)
  75. {
  76.     //{{AFX_DATA_MAP(CPromptDlg)
  77.     DDX_Check(pDX, IDC_ENABLEALL, m_bEnabled);
  78.     DDX_Check(pDX, IDC_BIT0, m_b0);
  79.     DDX_Check(pDX, IDC_BIT1, m_b1);
  80.     DDX_Check(pDX, IDC_BIT2, m_b2);
  81.     DDX_Check(pDX, IDC_BIT3, m_b3);
  82.     DDX_Check(pDX, IDC_BIT4, m_b4);
  83.     DDX_Check(pDX, IDC_BIT5, m_b5);
  84.     DDX_Check(pDX, IDC_BIT6, m_b6);
  85.     //}}AFX_DATA_MAP
  86. }
  87.  
  88. void CPromptDlg::Save()
  89. {
  90.     UINT nFlags = 0;
  91.     if (m_b0)
  92.         nFlags |= 1;
  93.     if (m_b1)
  94.         nFlags |= 2;
  95.     if (m_b2)
  96.         nFlags |= 4;
  97.     if (m_b3)
  98.         nFlags |= 8;
  99.     if (m_b4)
  100.         nFlags |= 0x10;
  101.     if (m_b5)
  102.         nFlags |= 0x20;
  103.     if (m_b6)
  104.         nFlags |= 0x40;
  105.  
  106.     if (!AfxGetApp()->WriteProfileInt(szSection, _T("TraceEnabled"), m_bEnabled) ||
  107.        !AfxGetApp()->WriteProfileInt(szSection, _T("TraceFlags"), nFlags))
  108.     {
  109.         CString strMsg;
  110.         strMsg.LoadString(IDS_WRITE_INI_FILE_FAILED);
  111.         AfxMessageBox(strMsg);
  112.     }
  113. }
  114.  
  115.  
  116. /////////////////////////////////////////////////////////////////////////////
  117. // Application class
  118.  
  119. class CTracerApp : public CWinApp
  120. {
  121. public:
  122.     virtual BOOL InitInstance();
  123. };
  124.  
  125. CTracerApp NEAR theTracerApp;
  126.  
  127. BOOL CTracerApp::InitInstance()
  128. {
  129.     Enable3dControls();
  130.     m_pszProfileName = _T("AFX.INI");       // Profile API goes to AFX.INI
  131.  
  132.     CPromptDlg  dlg;
  133.     if (dlg.DoModal() == IDOK)
  134.         dlg.Save();
  135.  
  136.     ::PostQuitMessage(0);       // Exit application
  137.     return FALSE;               // FALSE means CWinApp::Run is not called
  138. }
  139.  
  140. /////////////////////////////////////////////////////////////////////////////
  141.  
  142. void CPromptDlg::OnPaint()
  143. {
  144.     if (IsIconic())
  145.     {
  146.         CPaintDC dc(this); // device context for painting
  147.  
  148.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  149.  
  150.         // Center icon in client rectangle
  151.         int cxIcon = GetSystemMetrics(SM_CXICON);
  152.         int cyIcon = GetSystemMetrics(SM_CYICON);
  153.         CRect rect;
  154.         GetClientRect(&rect);
  155.         int x = (rect.Width() - cxIcon + 1) / 2;
  156.         int y = (rect.Height() - cyIcon + 1) / 2;
  157.  
  158.         // Draw the icon
  159.         dc.DrawIcon(x, y, m_hIcon);
  160.     }
  161.     else
  162.     {
  163.         CDialog::OnPaint();
  164.     }
  165. }
  166.