WarHDlg.cpp
上传用户:tree100901
上传日期:2016-07-12
资源大小:182k
文件大小:6k
源码类别:

外挂编程

开发平台:

Visual C++

  1. // WarHDlg.cpp : 实现文件
  2. //
  3. #include "stdafx.h"
  4. #include "WarH.h"
  5. #include "MyTab.h"
  6. #include "StaticURL.h"
  7. #include "WarHDlg.h"
  8. #include "afxwin.h"
  9. #ifdef _DEBUG
  10. #define new DEBUG_NEW
  11. #endif
  12. // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
  13. class CAboutDlg : public CDialog
  14. {
  15. public:
  16. CAboutDlg();
  17. // 对话框数据
  18. enum { IDD = IDD_ABOUTBOX };
  19. protected:
  20. virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV 支持
  21. // 实现
  22. protected:
  23. DECLARE_MESSAGE_MAP()
  24. public:
  25. afx_msg void OnBnClickedTopwindow();
  26. public:
  27. BOOL m_bTop;
  28. };
  29. CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
  30. {
  31. m_bTop = FALSE;
  32. }
  33. void CAboutDlg::DoDataExchange(CDataExchange* pDX)
  34. {
  35. CDialog::DoDataExchange(pDX);
  36. DDX_Check(pDX, IDC_TOPWINDOW, m_bTop);
  37. }
  38. BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
  39. ON_BN_CLICKED(IDC_TOPWINDOW, &CAboutDlg::OnBnClickedTopwindow)
  40. END_MESSAGE_MAP()
  41. // CWarHDlg 对话框
  42. CWarHDlg::CWarHDlg(CWnd* pParent /*=NULL*/)
  43. : CDialog(CWarHDlg::IDD, pParent)
  44. {
  45. m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
  46. }
  47. void CWarHDlg::DoDataExchange(CDataExchange* pDX)
  48. {
  49. CDialog::DoDataExchange(pDX);
  50. DDX_Control(pDX, IDC_TAB, m_Tab);
  51. DDX_Control(pDX, IDC_URL, m_URL);
  52. }
  53. BEGIN_MESSAGE_MAP(CWarHDlg, CDialog)
  54. ON_WM_SYSCOMMAND()
  55. ON_WM_PAINT()
  56. ON_WM_QUERYDRAGICON()
  57. //}}AFX_MSG_MAP
  58. ON_WM_CTLCOLOR()
  59. END_MESSAGE_MAP()
  60. // CWarHDlg 消息处理程序
  61. BOOL CWarHDlg::OnInitDialog()
  62. {
  63. CDialog::OnInitDialog();
  64. // 将“关于...”菜单项添加到系统菜单中。
  65. // IDM_ABOUTBOX 必须在系统命令范围内。
  66. ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
  67. ASSERT(IDM_ABOUTBOX < 0xF000);
  68. CMenu* pSysMenu = GetSystemMenu(FALSE);
  69. if (pSysMenu != NULL)
  70. {
  71. CString strAboutMenu;
  72. strAboutMenu.LoadString(IDS_ABOUTBOX);
  73. if (!strAboutMenu.IsEmpty())
  74. {
  75. pSysMenu->AppendMenu(MF_SEPARATOR);
  76. pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  77. }
  78. }
  79. // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
  80. //  执行此操作
  81. SetIcon(m_hIcon, TRUE); // 设置大图标
  82. SetIcon(m_hIcon, FALSE); // 设置小图标
  83. // TODO: 在此添加额外的初始化代码
  84. m_Tab.InitTab();
  85. CRect rect;
  86. GetWindowRect(&rect);
  87. m_Tab.SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOMOVE);
  88. ::SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  89. return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
  90. }
  91. void CWarHDlg::OnSysCommand(UINT nID, LPARAM lParam)
  92. {
  93. if ((nID & 0xFFF0) == IDM_ABOUTBOX)
  94. {
  95. CAboutDlg dlgAbout;
  96. dlgAbout.DoModal();
  97. }
  98. else
  99. {
  100. CDialog::OnSysCommand(nID, lParam);
  101. }
  102. }
  103. // 如果向对话框添加最小化按钮,则需要下面的代码
  104. //  来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
  105. //  这将由框架自动完成。
  106. void CWarHDlg::OnPaint()
  107. {
  108. if (IsIconic())
  109. {
  110. CPaintDC dc(this); // 用于绘制的设备上下文
  111. SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
  112. // 使图标在工作矩形中居中
  113. int cxIcon = GetSystemMetrics(SM_CXICON);
  114. int cyIcon = GetSystemMetrics(SM_CYICON);
  115. CRect rect;
  116. GetClientRect(&rect);
  117. int x = (rect.Width() - cxIcon + 1) / 2;
  118. int y = (rect.Height() - cyIcon + 1) / 2;
  119. // 绘制图标
  120. dc.DrawIcon(x, y, m_hIcon);
  121. }
  122. else
  123. {
  124. CDialog::OnPaint();
  125. }
  126. }
  127. //当用户拖动最小化窗口时系统调用此函数取得光标显示。
  128. //
  129. HCURSOR CWarHDlg::OnQueryDragIcon()
  130. {
  131. return static_cast<HCURSOR>(m_hIcon);
  132. }
  133. HBRUSH CWarHDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
  134. {
  135. HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
  136. // TODO:  在此更改 DC 的任何属性
  137. int nID = pWnd->GetDlgCtrlID();
  138. if ( nID == IDC_STATIC)
  139. {
  140. pDC->SetTextColor(RGB(255, 0, 0));
  141. }
  142. else if(nID == IDC_URL)
  143. {
  144. pDC->SetTextColor(RGB(0, 0, 255));
  145. }
  146. // TODO:  如果默认的不是所需画笔,则返回另一个画笔
  147. return hbr;
  148. }
  149. void CAboutDlg::OnBnClickedTopwindow()
  150. {
  151. // TODO: 在此添加控件通知处理程序代码
  152. UpdateData(1);
  153. if (!m_bTop)
  154. {
  155. ::SetWindowPos(::AfxGetApp()->m_pMainWnd->GetSafeHwnd(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  156. }
  157. else
  158. {
  159. ::SetWindowPos(::AfxGetApp()->m_pMainWnd->GetSafeHwnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
  160. }
  161. }
  162. LRESULT CWarHDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
  163. {
  164. POINT point;
  165.     static NOTIFYICONDATA nid;
  166.     switch(message)
  167.     {
  168.     case WM_CREATE:
  169.         {
  170.         }
  171.         break;
  172.         
  173.     case WM_USER:
  174.         {
  175.             if(lParam == WM_LBUTTONDOWN)
  176.             {
  177. ::ShowWindow(m_hWnd, SW_NORMAL);
  178. Shell_NotifyIcon(NIM_DELETE, &nid);
  179.             }
  180. else if(lParam == WM_RBUTTONDOWN)
  181. {
  182. GetCursorPos(&point);
  183. ::SetForegroundWindow(m_hWnd);
  184.                 TrackPopupMenu(m_hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, m_hWnd, NULL);
  185. }
  186.         }
  187.         break;
  188. case WM_SIZE:
  189. if(wParam == SIZE_MINIMIZED)
  190. {
  191. ::ShowWindow(m_hWnd, SW_HIDE);
  192. m_hMenu = LoadMenu(::AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_MENU1));
  193.             m_hMenu = GetSubMenu(m_hMenu, 0);
  194.             nid.cbSize              =   sizeof(NOTIFYICONDATA);
  195.             nid.hWnd                =   m_hWnd;
  196. nid.hIcon               =   LoadIcon(::AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
  197.             nid.uCallbackMessage    =   WM_USER;
  198.             nid.uFlags              =   NIF_ICON | NIF_MESSAGE | NIF_TIP;
  199.             nid.uID                 =   IDR_MAINFRAME;
  200.             wcscpy(nid.szTip, _T("WarH V1.12"));
  201.             
  202.             Shell_NotifyIcon(NIM_ADD, &nid);
  203.         }
  204.         break;
  205. case WM_COMMAND:
  206.         {
  207.             switch(LOWORD(wParam))
  208.             {
  209.             case IDM_ABOUTBOX:
  210.                 {
  211. ::SendMessage(m_hWnd, WM_SYSCOMMAND, IDM_ABOUTBOX, 0);
  212.                 }
  213.                 break;
  214. case ID_MENU_SHOW:
  215.                 {
  216. ::ShowWindow(m_hWnd, SW_SHOWNORMAL);
  217.                 }
  218.                 break;
  219. case ID_MENU_HIDE:
  220.                 {
  221. ::ShowWindow(m_hWnd, SW_HIDE);
  222.                 }
  223.                 break;
  224.             case ID_MENU_EXIT:
  225.                 {
  226. ::SendMessage(m_hWnd, WM_CLOSE, 0, 0);
  227.                 }
  228.                 break;
  229.             }
  230. }
  231. break;
  232. }
  233. return CDialog::DefWindowProc(message, wParam, lParam);
  234. }