home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / com / dcom / mfccont / mfccontdlg.cpp < prev    next >
C/C++ Source or Header  |  1998-04-02  |  5KB  |  201 lines

  1. // MFCContDlg.cpp : implementation file
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "MFCCont.h"
  6. #include "MFCContDlg.h"
  7.  
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13.  
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16.  
  17. class CAboutDlg : public CDialog
  18. {
  19. public:
  20.     CAboutDlg();
  21.  
  22. // Dialog Data
  23.     //{{AFX_DATA(CAboutDlg)
  24.     enum { IDD = IDD_ABOUTBOX };
  25.     //}}AFX_DATA
  26.  
  27.     // ClassWizard generated virtual function overrides
  28.     //{{AFX_VIRTUAL(CAboutDlg)
  29.     protected:
  30.     virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  31.     //}}AFX_VIRTUAL
  32.  
  33. // Implementation
  34. protected:
  35.     //{{AFX_MSG(CAboutDlg)
  36.     //}}AFX_MSG
  37.     DECLARE_MESSAGE_MAP()
  38. };
  39.  
  40. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  41. {
  42.     //{{AFX_DATA_INIT(CAboutDlg)
  43.     //}}AFX_DATA_INIT
  44. }
  45.  
  46. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  47. {
  48.     CDialog::DoDataExchange(pDX);
  49.     //{{AFX_DATA_MAP(CAboutDlg)
  50.     //}}AFX_DATA_MAP
  51. }
  52.  
  53. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  54.     //{{AFX_MSG_MAP(CAboutDlg)
  55.         // No message handlers
  56.     //}}AFX_MSG_MAP
  57. END_MESSAGE_MAP()
  58.  
  59. /////////////////////////////////////////////////////////////////////////////
  60. // CMFCContDlg dialog
  61.  
  62. CMFCContDlg::CMFCContDlg(CWnd* pParent /*=NULL*/)
  63.     : CDialog(CMFCContDlg::IDD, pParent)
  64. {
  65.     //{{AFX_DATA_INIT(CMFCContDlg)
  66.         // NOTE: the ClassWizard will add member initialization here
  67.     //}}AFX_DATA_INIT
  68.     // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  69.     m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  70. }
  71.  
  72. void CMFCContDlg::DoDataExchange(CDataExchange* pDX)
  73. {
  74.     CDialog::DoDataExchange(pDX);
  75.     //{{AFX_DATA_MAP(CMFCContDlg)
  76.     DDX_Control(pDX, IDC_DRAWCTL1, m_DrawCtl);
  77.     //}}AFX_DATA_MAP
  78. }
  79.  
  80. BEGIN_MESSAGE_MAP(CMFCContDlg, CDialog)
  81.     //{{AFX_MSG_MAP(CMFCContDlg)
  82.     ON_WM_SYSCOMMAND()
  83.     ON_WM_PAINT()
  84.     ON_WM_QUERYDRAGICON()
  85.     ON_BN_CLICKED(IDC_CLEAR, OnClear)
  86.     ON_BN_CLICKED(IDC_CONNECT, OnConnect)
  87.     ON_BN_CLICKED(IDC_DISCONNECT, OnDisconnect)
  88.     //}}AFX_MSG_MAP
  89. END_MESSAGE_MAP()
  90.  
  91. /////////////////////////////////////////////////////////////////////////////
  92. // CMFCContDlg message handlers
  93.  
  94. BOOL CMFCContDlg::OnInitDialog()
  95. {
  96.     CDialog::OnInitDialog();
  97.  
  98.     // Add "About..." menu item to system menu.
  99.  
  100.     // IDM_ABOUTBOX must be in the system command range.
  101.     ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  102.     ASSERT(IDM_ABOUTBOX < 0xF000);
  103.  
  104.     CMenu* pSysMenu = GetSystemMenu(FALSE);
  105.     if (pSysMenu != NULL)
  106.     {
  107.         CString strAboutMenu;
  108.         strAboutMenu.LoadString(IDS_ABOUTBOX);
  109.         if (!strAboutMenu.IsEmpty())
  110.         {
  111.             pSysMenu->AppendMenu(MF_SEPARATOR);
  112.             pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  113.         }
  114.     }
  115.  
  116.     // Set the icon for this dialog.  The framework does this automatically
  117.     //  when the application's main window is not a dialog
  118.     SetIcon(m_hIcon, TRUE);         // Set big icon
  119.     SetIcon(m_hIcon, FALSE);        // Set small icon
  120.     
  121.     // TODO: Add extra initialization here
  122.     GetDlgItem(IDC_DISCONNECT)->EnableWindow(FALSE);    
  123.     
  124.     return TRUE;  // return TRUE  unless you set the focus to a control
  125. }
  126.  
  127. void CMFCContDlg::OnSysCommand(UINT nID, LPARAM lParam)
  128. {
  129.     if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  130.     {
  131.         CAboutDlg dlgAbout;
  132.         dlgAbout.DoModal();
  133.     }
  134.     else
  135.     {
  136.         CDialog::OnSysCommand(nID, lParam);
  137.     }
  138. }
  139.  
  140. // If you add a minimize button to your dialog, you will need the code below
  141. //  to draw the icon.  For MFC applications using the document/view model,
  142. //  this is automatically done for you by the framework.
  143.  
  144. void CMFCContDlg::OnPaint() 
  145. {
  146.     if (IsIconic())
  147.     {
  148.         CPaintDC dc(this); // device context for painting
  149.  
  150.         SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  151.  
  152.         // Center icon in client rectangle
  153.         int cxIcon = GetSystemMetrics(SM_CXICON);
  154.         int cyIcon = GetSystemMetrics(SM_CYICON);
  155.         CRect rect;
  156.         GetClientRect(&rect);
  157.         int x = (rect.Width() - cxIcon + 1) / 2;
  158.         int y = (rect.Height() - cyIcon + 1) / 2;
  159.  
  160.         // Draw the icon
  161.         dc.DrawIcon(x, y, m_hIcon);
  162.     }
  163.     else
  164.     {
  165.         CDialog::OnPaint();
  166.     }
  167. }
  168.  
  169. // The system calls this to obtain the cursor to display while the user drags
  170. //  the minimized window.
  171. HCURSOR CMFCContDlg::OnQueryDragIcon()
  172. {
  173.     return (HCURSOR) m_hIcon;
  174. }
  175.  
  176. void CMFCContDlg::OnClear() 
  177. {
  178.     m_DrawCtl.Clear();  
  179. }
  180.  
  181. void CMFCContDlg::OnConnect() 
  182. {
  183.     AfxGetApp()->BeginWaitCursor();
  184.     CEdit* pSource = (CEdit*) GetDlgItem(IDC_SOURCE);
  185.     CString s;
  186.     pSource->GetWindowText(s);
  187.     m_DrawCtl.Connect(s);
  188.     AfxGetApp()->EndWaitCursor();
  189.     GetDlgItem(IDC_DISCONNECT)->EnableWindow();
  190.     GetDlgItem(IDC_CONNECT)->EnableWindow(FALSE);   
  191. }
  192.  
  193. void CMFCContDlg::OnDisconnect() 
  194. {
  195.     AfxGetApp()->BeginWaitCursor();
  196.     m_DrawCtl.Disconnect();
  197.     AfxGetApp()->EndWaitCursor();
  198.     GetDlgItem(IDC_CONNECT)->EnableWindow();
  199.     GetDlgItem(IDC_DISCONNECT)->EnableWindow(FALSE);    
  200. }
  201.