WarHDlg.cpp
资源名称:WarH_2.10.rar [点击查看]
上传用户:tree100901
上传日期:2016-07-12
资源大小:182k
文件大小:6k
源码类别:
外挂编程
开发平台:
Visual C++
- // WarHDlg.cpp : 实现文件
- //
- #include "stdafx.h"
- #include "WarH.h"
- #include "MyTab.h"
- #include "StaticURL.h"
- #include "WarHDlg.h"
- #include "afxwin.h"
- #ifdef _DEBUG
- #define new DEBUG_NEW
- #endif
- // 用于应用程序“关于”菜单项的 CAboutDlg 对话框
- class CAboutDlg : public CDialog
- {
- public:
- CAboutDlg();
- // 对话框数据
- enum { IDD = IDD_ABOUTBOX };
- protected:
- virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV 支持
- // 实现
- protected:
- DECLARE_MESSAGE_MAP()
- public:
- afx_msg void OnBnClickedTopwindow();
- public:
- BOOL m_bTop;
- };
- CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
- {
- m_bTop = FALSE;
- }
- void CAboutDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Check(pDX, IDC_TOPWINDOW, m_bTop);
- }
- BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
- ON_BN_CLICKED(IDC_TOPWINDOW, &CAboutDlg::OnBnClickedTopwindow)
- END_MESSAGE_MAP()
- // CWarHDlg 对话框
- CWarHDlg::CWarHDlg(CWnd* pParent /*=NULL*/)
- : CDialog(CWarHDlg::IDD, pParent)
- {
- m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
- }
- void CWarHDlg::DoDataExchange(CDataExchange* pDX)
- {
- CDialog::DoDataExchange(pDX);
- DDX_Control(pDX, IDC_TAB, m_Tab);
- DDX_Control(pDX, IDC_URL, m_URL);
- }
- BEGIN_MESSAGE_MAP(CWarHDlg, CDialog)
- ON_WM_SYSCOMMAND()
- ON_WM_PAINT()
- ON_WM_QUERYDRAGICON()
- //}}AFX_MSG_MAP
- ON_WM_CTLCOLOR()
- END_MESSAGE_MAP()
- // CWarHDlg 消息处理程序
- BOOL CWarHDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- // 将“关于...”菜单项添加到系统菜单中。
- // IDM_ABOUTBOX 必须在系统命令范围内。
- ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
- ASSERT(IDM_ABOUTBOX < 0xF000);
- CMenu* pSysMenu = GetSystemMenu(FALSE);
- if (pSysMenu != NULL)
- {
- CString strAboutMenu;
- strAboutMenu.LoadString(IDS_ABOUTBOX);
- if (!strAboutMenu.IsEmpty())
- {
- pSysMenu->AppendMenu(MF_SEPARATOR);
- pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
- }
- }
- // 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
- // 执行此操作
- SetIcon(m_hIcon, TRUE); // 设置大图标
- SetIcon(m_hIcon, FALSE); // 设置小图标
- // TODO: 在此添加额外的初始化代码
- m_Tab.InitTab();
- CRect rect;
- GetWindowRect(&rect);
- m_Tab.SetWindowPos(NULL, 0, 0, rect.Width(), rect.Height(), SWP_NOMOVE);
- ::SetWindowPos(m_hWnd, HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- return TRUE; // 除非将焦点设置到控件,否则返回 TRUE
- }
- void CWarHDlg::OnSysCommand(UINT nID, LPARAM lParam)
- {
- if ((nID & 0xFFF0) == IDM_ABOUTBOX)
- {
- CAboutDlg dlgAbout;
- dlgAbout.DoModal();
- }
- else
- {
- CDialog::OnSysCommand(nID, lParam);
- }
- }
- // 如果向对话框添加最小化按钮,则需要下面的代码
- // 来绘制该图标。对于使用文档/视图模型的 MFC 应用程序,
- // 这将由框架自动完成。
- void CWarHDlg::OnPaint()
- {
- if (IsIconic())
- {
- CPaintDC dc(this); // 用于绘制的设备上下文
- SendMessage(WM_ICONERASEBKGND, reinterpret_cast<WPARAM>(dc.GetSafeHdc()), 0);
- // 使图标在工作矩形中居中
- int cxIcon = GetSystemMetrics(SM_CXICON);
- int cyIcon = GetSystemMetrics(SM_CYICON);
- CRect rect;
- GetClientRect(&rect);
- int x = (rect.Width() - cxIcon + 1) / 2;
- int y = (rect.Height() - cyIcon + 1) / 2;
- // 绘制图标
- dc.DrawIcon(x, y, m_hIcon);
- }
- else
- {
- CDialog::OnPaint();
- }
- }
- //当用户拖动最小化窗口时系统调用此函数取得光标显示。
- //
- HCURSOR CWarHDlg::OnQueryDragIcon()
- {
- return static_cast<HCURSOR>(m_hIcon);
- }
- HBRUSH CWarHDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
- {
- HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);
- // TODO: 在此更改 DC 的任何属性
- int nID = pWnd->GetDlgCtrlID();
- if ( nID == IDC_STATIC)
- {
- pDC->SetTextColor(RGB(255, 0, 0));
- }
- else if(nID == IDC_URL)
- {
- pDC->SetTextColor(RGB(0, 0, 255));
- }
- // TODO: 如果默认的不是所需画笔,则返回另一个画笔
- return hbr;
- }
- void CAboutDlg::OnBnClickedTopwindow()
- {
- // TODO: 在此添加控件通知处理程序代码
- UpdateData(1);
- if (!m_bTop)
- {
- ::SetWindowPos(::AfxGetApp()->m_pMainWnd->GetSafeHwnd(), HWND_NOTOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- }
- else
- {
- ::SetWindowPos(::AfxGetApp()->m_pMainWnd->GetSafeHwnd(), HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE);
- }
- }
- LRESULT CWarHDlg::DefWindowProc(UINT message, WPARAM wParam, LPARAM lParam)
- {
- POINT point;
- static NOTIFYICONDATA nid;
- switch(message)
- {
- case WM_CREATE:
- {
- }
- break;
- case WM_USER:
- {
- if(lParam == WM_LBUTTONDOWN)
- {
- ::ShowWindow(m_hWnd, SW_NORMAL);
- Shell_NotifyIcon(NIM_DELETE, &nid);
- }
- else if(lParam == WM_RBUTTONDOWN)
- {
- GetCursorPos(&point);
- ::SetForegroundWindow(m_hWnd);
- TrackPopupMenu(m_hMenu, TPM_RIGHTBUTTON, point.x, point.y, 0, m_hWnd, NULL);
- }
- }
- break;
- case WM_SIZE:
- if(wParam == SIZE_MINIMIZED)
- {
- ::ShowWindow(m_hWnd, SW_HIDE);
- m_hMenu = LoadMenu(::AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_MENU1));
- m_hMenu = GetSubMenu(m_hMenu, 0);
- nid.cbSize = sizeof(NOTIFYICONDATA);
- nid.hWnd = m_hWnd;
- nid.hIcon = LoadIcon(::AfxGetApp()->m_hInstance, MAKEINTRESOURCE(IDR_MAINFRAME));
- nid.uCallbackMessage = WM_USER;
- nid.uFlags = NIF_ICON | NIF_MESSAGE | NIF_TIP;
- nid.uID = IDR_MAINFRAME;
- wcscpy(nid.szTip, _T("WarH V1.12"));
- Shell_NotifyIcon(NIM_ADD, &nid);
- }
- break;
- case WM_COMMAND:
- {
- switch(LOWORD(wParam))
- {
- case IDM_ABOUTBOX:
- {
- ::SendMessage(m_hWnd, WM_SYSCOMMAND, IDM_ABOUTBOX, 0);
- }
- break;
- case ID_MENU_SHOW:
- {
- ::ShowWindow(m_hWnd, SW_SHOWNORMAL);
- }
- break;
- case ID_MENU_HIDE:
- {
- ::ShowWindow(m_hWnd, SW_HIDE);
- }
- break;
- case ID_MENU_EXIT:
- {
- ::SendMessage(m_hWnd, WM_CLOSE, 0, 0);
- }
- break;
- }
- }
- break;
- }
- return CDialog::DefWindowProc(message, wParam, lParam);
- }