📄 xpeasteregg.cpp
字号:
//////////////////////////////////////////////////////////////////////////////
//类名:CXPEasterEggApp
//功能:应用程序的初始化
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "XPEasterEgg.h"
#include "MainFrm.h"
#include "XPEasterEggDoc.h"
#include "XPEasterEggView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CXPEasterEggApp
BEGIN_MESSAGE_MAP(CXPEasterEggApp, CWinApp)
//{{AFX_MSG_MAP(CXPEasterEggApp)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
// NOTE - the ClassWizard will add and remove mapping macros here.
// DO NOT EDIT what you see in these blocks of generated code!
//}}AFX_MSG_MAP
// Standard file based document commands
ON_COMMAND(ID_FILE_NEW, CWinApp::OnFileNew)
ON_COMMAND(ID_FILE_OPEN, CWinApp::OnFileOpen)
// Standard print setup command
ON_COMMAND(ID_FILE_PRINT_SETUP, CWinApp::OnFilePrintSetup)
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXPEasterEggApp construction
CXPEasterEggApp::CXPEasterEggApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CXPEasterEggApp object
CXPEasterEggApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CXPEasterEggApp initialization
//////////////////////////////////////////////////////////////////////////////
//名称:InitInstance
//功能: 初始化实
/////////////////////////////////////////////////////////////////////////////
BOOL CXPEasterEggApp::InitInstance()
{
AfxEnableControlContainer();
// Standard initialization
// If you are not using these features and wish to reduce the size
// of your final executable, you should remove from the following
// the specific initialization routines you do not need.
#ifdef _AFXDLL
Enable3dControls(); // Call this when using MFC in a shared DLL
#else
Enable3dControlsStatic(); // Call this when linking to MFC statically
#endif
//此程序只能运行一次,用互斥量来判断程序是否已运行
HANDLE m_hMutex=CreateMutex(NULL,TRUE, m_pszAppName);
if(GetLastError()==ERROR_ALREADY_EXISTS) { return FALSE; }
//设置对话框背景和文本颜色
SetDialogBkColor(RGB(160,180,220),RGB(0,0,0));
// Change the registry key under which our settings are stored.
// TODO: You should modify this string to be something appropriate
// such as the name of your company or organization.
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(); // Load standard INI file options (including MRU)
// Register the application's document templates. Document templates
// serve as the connection between documents, frame windows and views.
CSingleDocTemplate* pDocTemplate;
pDocTemplate = new CSingleDocTemplate(
IDR_MAINFRAME,
RUNTIME_CLASS(CXPEasterEggDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CXPEasterEggView));
AddDocTemplate(pDocTemplate);
//设置XP风格菜单显示
CNewMenu::SetMenuDrawMode(CNewMenu::STYLE_XP);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The one and only window has been initialized, so show and update it.
m_pMainWnd->ShowWindow(SW_SHOW);
m_pMainWnd->UpdateWindow();
return TRUE;
}
//////////////////////////////////////////////////////////////////////////////
//类名:CAboutDlg
//功能:关于对话框类
/////////////////////////////////////////////////////////////////////////////
class CAboutDlg : public CNewDialog //更换成XP风格系统菜单
{
public:
CAboutDlg();
void SizeWindow(int ReduceHeight, bool bExtend); //伸展或收缩对话框
//"关于"对话框动态显示
int dx,dy; //偏移量
int nWidth,nHeight; //窗体宽、高
//"关于"对话框中的荣誉显示
int m_nReducedHeight; //收缩状态下的窗口高度
bool m_bVertical; //是否显示荣誉标志
// Dialog Data
//{{AFX_DATA(CAboutDlg)
enum { IDD = IDD_ABOUTBOX };
CPictureEx m_Flag; //GIF动态图像显示
CButtonXP m_OK; //XP风格按钮
CButtonXP m_More; //XP风格按钮
CAboutCtrl m_DyCredits; //荣誉显示效果
//}}AFX_DATA
// ClassWizard generated virtual function overrides
//{{AFX_VIRTUAL(CAboutDlg)
public:
virtual BOOL PreTranslateMessage(MSG* pMsg);
virtual BOOL DestroyWindow();
protected:
virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support
//}}AFX_VIRTUAL
// Implementation
protected:
//{{AFX_MSG(CAboutDlg)
virtual BOOL OnInitDialog();
afx_msg void OnTimer(UINT nIDEvent);
afx_msg void OnMore();
afx_msg void OnRButtonDblClk(UINT nFlags, CPoint point);
afx_msg LRESULT OnHotKey(WPARAM wParam, LPARAM lParam); //自定义系统热键
virtual void OnOK();
//}}AFX_MSG
DECLARE_MESSAGE_MAP()
};
CAboutDlg::CAboutDlg() : CNewDialog(CAboutDlg::IDD) //更换成XP风格系统菜单
{
//{{AFX_DATA_INIT(CAboutDlg)
//}}AFX_DATA_INIT
}
void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
CNewDialog::DoDataExchange(pDX); //更换成XP风格系统菜单
//{{AFX_DATA_MAP(CAboutDlg)
DDX_Control(pDX, IDC_FLAG, m_Flag);
DDX_Control(pDX, IDOK, m_OK);
DDX_Control(pDX, ID_MORE, m_More);
DDX_Control(pDX, IDC_DYCREDITS, m_DyCredits);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CAboutDlg, CNewDialog) //更换成XP风格系统菜单
//{{AFX_MSG_MAP(CAboutDlg)
ON_WM_TIMER()
ON_BN_CLICKED(ID_MORE, OnMore)
ON_WM_RBUTTONDBLCLK()
ON_MESSAGE(WM_HOTKEY,OnHotKey) //自定义系统热键消息涵数
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CXPEasterEggApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CXPEasterEggApp message handlers
//////////////////////////////////////////////////////////////////////////////
//名称:OnInitDialog
//功能:初始化"关于"对话框
/////////////////////////////////////////////////////////////////////////////
BOOL CAboutDlg::OnInitDialog() //
{
CNewDialog::OnInitDialog(); //更换成XP风格系统菜单
//"关于"对话框动态显示效果设置
CRect dlgRect;
GetWindowRect(dlgRect);
CRect desktopRect;
GetDesktopWindow()->GetWindowRect(desktopRect);
MoveWindow(
(desktopRect.Width() - dlgRect.Width()) / 2,
(desktopRect.Height() - dlgRect.Height()) / 2,
0,
0 );
nWidth=dlgRect.Width();
nHeight=dlgRect.Height();
dx=10; // X方向偏移量
dy=10; // Y方向偏移量
::SetTimer(this->m_hWnd, 1,10 , NULL); //启动开始时动态对话框效果
//"关于"对话框中对话框可收缩效果
CRect Rect1,Rect2; //对话框收缩时大小
GetDlgItem(IDC_DYCREDITS)->GetWindowRect(Rect1);
GetDlgItem(IDC_COPYRIGHT)->GetWindowRect(Rect2);
m_nReducedHeight = Rect1.Height()+(Rect1.top -Rect2.bottom)/2; //收缩后窗体高度
dlgRect.bottom -= (Rect1.Height()+(Rect1.top -Rect2.bottom)/2);
// MoveWindow(&dlgRect); //如果要显示对话框起始动态效果的话,不能使用该句
m_bVertical=false; //默认收缩对话框
//"关于"对话框中星空荣誉显示设置
CString strCredits = "\tXP风格复活节彩蛋实现\n\n"
"\r作者:\n"
"王超\n\n"
"\r指导老师:\n"
"宋亚奇\n\n"
"\rEmail: wangchao2960@163.com\n\n"
"\r第一次的作品我成功了\n"
"\n";
m_DyCredits.SetCredits(strCredits);
//显示动态GIF图像logo
if(m_Flag.Load(MAKEINTRESOURCE(IDR_FLAG),_T("GIF")))
{
m_Flag.SetBkColor(RGB(160,180,220));
m_Flag.Draw();
}
//注册系统热键,用来显示隐藏信息<Ctrl+Alt+F3键>
RegisterHotKey(GetSafeHwnd(),WM_SHOWHOTKEY,MOD_ALT|MOD_CONTROL,VK_F3);
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
//********************************************************************************
//* 名称:OnHotKey
//* 功能:<Ctrl+Alt+F3键>显示隐藏的信息
//********************************************************************************
LRESULT CAboutDlg::OnHotKey(WPARAM wParam,LPARAM lParam)
{
if(wParam==WM_SHOWHOTKEY)
{
OnMore();
}
return 0;
}
//********************************************************************************
//* 名称:DestroyWindow
//* 功能:程序关闭时的处理工作
//********************************************************************************
BOOL CAboutDlg::DestroyWindow()
{
//注销已注册的系统热键
UnregisterHotKey(GetSafeHwnd(),WM_SHOWHOTKEY);
return CNewDialog::DestroyWindow(); //更换成XP风格系统菜单
}
// ---------------------------------------------------------
// 名称: OnRButtonDblClk
// 功能: 在图片框按住Ctrl键,双击鼠标右键可显示,显示隐藏的信息。
// 变量: 无
// 返回: 无
// ---------------------------------------------------------
void CAboutDlg::OnRButtonDblClk(UINT nFlags, CPoint point)
{
if(nFlags==(MK_CONTROL|MK_RBUTTON ))
{
CPictureEx *pAbout =(CPictureEx *)GetDlgItem(IDC_FLAG);
CRect rcAbout;
pAbout->GetWindowRect(&rcAbout);
CPoint pt;
GetCursorPos(&pt);
if(rcAbout.PtInRect(pt))
OnMore();
}
CNewDialog::OnLButtonDblClk(nFlags, point); //更换成XP风格系统菜单
}
// ---------------------------------------------------------
// 名称: OnTimer
// 功能: 显示对话框动态效果
// 变量: nIDEvent -- 计时器ID
// 返回: 无
// ---------------------------------------------------------
void CAboutDlg::OnTimer(UINT nIDEvent)
{
CRect dlgRect;
GetWindowRect(dlgRect);
CRect desktopRect;
GetDesktopWindow()->GetWindowRect(desktopRect);
if((dlgRect.Width() >=nWidth)) //&& (dlgRect.Height() >=nHeight))
{
dlgRect.right = dlgRect.left + nWidth;
::KillTimer(this->m_hWnd, 1); //关闭定时器
}
if(nIDEvent == 1) //开始动态伸展
{
MoveWindow( //高度不变,因为要隐藏荣誉显示框
(-dx+desktopRect.Width() - dlgRect.Width()) / 2,
// (-dy+desktopRect.Height() - dlgRect.Height()) / 2,
nHeight-m_nReducedHeight,
+dx+dlgRect.Width(),
// +dy+dlgRect.Height() );
nHeight-m_nReducedHeight);
if(dlgRect.Width() >=nWidth)
dx=0; // X偏移量置0
// if(dlgRect.Height() >=nHeight)
// dy=0; // Y偏移量置0
}
CNewDialog::OnTimer(nIDEvent); //更换成XP风格系统菜单
}
// ---------------------------------------------------------
// 名称: OnMore
// 功能: 是否荣誉显示
// 变量: 无
// 返回: 无
// ---------------------------------------------------------
void CAboutDlg::OnMore()
{
m_bVertical = !m_bVertical;
if(m_bVertical == FALSE) //不显示
{
SetDlgItemText(ID_MORE,_T("更多>>"));
SizeWindow(m_nReducedHeight,true);
}
else //显示
{
SetDlgItemText(ID_MORE,_T("<<隐藏"));
SizeWindow(m_nReducedHeight,false);
}
UpdateWindow();
}
// ---------------------------------------------------------
// 名称: SizeWindow
// 功能: 伸展或收缩对话框
// 变量: ReduceHeight-收缩高度,bExtend-是否伸展
// 返回: 无
// ---------------------------------------------------------
void CAboutDlg::SizeWindow(int ReduceHeight, bool bExtend)
{
CRect rc;
GetWindowRect(&rc);
if(bExtend)
{
for (int i= 0; i < ReduceHeight; i++)
{
rc.bottom--;
MoveWindow(&rc);
}
}
else
{
for (int i= 0; i < ReduceHeight; i++)
{
rc.bottom++;
MoveWindow(&rc);
}
}
}
// ---------------------------------------------------------
// 名称: PreTranslateMessage
// 功能: 截获ESC和回车键,避免按下此键时关闭对话框
// 变量: pMsg -- 消息
// 返回: 成功返回TRUE,否则返回FALSE
// ---------------------------------------------------------
BOOL CAboutDlg::PreTranslateMessage(MSG* pMsg)
{
//截获ESC和回车键,避免按下此键时关闭对话框
if (pMsg->message == WM_KEYDOWN)
{
if(pMsg->wParam==VK_ESCAPE)
return true;
if(pMsg->wParam==VK_RETURN)
return true;
}
return CNewDialog::PreTranslateMessage(pMsg); //更换成XP风格系统菜单
}
void CAboutDlg::OnOK()
{
// TODO: Add extra validation here
CNewDialog::OnOK();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -