📄 viewmode.cpp
字号:
//////////////////////////////////////////////////////////////////////////////
//类名:CViewModeApp
//功能:应用程序的初始化
//作者:徐景周(jingzhou_xu@163.net)
//组织:未来工作室(Future Studio)
//日期:2002.8.1
/////////////////////////////////////////////////////////////////////////////
#include "stdafx.h"
#include "ViewMode.h"
#include "MainFrm.h"
#include "ViewModeDoc.h"
#include "ViewModeView.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CViewModeApp
BEGIN_MESSAGE_MAP(CViewModeApp, CWinApp)
//{{AFX_MSG_MAP(CViewModeApp)
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()
/////////////////////////////////////////////////////////////////////////////
// CViewModeApp construction
CViewModeApp::CViewModeApp()
{
// TODO: add construction code here,
// Place all significant initialization in InitInstance
}
/////////////////////////////////////////////////////////////////////////////
// The one and only CViewModeApp object
CViewModeApp theApp;
/////////////////////////////////////////////////////////////////////////////
// CViewModeApp initialization
//////////////////////////////////////////////////////////////////////////////
//涵数名:InitInstance
//功能: 初始化实例
//作者: 徐景周(jingzhou_xu@163.net)
//组织: 未来工作室(Future Studio)
//日期: 2002.8.1
/////////////////////////////////////////////////////////////////////////////
BOOL CViewModeApp::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(CViewModeDoc),
RUNTIME_CLASS(CMainFrame), // main SDI frame window
RUNTIME_CLASS(CViewModeView));
AddDocTemplate(pDocTemplate);
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
//添加下面一行代码,是在初始化时不建立空视图
// cmdInfo.m_nShellCommand=CCommandLineInfo::FileNothing;
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
//功能:关于对话框类
//作者:徐景周(jingzhou_xu@163.net)
//组织:未来工作室(Future Studio)
//日期:2002.8.1
/////////////////////////////////////////////////////////////////////////////
class CAboutDlg : public CDialog
{
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动态图像显示
CWBButton m_OK; //位图按钮
CWBButton m_More; //位图按钮
CStarWarsCtrl m_DyCredits; //荣誉显示效果
//}}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)
virtual BOOL OnInitDialog();
afx_msg void OnMore();
afx_msg void OnTimer(UINT nIDEvent);
//}}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)
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, CDialog)
//{{AFX_MSG_MAP(CAboutDlg)
ON_BN_CLICKED(ID_MORE, OnMore)
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
// App command to run the dialog
void CViewModeApp::OnAppAbout()
{
CAboutDlg aboutDlg;
aboutDlg.DoModal();
}
/////////////////////////////////////////////////////////////////////////////
// CViewModeApp message handlers
//////////////////////////////////////////////////////////////////////////////
//涵数名:OnInitDialog
//功能:初始化"关于"对话框
//作者:徐景周(jingzhou_xu@163.net)
//组织:未来工作室(Future Studio)
/////////////////////////////////////////////////////////////////////////////
BOOL CAboutDlg::OnInitDialog()
{
CDialog::OnInitDialog();
//"关于"对话框动态显示效果设置
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=15; // X方向偏移量
dy=15; // 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; //默认收缩对话框
//"关于"对话框中星空荣誉显示设置
m_DyCredits.SetStarSpeed(30);
m_DyCredits.SetScrollSpeed(2);
m_DyCredits.AddTextLine("界面多模式显示示例 1.0版"); //滚动速度(0-慢速,1-中速,2-快速)
m_DyCredits.AddTextLine("");
m_DyCredits.AddTextLine("作者:徐景周");
m_DyCredits.AddTextLine("");
m_DyCredits.AddTextLine("Email: jingzhou_xu@163.net");
m_DyCredits.AddTextLine("");
m_DyCredits.AddTextLine("未来工作室(Future Studio)出品");
m_DyCredits.AddTextLine("");
m_DyCredits.AddTextLine("");
//设置“关于”对话框的位图按钮显示
m_OK.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
m_More.LoadBitmaps(IDB_BUTTON,5, 5, 5, 5, 4 );
//显示动态GIF图像logo
if(m_Flag.Load(MAKEINTRESOURCE(IDR_FLAG),_T("GIF")))
{
m_Flag.SetBkColor(RGB(160,180,220));
m_Flag.Draw();
}
return TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
// ---------------------------------------------------------
// 名称: OnTimer
// 功能: 显示对话框动态效果
// 变量: nIDEvent -- 计时器ID
// 返回: 无
// ---------------------------------------------------------
void CAboutDlg::OnTimer(UINT nIDEvent)
{
CRect dlgRect;
GetWindowRect(dlgRect);
CRect desktopRect;
GetDesktopWindow()->GetWindowRect(desktopRect);
if((dlgRect.Width() >=nWidth)) //&& (dlgRect.Height() >=nHeight))
::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
}
CDialog::OnTimer(nIDEvent);
}
// ---------------------------------------------------------
// 名称: 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);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -