www.gusucode.com > VC++屏幕取色程序源码升级版源码程序 > VC++屏幕取色程序源码升级版源码程序\code\PageDlg.cpp
// PageDlg.cpp : implementation file // download by http://www.NewXing.com #include "stdafx.h" #include "Page.h" #include "PageDlg.h" #ifdef _DEBUG #define new DEBUG_NEW #undef THIS_FILE static char THIS_FILE[] = __FILE__; #endif ///////////////////////////////////////////////////////////////////////////// class CAboutDlg : public CDialog { public: CAboutDlg(); // Dialog Data //{{AFX_DATA(CAboutDlg) enum { IDD = IDD_ABOUTBOX }; //}}AFX_DATA // ClassWizard generated virtual function overrides //{{AFX_VIRTUAL(CAboutDlg) protected: virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support //}}AFX_VIRTUAL // Implementation protected: //{{AFX_MSG(CAboutDlg) //}}AFX_MSG DECLARE_MESSAGE_MAP() }; CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD) { //{{AFX_DATA_INIT(CAboutDlg) //}}AFX_DATA_INIT } void CAboutDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CAboutDlg) //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CAboutDlg, CDialog) //{{AFX_MSG_MAP(CAboutDlg) // No message handlers //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPageDlg dialog CPageDlg::CPageDlg(CWnd* pParent /*=NULL*/) : CDialog(CPageDlg::IDD, pParent) { //{{AFX_DATA_INIT(CPageDlg) // NOTE: the ClassWizard will add member initialization here //}}AFX_DATA_INIT // Note that LoadIcon does not require a subsequent DestroyIcon in Win32 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME); } void CPageDlg::DoDataExchange(CDataExchange* pDX) { CDialog::DoDataExchange(pDX); //{{AFX_DATA_MAP(CPageDlg) DDX_Control(pDX, IDC_RECT, m_rcArea); //}}AFX_DATA_MAP } BEGIN_MESSAGE_MAP(CPageDlg, CDialog) //{{AFX_MSG_MAP(CPageDlg) ON_WM_SYSCOMMAND() ON_WM_PAINT() ON_WM_QUERYDRAGICON() ON_WM_LBUTTONDOWN() ON_MESSAGE(MYWM_NOTIFYICON,OnMyIconNotify) ON_MESSAGE(WM_HOTKEY,OnHotKey) ON_COMMAND(IDM_ABOUT, OnAbout) ON_COMMAND(IDM_EXIT, OnExit) //}}AFX_MSG_MAP END_MESSAGE_MAP() ///////////////////////////////////////////////////////////////////////////// // CPageDlg message handlers BOOL CPageDlg::OnInitDialog() { CDialog::OnInitDialog(); // Add "About..." menu item to system menu. // IDM_ABOUTBOX must be in the system command range. 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); } } // Set the icon for this dialog. The framework does this automatically // when the application's main window is not a dialog SetIcon(m_hIcon, TRUE); // Set big icon SetIcon(m_hIcon, FALSE); // Set small icon /*---------------------------------------------------------*/ m_PropertySheet.AddPage(&m_page1); m_PropertySheet.AddPage(&m_page2); m_PropertySheet.AddPage(&m_page3); m_PropertySheet.AddPage(&m_page4); //m_PropertySheet.SetActivePage(&m_page2); m_PropertySheet.Create(this, WS_CHILD | WS_VISIBLE, 0); //创建非摸态的属性表 m_PropertySheet.ModifyStyleEx (0, WS_EX_CONTROLPARENT); // 当对话框搜索下一个Tab项时,WS_EX_CONTROLPARENT标记避免了死循环发生的可能性,他可以让对话框搜索到属性表中的子窗体控件,就象对话框窗体上的其他普通控件一样 m_PropertySheet.ModifyStyle( 0, WS_TABSTOP ); //允许用户TAB键切换到属性表 CRect rcSheet; m_rcArea.GetWindowRect( &rcSheet ); // rcSheet.top+=20; rcSheet.left-=8; ScreenToClient( &rcSheet ); // m_PropertySheet.SetWindowPos( NULL, rcSheet.left, rcSheet.top, 0, 0, // SWP_NOZORDER | SWP_NOSIZE | SWP_NOACTIVATE ); // Subtract 7 from the left and top limits of the frame to account for the property sheet's margin. This magic number works for the default font used by the resource editor. m_PropertySheet.MoveWindow(rcSheet); /*---------------------------------------------------------*/ /*注*/ WORD virtualKey=::GetPrivateProfileInt("HotKey","HotkeyVK",0,".\\Settings.ini"); /*册*/ WORD systemKey=::GetPrivateProfileInt("HotKey","HotkeySystem",0,".\\Settings.ini"); /*系*/ //m_page2.m_hotkey.SetHotKey(virtualKey, systemKey); /*统*/ /*热*/ UINT fsModifiers = NULL; /*键*/ if (systemKey & HOTKEYF_ALT)// convert systemkeys to modifiers /**/ { /**/ fsModifiers |= MOD_ALT; /**/ } /**/ if (systemKey & HOTKEYF_CONTROL) /**/ { /**/ fsModifiers |= MOD_CONTROL; /**/ } /*注*/ if (systemKey & HOTKEYF_SHIFT) /*册*/ { /*系*/ fsModifiers |= MOD_SHIFT; /*统*/ } /*热*/ RegisterHotKey(AfxGetMainWnd()->m_hWnd,400, fsModifiers, virtualKey); /*键*/ /*---------------------状态栏---------------------------------*/ m_wndStatusBar.Create(WS_CHILD|WS_VISIBLE|CCS_BOTTOM, CRect(0,0,0,0), this, 102); int strPartDim[4]= {300,-1}; m_wndStatusBar.SetParts(2,strPartDim); m_wndStatusBar.SetText("欢迎使用",0,0 ); m_wndStatusBar.SetText("作者:三峡大学 程红秀",1,0); /*------------------------------------------------------------*/ TaskBarAddIcon(GetSafeHwnd(),121,AfxGetApp()->LoadIcon(IDR_MAINFRAME),"屏幕取色"); //添加任务栏图标 CRect rc; // //设置窗体的 位置; GetWindowRect(rc); ::MoveWindow(this->GetSafeHwnd(), ::GetPrivateProfileInt("WinPos","x",0,".\\Settings.ini"), ::GetPrivateProfileInt("WinPos","y",0,".\\Settings.ini"), rc.Width(), rc.Height(), true ); if(m_page2.m_bTopMost) // 设置窗体是是否在最前面 AfxGetMainWnd()->SetWindowPos(&CWnd::wndTopMost,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE); else AfxGetMainWnd()->SetWindowPos(&CWnd::wndNoTopMost ,0,0,0,0,SWP_NOSIZE | SWP_NOMOVE); if(m_page2.m_check_minimize) //是否最小化 PostMessage(WM_SYSCOMMAND, SC_MINIMIZE, 0); UpdateData(FALSE); return TRUE; } void CPageDlg::OnSysCommand(UINT nID, LPARAM lParam) { if ((nID & 0xFFF0) == IDM_ABOUTBOX) { CAboutDlg dlgAbout; dlgAbout.DoModal(); } else { CDialog::OnSysCommand(nID, lParam); } } void CPageDlg::OnPaint() { if (IsIconic()) { CPaintDC dc(this); // device context for painting SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0); // Center icon in client rectangle 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; // Draw the icon dc.DrawIcon(x, y, m_hIcon); } else { CDialog::OnPaint(); } } // The system calls this to obtain the cursor to display while the user drags // the minimized window. HCURSOR CPageDlg::OnQueryDragIcon() { return (HCURSOR) m_hIcon; } void CPageDlg::OnLButtonDown(UINT nFlags, CPoint point) { AfxGetMainWnd()->SendMessage(WM_NCLBUTTONDOWN,HTCAPTION,0); CDialog::OnLButtonDown(nFlags, point); } BOOL CPageDlg::TaskBarAddIcon(HWND hwnd, UINT uID, HICON hicon, LPSTR lpszTip) { NOTIFYICONDATA d; d.cbSize=sizeof(NOTIFYICONDATA); d.hWnd=hwnd; d.uID=uID; d.uFlags=NIF_ICON | NIF_TIP | NIF_MESSAGE; d.uCallbackMessage=MYWM_NOTIFYICON; d.hIcon=hicon; if(lpszTip) lstrcpy(d.szTip,lpszTip); else d.szTip[0]='\0'; return Shell_NotifyIcon(NIM_ADD,&d); } BOOL CPageDlg::TaskBarDeleteIcon(HWND hwnd, UINT uID) { NOTIFYICONDATA d; d.cbSize=sizeof(NOTIFYICONDATA); d.hWnd=hwnd; d.uID=uID; return Shell_NotifyIcon(NIM_DELETE,&d); } BOOL CPageDlg::TaskBarModifyIcon(HWND hwnd, UINT uID, HICON hicon, LPSTR lpszTip) { NOTIFYICONDATA d; d.cbSize=sizeof(NOTIFYICONDATA); d.hWnd=hwnd; d.uID=uID; d.uFlags=NIF_ICON | NIF_TIP | NIF_MESSAGE; d.uCallbackMessage=MYWM_NOTIFYICON; d.hIcon=hicon; if(lpszTip) lstrcpy(d.szTip,lpszTip); else d.szTip[0]='\0'; return Shell_NotifyIcon(NIM_MODIFY,&d); } void CPageDlg::OnMyIconNotify(WPARAM wParam,LPARAM lParam) { UINT uMouseMsg=LOWORD(lParam); switch(uMouseMsg) { case WM_LBUTTONDOWN: new CFaderWnd(this); ShowWindow(IsWindowVisible()? SW_HIDE:SW_SHOWNORMAL); break; case WM_RBUTTONDOWN: { CPoint point; GetCursorPos(&point); COfficeXPMenu m_popmenu; m_popmenu.LoadMenu(IDR_MENU1); m_popmenu.SetType(TYPE_XP); CMenu *psub = (CMenu *)m_popmenu.GetSubMenu(0); //获取第一个子菜单的指针 CRect rect; GetWindowRect(rect); DWORD dwID =psub->TrackPopupMenu((TPM_LEFTALIGN|TPM_RIGHTBUTTON), point.x,point.y, this); } break; } } LRESULT CPageDlg::OnHotKey(WPARAM wp,LPARAM lp) { if(wp==400 ) { ShowWindow(IsWindowVisible()?SW_HIDE:SW_SHOWNORMAL); } return 0; } BOOL CPageDlg::DestroyWindow() { CRect rc; ////保存窗体的位置信息 GetWindowRect(&rc); char szInfo[32]; ::WritePrivateProfileString("WinPos","x", itoa(rc.left ,szInfo,10),".\\Settings.ini"); ::WritePrivateProfileString("WinPos","y", itoa(rc.top ,szInfo,10),".\\Settings.ini"); TaskBarDeleteIcon(GetSafeHwnd(),121); //删除任务栏的图标 return CDialog::DestroyWindow(); } void CPageDlg::OnAbout() { CAboutDlg dlg; dlg.DoModal(); } void CPageDlg::OnExit() { SendMessage(WM_CLOSE,0,0); } void CPageDlg::SetStateText(CString str) { this->m_wndStatusBar.SetText(str,0,0); }