SenderDlg.cpp
上传用户:lqt88888
上传日期:2009-12-14
资源大小:905k
文件大小:5k
源码类别:

书籍源码

开发平台:

Visual C++

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