📄 mainfrm.cpp
字号:
// MainFrm.cpp : implementation of the CMainFrame class
//
#include "stdafx.h"
#include "扫雷.h"
#include "MainFrm.h"
#include "defdialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CMainFrame
IMPLEMENT_DYNCREATE(CMainFrame, CFrameWnd)
BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
//{{AFX_MSG_MAP(CMainFrame)
ON_WM_CREATE()
ON_COMMAND(IDM_EASY, OnEasy)
ON_COMMAND(IDM_NORMAL, OnNormal)
ON_COMMAND(IDM_HARD, OnHard)
ON_COMMAND(IDM_DEFINE, OnDefine)
ON_COMMAND(IDM_BACKWAVE, OnBackwave)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMainFrame construction/destruction
CMainFrame::CMainFrame()
{
// TODO: add member initialization code here
CMainFrame::m_bAutoMenuEnable=FALSE;
}
CMainFrame::~CMainFrame()
{
}
BOOL CMainFrame::PreCreateWindow(CREATESTRUCT& cs)
{
CMyApp *App=(CMyApp *)AfxGetApp();
cs.x=App->Afx_Game.WindowRange.left;
cs.y=App->Afx_Game.WindowRange.top;
cs.cx=App->Afx_Game.WindowRange.right;
cs.cy=App->Afx_Game.WindowRange.bottom;
cs.style = WS_OVERLAPPED | WS_CAPTION | FWS_ADDTOTITLE
| WS_SYSMENU | WS_MINIMIZEBOX;
if( !CFrameWnd::PreCreateWindow(cs) )
return FALSE;
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return TRUE;
}
/////////////////////////////////////////////////////////////////////////////
// CMainFrame diagnostics
#ifdef _DEBUG
void CMainFrame::AssertValid() const
{
CFrameWnd::AssertValid();
}
void CMainFrame::Dump(CDumpContext& dc) const
{
CFrameWnd::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CMainFrame message handlers
int CMainFrame::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
// TODO: Add your specialized creation code here
TitleBar.Create(this,IDD_DIALOGBAR,CBRS_TOP,AFX_IDW_DIALOGBAR);
CMyApp *App=(CMyApp *)AfxGetApp();
App->Afx_Game.TitleBomb.Create("",WS_CHILD|WS_VISIBLE,CRect(20,10,60,30),this,IDC_TITLEBOMB);
int i,j;
RECT rect;
CMainFrame::GetWindowRect(&rect);
i=rect.right-rect.left;j=rect.bottom-rect.top;
App->Afx_Game.GameTime.Create("",WS_CHILD|WS_VISIBLE,CRect(i-60,10,i-20,30),this,IDC_GAMETIME);
App->Afx_Game.GameEnd.Create("",WS_CHILD|WS_VISIBLE,CRect(i/2-20,10,i/2+20,30),this,IDC_GAMEEND);
if (CFrameWnd::OnCreate(lpCreateStruct) == -1)
return -1;
return 0;
}
void CMainFrame::OnEasy()
{
// TODO: Add your command handler code here
CMyApp *App=(CMyApp *)AfxGetApp();
App->Afx_Game.Width=12;
App->Afx_Game.Heigh=12;
App->Afx_Game.BombNum=18;
CMenu *menu;
menu=AfxGetMainWnd()->GetMenu();
menu->CheckMenuItem(IDM_EASY,MF_BYCOMMAND|MF_CHECKED);
menu->CheckMenuItem(IDM_NORMAL,MF_BYCOMMAND|MF_UNCHECKED);
menu->CheckMenuItem(IDM_HARD,MF_BYCOMMAND|MF_UNCHECKED);
menu->CheckMenuItem(IDM_DEFINE,MF_BYCOMMAND|MF_UNCHECKED);
//重画窗口
int i,j;
i=App->Afx_Game.Width*15+11;j=App->Afx_Game.Heigh*15+85;
App->Afx_Game.WindowRange=CRect(400-i/2,300-j/2,i,j);
RECT rect;
CMainFrame::GetWindowRect(&rect);
i=rect.right-rect.left;j=rect.bottom-rect.top;
CMainFrame::MoveWindow(App->Afx_Game.WindowRange.left,App->Afx_Game.WindowRange.top,App->Afx_Game.WindowRange.right,App->Afx_Game.WindowRange.bottom,TRUE);
App->Afx_Game.GameTime.MoveWindow(130,10,40,20);
App->Afx_Game.GameEnd.MoveWindow(75,10,40,20);
CMainFrame::SendMessage(WM_COMMAND,IDM_ENDGAME,0);
}
void CMainFrame::OnNormal()
{
// TODO: Add your command handler code here
CMyApp *App=(CMyApp *)AfxGetApp();
App->Afx_Game.Width=18;
App->Afx_Game.Heigh=18;
App->Afx_Game.BombNum=36;
CMenu *menu;
menu=AfxGetMainWnd()->GetMenu();
menu->CheckMenuItem(IDM_EASY,MF_BYCOMMAND|MF_UNCHECKED);
menu->CheckMenuItem(IDM_NORMAL,MF_BYCOMMAND|MF_CHECKED);
menu->CheckMenuItem(IDM_HARD,MF_BYCOMMAND|MF_UNCHECKED);
menu->CheckMenuItem(IDM_DEFINE,MF_BYCOMMAND|MF_UNCHECKED);
//重画窗口
int i,j;
i=App->Afx_Game.Width*15+11;j=App->Afx_Game.Heigh*15+85;
App->Afx_Game.WindowRange=CRect(400-i/2,300-j/2,i,j);
CMainFrame::MoveWindow(App->Afx_Game.WindowRange.left,App->Afx_Game.WindowRange.top,App->Afx_Game.WindowRange.right,App->Afx_Game.WindowRange.bottom,TRUE);
RECT rect;
CMainFrame::GetWindowRect(&rect);
i=rect.right-rect.left;j=rect.bottom-rect.top;
CMainFrame::MoveWindow(App->Afx_Game.WindowRange.left,App->Afx_Game.WindowRange.top,App->Afx_Game.WindowRange.right,App->Afx_Game.WindowRange.bottom,TRUE);
App->Afx_Game.GameTime.MoveWindow(i-60,10,40,20);
App->Afx_Game.GameEnd.MoveWindow(i/2-20,10,40,20);
CMainFrame::SendMessage(WM_COMMAND,IDM_ENDGAME,0);
}
void CMainFrame::OnHard()
{
// TODO: Add your command handler code here
CMyApp *App=(CMyApp *)AfxGetApp();
App->Afx_Game.Width=24;
App->Afx_Game.Heigh=24;
App->Afx_Game.BombNum=48;
CMenu *menu;
menu=AfxGetMainWnd()->GetMenu();
menu->CheckMenuItem(IDM_EASY,MF_BYCOMMAND|MF_UNCHECKED);
menu->CheckMenuItem(IDM_NORMAL,MF_BYCOMMAND|MF_UNCHECKED);
menu->CheckMenuItem(IDM_HARD,MF_BYCOMMAND|MF_CHECKED);
menu->CheckMenuItem(IDM_DEFINE,MF_BYCOMMAND|MF_UNCHECKED);
//重画窗口
int i,j;
i=App->Afx_Game.Width*15+11;j=App->Afx_Game.Heigh*15+85;
App->Afx_Game.WindowRange=CRect(400-i/2,300-j/2,i,j);
CMainFrame::MoveWindow(App->Afx_Game.WindowRange.left,App->Afx_Game.WindowRange.top,App->Afx_Game.WindowRange.right,App->Afx_Game.WindowRange.bottom,TRUE);
RECT rect;
CMainFrame::GetWindowRect(&rect);
i=rect.right-rect.left;j=rect.bottom-rect.top;
CMainFrame::MoveWindow(App->Afx_Game.WindowRange.left,App->Afx_Game.WindowRange.top,App->Afx_Game.WindowRange.right,App->Afx_Game.WindowRange.bottom,TRUE);
App->Afx_Game.GameTime.MoveWindow(i-60,10,40,20);
App->Afx_Game.GameEnd.MoveWindow(i/2-20,10,40,20);
CMainFrame::SendMessage(WM_COMMAND,IDM_ENDGAME,0);
}
void CMainFrame::OnDefine()
{
// TODO: Add your command handler code here
CMenu *menu;
menu=AfxGetMainWnd()->GetMenu();
menu->CheckMenuItem(IDM_EASY,MF_BYCOMMAND|MF_UNCHECKED);
menu->CheckMenuItem(IDM_NORMAL,MF_BYCOMMAND|MF_UNCHECKED);
menu->CheckMenuItem(IDM_HARD,MF_BYCOMMAND|MF_UNCHECKED);
menu->CheckMenuItem(IDM_DEFINE,MF_BYCOMMAND|MF_CHECKED);
DEFDIALOG Def;
Def.SubclassDlgItem(IDD_DIALOG,this);
Def.DoModal();
//重画窗口
CMyApp *App=(CMyApp *)AfxGetApp();
int i,j;
i=App->Afx_Game.Width*15+11;j=App->Afx_Game.Heigh*15+85;
App->Afx_Game.WindowRange=CRect(400-i/2,300-j/2,i,j);
CMainFrame::MoveWindow(App->Afx_Game.WindowRange.left,App->Afx_Game.WindowRange.top,App->Afx_Game.WindowRange.right,App->Afx_Game.WindowRange.bottom,TRUE);
RECT rect;
CMainFrame::GetWindowRect(&rect);
i=rect.right-rect.left;j=rect.bottom-rect.top;
CMainFrame::MoveWindow(App->Afx_Game.WindowRange.left,App->Afx_Game.WindowRange.top,App->Afx_Game.WindowRange.right,App->Afx_Game.WindowRange.bottom,TRUE);
App->Afx_Game.GameTime.MoveWindow(i-60,10,40,20);
App->Afx_Game.GameEnd.MoveWindow(i/2-20,10,40,20);
CMainFrame::SendMessage(WM_COMMAND,IDM_ENDGAME,0);
}
void CMainFrame::OnBackwave()
{
// TODO: Add your command handler code here
CMyApp *App=(CMyApp *)AfxGetApp();
CMenu *menu;
menu=AfxGetMainWnd()->GetMenu();
if (App->Afx_Game.BackWave)
menu->CheckMenuItem(IDM_BACKWAVE,MF_BYCOMMAND|MF_UNCHECKED);
else
menu->CheckMenuItem(IDM_BACKWAVE,MF_BYCOMMAND|MF_CHECKED);
App->Afx_Game.BackWave=1-App->Afx_Game.BackWave;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -