DebugDlg.cpp
上传用户:woomicn
上传日期:2017-11-10
资源大小:42k
文件大小:6k
源码类别:

多显示器编程

开发平台:

Visual C++

  1. // DebugDlg.cpp : implementation file
  2. //
  3. #include "stdafx.h"
  4. #include "Debug.h"
  5. #include "DebugDlg.h"
  6. #include "OptionsDlg.h"
  7. #include "Globals.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #undef THIS_FILE
  11. static char THIS_FILE[] = __FILE__;
  12. #endif
  13. long nNumber = 0L;
  14. /////////////////////////////////////////////////////////////////////////////
  15. // CAboutDlg dialog used for App About
  16. class CAboutDlg : public CDialog
  17. {
  18. public:
  19. CAboutDlg();
  20. // Dialog Data
  21. //{{AFX_DATA(CAboutDlg)
  22. enum { IDD = IDD_ABOUTBOX };
  23. //}}AFX_DATA
  24. // ClassWizard generated virtual function overrides
  25. //{{AFX_VIRTUAL(CAboutDlg)
  26. protected:
  27. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
  28. //}}AFX_VIRTUAL
  29. // Implementation
  30. protected:
  31. //{{AFX_MSG(CAboutDlg)
  32. virtual BOOL OnInitDialog();
  33. //}}AFX_MSG
  34. DECLARE_MESSAGE_MAP()
  35. };
  36. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  37. {
  38. //{{AFX_DATA_INIT(CAboutDlg)
  39. //}}AFX_DATA_INIT
  40. }
  41. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialog::DoDataExchange(pDX);
  44. //{{AFX_DATA_MAP(CAboutDlg)
  45. //}}AFX_DATA_MAP
  46. }
  47. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  48. //{{AFX_MSG_MAP(CAboutDlg)
  49. //}}AFX_MSG_MAP
  50. END_MESSAGE_MAP()
  51. /////////////////////////////////////////////////////////////////////////////
  52. // CDebugDlg dialog
  53. CDebugDlg::CDebugDlg(CWnd* pParent /*=NULL*/)
  54. : CDialog(CDebugDlg::IDD, pParent)
  55. {
  56. //{{AFX_DATA_INIT(CDebugDlg)
  57. //}}AFX_DATA_INIT
  58. // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
  59. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  60. }
  61. void CDebugDlg::DoDataExchange(CDataExchange* pDX)
  62. {
  63. CDialog::DoDataExchange(pDX);
  64. //{{AFX_DATA_MAP(CDebugDlg)
  65. DDX_Control(pDX, IDC_PROGRESS_LEVEL, m_ctlLevel);
  66. DDX_Control(pDX, IDSTOP, m_Stop);
  67. DDX_Control(pDX, IDC_MESSAGES, m_ctlMessages);
  68. //}}AFX_DATA_MAP
  69. }
  70. BEGIN_MESSAGE_MAP(CDebugDlg, CDialog)
  71. //{{AFX_MSG_MAP(CDebugDlg)
  72. ON_WM_SYSCOMMAND()
  73. ON_WM_PAINT()
  74. ON_WM_QUERYDRAGICON()
  75. ON_BN_CLICKED(IDOPTIONS, OnOptions)
  76. ON_BN_CLICKED(IDSTOP, OnStop)
  77. ON_BN_CLICKED(IDCLEARALL, OnClearall)
  78. ON_WM_COPYDATA()
  79. //}}AFX_MSG_MAP
  80. END_MESSAGE_MAP()
  81. /////////////////////////////////////////////////////////////////////////////
  82. // CDebugDlg message handlers
  83. BOOL CDebugDlg::OnInitDialog()
  84. {
  85. CDialog::OnInitDialog();
  86. // Add "About..." menu item to system menu.
  87. // IDM_ABOUTBOX must be in the system command range.
  88. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  89. ASSERT(IDM_ABOUTBOX < 0xF000);
  90. CMenu* pSysMenu = GetSystemMenu(FALSE);
  91. if (pSysMenu != NULL)
  92. {
  93. CString strAboutMenu;
  94. strAboutMenu.LoadString(IDS_ABOUTBOX);
  95. if (!strAboutMenu.IsEmpty())
  96. {
  97. pSysMenu->AppendMenu(MF_SEPARATOR);
  98. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  99. }
  100. }
  101. // Set the icon for this dialog.  The framework does this automatically
  102. //  when the application's main window is not a dialog
  103. SetIcon(m_hIcon, TRUE); // Set big icon
  104. SetIcon(m_hIcon, FALSE); // Set small icon
  105. if(bRunning)
  106. {
  107. m_Stop.SetWindowText("&Stop");
  108. }
  109. else
  110. {
  111. m_Stop.SetWindowText("&Start");
  112. }
  113. m_ctlLevel.SetPos(0);
  114. return TRUE;  // return TRUE  unless you set the focus to a control
  115. }
  116. void CDebugDlg::OnSysCommand(UINT nID, LPARAM lParam)
  117. {
  118. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  119. {
  120. CAboutDlg dlgAbout;
  121. dlgAbout.DoModal();
  122. }
  123. else
  124. {
  125. CDialog::OnSysCommand(nID, lParam);
  126. }
  127. }
  128. // If you add a minimize button to your dialog, you will need the code below
  129. //  to draw the icon.  For MFC applications using the document/view model,
  130. //  this is automatically done for you by the framework.
  131. void CDebugDlg::OnPaint() 
  132. {
  133. if (IsIconic())
  134. {
  135. CPaintDC dc(this); // device context for painting
  136. SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
  137. // Center icon in client rectangle
  138. int cxIcon = GetSystemMetrics(SM_CXICON);
  139. int cyIcon = GetSystemMetrics(SM_CYICON);
  140. CRect rect;
  141. GetClientRect(&rect);
  142. int x = (rect.Width() - cxIcon + 1) / 2;
  143. int y = (rect.Height() - cyIcon + 1) / 2;
  144. // Draw the icon
  145. dc.DrawIcon(x, y, m_hIcon);
  146. }
  147. else
  148. {
  149. CDialog::OnPaint();
  150. }
  151. }
  152. // The system calls this to obtain the cursor to display while the user drags
  153. //  the minimized window.
  154. HCURSOR CDebugDlg::OnQueryDragIcon()
  155. {
  156. return (HCURSOR) m_hIcon;
  157. }
  158. BOOL CAboutDlg::OnInitDialog() 
  159. {
  160. CDialog::OnInitDialog();
  161. CenterWindow();
  162. return TRUE;  // return TRUE unless you set the focus to a control
  163.               // EXCEPTION: OCX Property Pages should return FALSE
  164. }
  165. void CDebugDlg::OnOptions() 
  166. {
  167. COptionsDlg CMyOptionsDlg;
  168. CMyOptionsDlg.DoModal();
  169. }
  170. void CDebugDlg::OnStop() 
  171. {
  172. bRunning = !bRunning;
  173. if(bRunning)
  174. {
  175. nNumber = 0;
  176. m_Stop.SetWindowText("&Stop");
  177. }
  178. else
  179. {
  180. m_Stop.SetWindowText("&Start");
  181. }
  182. }
  183. void CDebugDlg::OnCancel() 
  184. {
  185. CDialog::OnCancel();
  186. }
  187. void CDebugDlg::OnClearall() 
  188. {
  189. nNumber = 0;
  190. SetDlgItemText(IDC_EDIT_HWND, "");
  191. m_ctlLevel.SetPos(0);
  192. m_ctlMessages.SetWindowText("");
  193. m_ctlMessages.SetFocus();
  194. }
  195. BOOL CDebugDlg::OnCopyData(CWnd* pWnd, COPYDATASTRUCT* pCopyDataStruct) 
  196. {
  197. char szMessage[512];
  198. if(!bRunning)
  199. return TRUE;
  200. char szHWND[16];
  201. sprintf(szHWND, "%#x", (LONG) pWnd->m_hWnd);
  202. SetDlgItemText(IDC_EDIT_HWND, szHWND);
  203. if(bShowAnimation)
  204. {
  205. m_ctlLevel.SetPos(25 * ((int)(pCopyDataStruct->dwData) + 1));
  206. }
  207. if(pCopyDataStruct->dwData == (DWORD) 0 && !bShowLevel0)
  208. {
  209. m_ctlLevel.SetPos(0);
  210. return TRUE;
  211. }
  212. if(pCopyDataStruct->dwData == (DWORD) 1 && !bShowLevel1)
  213. {
  214. m_ctlLevel.SetPos(0);
  215. return TRUE;
  216. }
  217. if(pCopyDataStruct->dwData == (DWORD) 2 && !bShowLevel2)
  218. {
  219. m_ctlLevel.SetPos(0);
  220. return TRUE;
  221. }
  222. if(pCopyDataStruct->dwData == (DWORD) 3 && !bShowLevel3)
  223. {
  224. m_ctlLevel.SetPos(0);
  225. return TRUE;
  226. }
  227. m_ctlMessages.SetFocus();
  228. if(bShowNumber)
  229. {
  230. nNumber++;
  231. wsprintf(szMessage, "%d: ", nNumber);
  232. }
  233. strncat(szMessage, (char *) pCopyDataStruct->lpData, pCopyDataStruct->cbData);
  234. strcat(szMessage, "rn");
  235. if(!bShowReversed)
  236. {
  237. m_ctlMessages.SetSel(-1, -1, TRUE);
  238. m_ctlMessages.ReplaceSel(szMessage, FALSE);
  239. }
  240. else
  241. {
  242. m_ctlMessages.SetSel(0, 0, TRUE);
  243. m_ctlMessages.ReplaceSel(szMessage, FALSE);
  244. }
  245. if(bShowAnimation)
  246. m_ctlLevel.SetPos(0);
  247. return TRUE;
  248. //return CDialog::OnCopyData(pWnd, pCopyDataStruct);
  249. }