WeChatsDlg.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. // WeChatsDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "WeChats.h"
  5. #include "WeChatsDlg.h"
  6. #include "CWxObject.h"
  7. #include "WxMgr.h"
  8. #ifdef _DEBUG
  9. #define new DEBUG_NEW
  10. #endif
  11. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  12. class CAboutDlg : public CDialog
  13. {
  14. public:
  15. CAboutDlg();
  16. // 对话框数据
  17. enum { IDD = IDD_ABOUTBOX };
  18. protected:
  19. virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
  20. // 实现
  21. protected:
  22. DECLARE_MESSAGE_MAP()
  23. };
  24. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  25. {
  26. }
  27. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  28. {
  29. CDialog::DoDataExchange(pDX);
  30. }
  31. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  32. END_MESSAGE_MAP()
  33. // CWeChatsDlg 对话框
  34. HWND g_hWxWnd = NULL;
  35. CWeChatsDlg::CWeChatsDlg(CWnd* pParent /*=NULL*/)
  36. : CDialog(CWeChatsDlg::IDD, pParent)
  37. {
  38. m_bMouseDown = FALSE;
  39. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  40. }
  41. void CWeChatsDlg::DoDataExchange(CDataExchange* pDX)
  42. {
  43. CDialog::DoDataExchange(pDX);
  44. }
  45. BEGIN_MESSAGE_MAP(CWeChatsDlg, CDialog)
  46. ON_WM_SYSCOMMAND()
  47. ON_WM_PAINT()
  48. ON_WM_QUERYDRAGICON()
  49. //}}AFX_MSG_MAP
  50. ON_BN_CLICKED(BTN_OPEN_WX, &CWeChatsDlg::OnBnClickedOpenWx)
  51. ON_WM_CTLCOLOR()
  52. ON_BN_CLICKED(BTN_ATTACH_WX, &CWeChatsDlg::OnBnClickedAttachWx)
  53. END_MESSAGE_MAP()
  54. // CWeChatsDlg 消息处理程序
  55. BOOL CWeChatsDlg::OnInitDialog()
  56. {
  57. CDialog::OnInitDialog();
  58. // 将“关于...”菜单项添加到系统菜单中。
  59. // IDM_ABOUTBOX 必须在系统命令范围内。
  60. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  61. ASSERT(IDM_ABOUTBOX < 0xF000);
  62. CMenu* pSysMenu = GetSystemMenu(FALSE);
  63. if (pSysMenu != NULL)
  64. {
  65. BOOL bNameValid;
  66. CString strAboutMenu;
  67. bNameValid = strAboutMenu.LoadString(IDS_ABOUTBOX);
  68. ASSERT(bNameValid);
  69. if (!strAboutMenu.IsEmpty())
  70. {
  71. pSysMenu->AppendMenu(MF_SEPARATOR);
  72. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  73. }
  74. }
  75. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  76. // 执行此操作
  77. SetIcon(m_hIcon, TRUE); // 设置大图标
  78. SetIcon(m_hIcon, FALSE); // 设置小图标
  79. // TODO: 在此添加额外的初始化代码
  80. CRect rcWxList, rcWxShow;
  81. GetDlgItem(RECT_WXLIST)->GetWindowRect(&rcWxList);
  82. GetDlgItem(RECT_WECHAT)->GetWindowRect(&rcWxShow);
  83. ScreenToClient(&rcWxList);
  84. ScreenToClient(&rcWxShow);
  85. m_wxMgr.SetMainWnd(this, rcWxList, rcWxShow);
  86. return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
  87. }
  88. void CWeChatsDlg::OnSysCommand(UINT nID, LPARAM lParam)
  89. {
  90. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  91. {
  92. CAboutDlg dlgAbout;
  93. dlgAbout.DoModal();
  94. }
  95. else
  96. {
  97. CDialog::OnSysCommand(nID, lParam);
  98. }
  99. }
  100. // 如果向对话框添加最小化按钮,则需要下面的代码
  101. // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  102. // 这将由框架自动完成。
  103. void CWeChatsDlg::OnPaint()
  104. {
  105. if (IsIconic())
  106. {
  107. CPaintDC dc(this); // 用于绘制的设备上下文
  108. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  109. // 使图标在工作区矩形中居中
  110. int cxIcon = GetSystemMetrics(SM_CXICON);
  111. int cyIcon = GetSystemMetrics(SM_CYICON);
  112. CRect rect;
  113. GetClientRect(&rect);
  114. int x = (rect.Width() - cxIcon + 1) / 2;
  115. int y = (rect.Height() - cyIcon + 1) / 2;
  116. // 绘制图标
  117. dc.DrawIcon(x, y, m_hIcon);
  118. }
  119. else
  120. {
  121. CDialog::OnPaint();
  122. }
  123. }
  124. //当用户拖动最小化窗口时系统调用此函数取得光标
  125. //显示。
  126. HCURSOR CWeChatsDlg::OnQueryDragIcon()
  127. {
  128. return static_cast<HCURSOR>(m_hIcon);
  129. }
  130. void CWeChatsDlg::OnBnClickedOpenWx()
  131. {
  132. // TODO: 在此添加控件通知处理程序代码
  133. m_wxMgr.OpenWeChat();
  134. }
  135. void CWeChatsDlg::OnBnClickedAttachWx()
  136. {
  137. // TODO: 在此添加控件通知处理程序代码
  138. m_wxMgr.AttachUnMgrWxProc(GetDlgItem(WX_RECT));
  139. }
  140. HBRUSH CWeChatsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  141. {
  142. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  143. // TODO: 在此更改 DC 的任何特性
  144. pDC->SetBkMode(TRANSPARENT);
  145. // TODO: 如果默认的不是所需画笔,则返回另一个画笔
  146. return hbr;
  147. }
  148. BOOL CWeChatsDlg::DestroyWindow()
  149. {
  150. // TODO: 在此添加专用代码和/或调用基类
  151. m_wxMgr.DetachAllWxProc();
  152. return CDialog::DestroyWindow();
  153. }
  154. BOOL CWeChatsDlg::PreTranslateMessage(MSG* pMsg)
  155. {
  156. // TODO: 在此添加专用代码和/或调用基类
  157. if (pMsg->hwnd == m_hWnd)
  158. {
  159. if (pMsg->message == WM_NCLBUTTONDOWN)
  160. {// 非客户区左键按下;
  161. m_bMouseDown = TRUE;
  162. }
  163. if (pMsg->message == WM_NCLBUTTONUP)
  164. {// 非客户区左键放开;
  165. m_bMouseDown = FALSE;
  166. }
  167. if (pMsg->message == WM_NCMOUSEMOVE)
  168. {// 非客户区鼠标移动;
  169. if (m_bMouseDown && m_wxObj.m_hWxMainWnd)
  170. {
  171. //::PostMessage(m_wxObj.m_hWxMainWnd,WM_SYSCOMMAND, SC_MAXIMIZE, NULL);
  172. }
  173. }
  174. }
  175. return CDialog::PreTranslateMessage(pMsg);
  176. }