📄 xxxdlg.cpp
字号:
// xxxDlg.cpp : implementation file
//
#include "stdafx.h"
#include "xxx.h"
#include <graphics.h>
#include <INPUT.h>
#include <other.h>
#include <SETINI.h>
#include "xxxDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CXxxDlg dialog
CXxxDlg::CXxxDlg(CWnd* pParent /*=NULL*/)
: CDialog(CXxxDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CXxxDlg)
// 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 CXxxDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CXxxDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CXxxDlg, CDialog)
//{{AFX_MSG_MAP(CXxxDlg)
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_TIMER()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CXxxDlg message handlers
BOOL CXxxDlg::OnInitDialog()
{
CDialog::OnInitDialog();
// 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
int cx=::GetSystemMetrics(SM_CXSCREEN);
int cy=::GetSystemMetrics(SM_CYSCREEN);
this->MoveWindow(0,0,cx,cy);
CGDisplay *pDisplay=CreateDisplay(this->m_hWnd,cx,cy,32,FALSE);
if(pDisplay==NULL)
{
AfxMessageBox("不能初始化图形系统!");
return FALSE;
}
pDisplay->ClearScreen();
pDisplay->Update();
m_nScreenX=cx;
m_nScreenY=cy;
m_Game.Init();
CGSetIni ini;
if(ini.LoadIni("Config.ini"))
{
CGString filename=ini.ReadStr("Level","MapName");
int level=ini.ReadInt("Level","Level");
m_Game.SetLevel(level);
m_Game.LoadMap(filename);
}
else
m_Game.LoadMap("Level0.Dat");
ini.Clear();
this->SetTimer(0,150,NULL);
return TRUE; // return TRUE unless you set the focus to a control
}
// 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 CXxxDlg::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 CXxxDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CXxxDlg::OnOK()
{
}
void CXxxDlg::OnCancel()
{
if(AfxMessageBox("是否退出?",MB_YESNO|MB_ICONQUESTION)==6)
{
int level=m_Game.GetLevel();
CGString filename;
filename.Format("Level%d.dat",level);
CGSetIni ini;
ini.LoadIni("Config.ini");
ini.SetStrData("Level","MapName",filename);
ini.SetIntData("Level","Level",level);
ini.SaveIni("Config.ini");
ini.Clear();
CGDisplay *d=GetDisplay();
__RELEASES(d);
CDialog::OnCancel();
}
}
void CXxxDlg::OnTimer(UINT nIDEvent)
{
m_Game.GameLoop();
CDialog::OnTimer(nIDEvent);
}
BOOL CXxxDlg::PreTranslateMessage(MSG* pMsg)
{
if(pMsg->message==WM_KEYUP)
{
switch(pMsg->wParam)
{
case VK_LEFT:
m_Game.MoveMan(0,-1);
break;
case VK_RIGHT:
m_Game.MoveMan(0,1);
break;
case VK_UP:
m_Game.MoveMan(1,-1);
break;
case VK_DOWN:
m_Game.MoveMan(1,1);
break;
case 'Z':
m_Game.Undo();
break;
}
}
return CDialog::PreTranslateMessage(pMsg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -