home *** CD-ROM | disk | FTP | other *** search
/ QBasic & Borland Pascal & C / Delphi5.iso / C / BC_502 / TRACER.PAK / TRACER.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1997-05-06  |  4.4 KB  |  203 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-1995 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.     //}}AFX_DATA
  34.  
  35.     void Save();
  36.     virtual void DoDataExchange(CDataExchange* pDX);
  37.  
  38. #ifdef _MAC
  39.     virtual BOOL OnInitDialog(void);
  40. #endif
  41.  
  42.     //{{AFX_MSG(CPromptDlg)
  43.     afx_msg void OnPaint();
  44.     //}}AFX_MSG
  45. #ifdef _MAC
  46.     afx_msg void OnSysCommand(UINT nID, LPARAM lParam);
  47. #endif
  48.     DECLARE_MESSAGE_MAP()
  49.  
  50. protected:
  51.     HICON    m_hIcon;
  52. };
  53.  
  54. BEGIN_MESSAGE_MAP(CPromptDlg, CDialog)
  55.     //{{AFX_MSG_MAP(CPromptDlg)
  56.     ON_WM_PAINT()
  57.     //}}AFX_MSG_MAP
  58. #ifdef _MAC
  59.     ON_WM_SYSCOMMAND()
  60. #endif
  61. END_MESSAGE_MAP()
  62.  
  63. static TCHAR BASED_CODE szSection[] = _T("Diagnostics");
  64.  
  65. CPromptDlg::CPromptDlg()
  66.     : CDialog(CPromptDlg::IDD)
  67. {
  68.     m_bEnabled = AfxGetApp()->GetProfileInt(szSection, _T("TraceEnabled"), 1);
  69.     UINT nFlags = AfxGetApp()->GetProfileInt(szSection, _T("TraceFlags"), 0);
  70.     //{{AFX_DATA_INIT(CPromptDlg)
  71.     m_b0 = (nFlags & 1) != 0;
  72.     m_b1 = (nFlags & 2) != 0;
  73.     m_b2 = (nFlags & 4) != 0;
  74.     m_b3 = (nFlags & 8) != 0;
  75.     m_b4 = (nFlags & 0x10) != 0;
  76.     m_b5 = (nFlags & 0x20) != 0;
  77.     //}}AFX_DATA_INIT
  78.  
  79.     m_hIcon = AfxGetApp()->LoadIcon(AFX_IDI_STD_FRAME);
  80. }
  81.  
  82. void CPromptDlg::DoDataExchange(CDataExchange* pDX)
  83. {
  84.     //{{AFX_DATA_MAP(CPromptDlg)
  85.     DDX_Check(pDX, IDC_ENABLEALL, m_bEnabled);
  86.     DDX_Check(pDX, IDC_BIT0, m_b0);
  87.     DDX_Check(pDX, IDC_BIT1, m_b1);
  88.     DDX_Check(pDX, IDC_BIT2, m_b2);
  89.     DDX_Check(pDX, IDC_BIT3, m_b3);
  90.     DDX_Check(pDX, IDC_BIT4, m_b4);
  91.     DDX_Check(pDX, IDC_BIT5, m_b5);
  92.     //}}AFX_DATA_MAP
  93. }
  94.  
  95. void CPromptDlg::Save()
  96. {
  97.     UINT nFlags = 0;
  98.     if (m_b0)
  99.         nFlags |= 1;
  100.     if (m_b1)
  101.         nFlags |= 2;
  102.     if (m_b2)
  103.         nFlags |= 4;
  104.     if (m_b3)
  105.         nFlags |= 8;
  106.     if (m_b4)
  107.         nFlags |= 0x10;
  108.     if (m_b5)
  109.         nFlags |= 0x20;
  110.  
  111.     if (!AfxGetApp()->WriteProfileInt(szSection, _T("TraceEnabled"), m_bEnabled) ||
  112.        !AfxGetApp()->WriteProfileInt(szSection, _T("TraceFlags"), nFlags))
  113.     {
  114.         CString strMsg;
  115.         strMsg.LoadString(IDS_WRITE_INI_FILE_FAILED);
  116.         AfxMessageBox(strMsg);
  117.     }
  118. }
  119.  
  120.  
  121. /////////////////////////////////////////////////////////////////////////////
  122. // Application class
  123.  
  124. class CTracerApp : public CWinApp
  125. {
  126. public:
  127.     virtual BOOL InitInstance();
  128. };
  129.  
  130. CTracerApp NEAR theTracerApp;
  131.  
  132. BOOL CTracerApp::InitInstance()
  133. {
  134.     Enable3dControls();
  135. #ifndef _MAC
  136.     m_pszProfileName = _T("AFX.INI");       // Profile API goes to AFX.INI
  137. #else
  138.     m_pszProfileName = _T("AFX Preferences"); // Profile API goes to AFX Preferences
  139. #endif
  140.  
  141.     CPromptDlg  dlg;
  142.     if (dlg.DoModal() == IDOK)
  143.         dlg.Save();
  144.  
  145.     ::PostQuitMessage(0);       // Exit application
  146.     return FALSE;               // FALSE means CWinApp::Run is not called
  147. }
  148.  
  149. /////////////////////////////////////////////////////////////////////////////
  150.  
  151. #ifdef _MAC
  152.  
  153. void CPromptDlg::OnSysCommand(UINT nID, LPARAM lParam)
  154. {
  155.  
  156.     if (LOWORD(nID) == ID_APP_ABOUT)
  157.     {
  158.         CDialog dlg("IDD_ABOUTBOX");
  159.         dlg.DoModal();
  160.     }
  161.     else
  162.     {
  163.         CDialog::OnSysCommand(nID, lParam);
  164.     }
  165. }
  166.  
  167.  
  168. BOOL CPromptDlg::OnInitDialog(void)
  169. {
  170.     CDialog::OnInitDialog();
  171.  
  172.     CMenu* pMenu = GetSystemMenu(FALSE);
  173.     pMenu->ModifyMenu(0, MF_BYPOSITION, ID_APP_ABOUT, "About Tracer");
  174.  
  175.     return TRUE;
  176. }
  177. #endif
  178.  
  179. void CPromptDlg::OnPaint() 
  180. {
  181.     if (IsIconic())
  182.     {
  183.         CPaintDC dc(this); // device context for painting
  184.  
  185.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  186.  
  187.         // Center icon in client rectangle
  188.         int cxIcon = GetSystemMetrics(SM_CXICON);
  189.         int cyIcon = GetSystemMetrics(SM_CYICON);
  190.         CRect rect;
  191.         GetClientRect(&rect);
  192.         int x = (rect.Width() - cxIcon + 1) / 2;
  193.         int y = (rect.Height() - cyIcon + 1) / 2;
  194.  
  195.         // Draw the icon
  196.         dc.DrawIcon(x, y, m_hIcon);
  197.     }
  198.     else
  199.     {
  200.         CDialog::OnPaint();
  201.     }    
  202. }
  203.