⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pagedlg.cpp

📁 这源代码是《白领就业指南:visual c++ 6.0 设计师之路》的配套源代码
💻 CPP
字号:
// PageDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Page.h"
#include "PageDlg.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

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(WM_HOTKEY,OnHotKey)
	ON_MESSAGE(MYWM_NOTIFYICON,OnMyIconNotify)
	//}}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


	/*注*/		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);
	/*键*/	
	

	
	/*注*/		WORD vKey=::GetPrivateProfileInt("HotKey_SS","vKey",0,".\\Settings.ini");
	/*册*/		WORD sKey=::GetPrivateProfileInt("HotKey_SS","sKey",0,".\\Settings.ini");
	/*系*/		//m_page2.m_hotkey.SetHotKey(virtualKey, systemKey);	
	/*统*/		
	/*热*/		UINT fs = NULL;		
	/*键*/		if (sKey & HOTKEYF_ALT)// convert systemkeys to modifiers
	/**/		{
	/**/			fs	|= MOD_ALT;
	/**/		}
	/**/		if (sKey & HOTKEYF_CONTROL)
	/**/		{
	/**/			fs	|= MOD_CONTROL;
	/**/		}
	/*注*/		if (sKey & HOTKEYF_SHIFT)
	/*册*/		{
	/*系*/			fs	|= MOD_SHIFT;
	/*统*/		}
	/*热*/		RegisterHotKey(AfxGetMainWnd()->m_hWnd,401, fs, vKey);
	/*键*/	
	

	/*注*/		WORD vKey2=::GetPrivateProfileInt("HotKey_SS","vKey2",0,".\\Settings.ini");
	/*册*/		WORD sKey2=::GetPrivateProfileInt("HotKey_SS","sKey2",0,".\\Settings.ini");
	/*系*/		//m_page2.m_hotkey.SetHotKey(virtualKey, systemKey);	
	/*统*/		
	/*热*/		UINT fs2 = NULL;		
	/*键*/		if (sKey2 & HOTKEYF_ALT)// convert systemkeys to modifiers
	/**/		{
	/**/			fs2	|= MOD_ALT;
	/**/		}
	/**/		if (sKey2 & HOTKEYF_CONTROL)
	/**/		{
	/**/			fs2	|= MOD_CONTROL;
	/**/		}
	/*注*/		if (sKey2 & HOTKEYF_SHIFT)
	/*册*/		{
	/*系*/			fs2	|= MOD_SHIFT;
	/*统*/		}
	/*热*/		RegisterHotKey(AfxGetMainWnd()->m_hWnd,402, fs2, vKey2);
	/*键*/	
/*---------------------------------------------------------*/

	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);

/*---------------------------------------------------------*/
/*---------------------状态栏---------------------------------*/		
	CTime time=CTime::GetCurrentTime();	
	CString m_strTime=time.Format("%X");	
	m_strTime="程序启动时间 "+m_strTime;
	 
	m_wndStatusBar.Create(WS_CHILD|WS_VISIBLE|CCS_BOTTOM,  CRect(0,0,0,0),  this,  102);

	int strPartDim[4]= {100,300,-1};	     
	m_wndStatusBar.SetParts(3,strPartDim);

	m_wndStatusBar.SetText("欢迎使用",0,0 );
	m_wndStatusBar.SetText(m_strTime,1,0);
	m_wndStatusBar.SetText("作者:老牛",2,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);


	if ( ((CPageApp*)AfxGetApp())->pSplashThread != NULL)
		((CPageApp*)AfxGetApp())->pSplashThread->HideSplash();     //在创建了主对话框 并初始化了各个子对话框以后,隐藏启动画面	

	return TRUE; 
}

void CPageDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
	if ((nID & 0xFFF0) == IDM_ABOUTBOX)
	{
		CAboutDlg dlgAbout;
		dlgAbout.DoModal();
	}
		
	if(nID==SC_MINIMIZE)
	{
		ShowWindow(SW_HIDE);
	}

	else
	{
		CDialog::OnSysCommand(nID, lParam);
	}
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

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:
		{
			ShowWindow(IsWindowVisible()? SW_HIDE:SW_SHOWNORMAL);
		
		}break;

	case WM_RBUTTONDOWN:
		{
			CPoint point;
			GetCursorPos(&point);
			
			COfficeXPMenu m_menu;
			m_menu.LoadMenu(IDR_MENU1);	
			m_menu.SetType(TYPE_XP);			
			//	ClientToScreen(&point);
			COfficeXPMenu *psub = (COfficeXPMenu *)m_menu.GetSubMenu(0); 
			this->SetForegroundWindow();
			psub->TrackPopupMenu(TPM_RIGHTBUTTON,point.x,point.y,this);
			m_menu.DestroyMenu();	
		}
		break;  
	}
}

LRESULT CPageDlg::OnHotKey(WPARAM wp,LPARAM lp)
{
	if(wp==400 )
	{
		if(!IsWindowVisible())
		{	
			ShowWindow(SW_SHOWNORMAL);
		}
		else
		{
			ShowWindow(SW_HIDE);
		}
	}	 
	if(wp==401)
	{
		if(m_page1.pWnd ==NULL)
		{
			m_page1.OnStart();
		}
		else
		{
			m_page1.pWnd->SendMessage(WM_CLOSE,0,0);
			m_page1.pWnd=NULL;
			ShowWindow(m_page1.m_bMinimized? SW_SHOWMINIMIZED : SW_SHOWNORMAL);
		} 
	}
	if(wp==402)
	{
		m_page1.pWnd->OnRefresh();
	}


	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();
}







⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -