📄 fiveplusdlg.cpp
字号:
// FivePlusDlg.cpp : implementation file
//
#include "stdafx.h"
#include "FivePlus.h"
#include "FivePlusDlg.h"
#include "HighScoreDlg.h"
#include "DlgProxy.h"
#include "SettingDlg.h"
#include <winuser.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 void OnLButtonDown(UINT nFlags, CPoint point);
afx_msg BOOL OnSetCursor(CWnd* pWnd, UINT nHitTest, UINT message);
//}}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)
ON_WM_LBUTTONDOWN()
ON_WM_SETCURSOR()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFivePlusDlg dialog
IMPLEMENT_DYNAMIC(CFivePlusDlg, CDialog);
CFivePlusDlg::CFivePlusDlg(CWnd* pParent /*=NULL*/)
: CDialog(CFivePlusDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CFivePlusDlg)
// 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);
m_pAutoProxy = NULL;
}
CFivePlusDlg::~CFivePlusDlg()
{
// If there is an automation proxy for this dialog, set
// its back pointer to this dialog to NULL, so it knows
// the dialog has been deleted.
if (m_pAutoProxy != NULL)
m_pAutoProxy->m_pDialog = NULL;
if ( m_dcBK.m_hDC )
m_dcBK.DeleteDC();
if ( m_bmpBK.m_hObject )
m_bmpBK.DeleteObject();
if ( m_dcGrid.m_hDC )
m_dcGrid.DeleteDC();
if ( m_bmpGrid.m_hObject ){
m_bmpGrid.DeleteObject();
}
if ( m_dcNumber.m_hDC )
m_dcNumber.DeleteDC();
if ( m_bmpNumber.m_hObject ){
m_bmpNumber.DeleteObject();
}
if ( m_dcOneGrid.m_hDC )
m_dcOneGrid.DeleteDC();
if ( m_bmpOneGrid.m_hObject ){
m_bmpOneGrid.DeleteObject();
}
}
void CFivePlusDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CFivePlusDlg)
// NOTE: the ClassWizard will add DDX and DDV calls here
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CFivePlusDlg, CDialog)
//{{AFX_MSG_MAP(CFivePlusDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_WM_CLOSE()
ON_COMMAND(ID_GAME_NEW, OnGameNew)
ON_WM_LBUTTONDOWN()
ON_WM_TIMER()
ON_WM_DESTROY()
ON_COMMAND(ID_HELP_ABOUT, OnAboutbox)
ON_WM_CREATE()
ON_COMMAND(ID_GAME_SCORE, OnGameScore)
ON_COMMAND(ID_HELP_HOW_TO_PLAY, OnHelpHowToPlay)
ON_WM_HELPINFO()
ON_COMMAND(ID_TOOL_SETTING, OnToolSetting)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFivePlusDlg message handlers
BOOL CFivePlusDlg::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
// TODO: Add extra initialization here
CClientDC dc(this);
m_dcBK.CreateCompatibleDC(&dc);
CFivePlusApp* theApp = (CFivePlusApp*)::AfxGetApp();
HBITMAP hbmp = (HBITMAP)::LoadImage(::AfxGetInstanceHandle(),
theApp->m_szWorkPath + "\\res\\BK.bmp", IMAGE_BITMAP, 0, 0,
LR_DEFAULTCOLOR|LR_LOADFROMFILE);
m_bmpBK.Attach(hbmp);
//m_bmpBK.LoadBitmap(IDB_BITMAP_BACKGROUND);
m_dcBK.SelectObject(&m_bmpBK);
m_dcGrid.CreateCompatibleDC(&dc);
hbmp = (HBITMAP)::LoadImage(::AfxGetInstanceHandle(),
theApp->m_szWorkPath + "\\res\\ALL_GRID.bmp", IMAGE_BITMAP, 0, 0,
LR_DEFAULTCOLOR|LR_LOADFROMFILE);
m_bmpGrid.Attach(hbmp);
//m_bmpGrid.LoadBitmap(IDB_BITMAP_ALL_GRID);
m_dcGrid.SelectObject(&m_bmpGrid);
m_dcNumber.CreateCompatibleDC(&dc);
hbmp = (HBITMAP)::LoadImage(::AfxGetInstanceHandle(),
theApp->m_szWorkPath + "\\res\\NUMBER.bmp", IMAGE_BITMAP, 0, 0,
LR_DEFAULTCOLOR|LR_LOADFROMFILE);
m_bmpNumber.Attach(hbmp);
//m_bmpNumber.LoadBitmap(IDB_BITMAP_NUMBER);
m_dcNumber.SelectObject(&m_bmpNumber);
m_dcOneGrid.CreateCompatibleDC(&dc);
m_bmpOneGrid.CreateCompatibleBitmap(&dc, GRID_WIDTH, GRID_HEIGHT);
m_dcOneGrid.SelectObject(&m_bmpOneGrid);
m_rectPlayArea.SetRect(0,
PLAY_AREA_TOP,
GRID_NUM_HOR * (GRID_WIDTH + 2),
PLAY_AREA_TOP + GRID_NUM_VER * (GRID_HEIGHT + 2));
m_rectNextBalls.SetRect(NEXT_GRID_LEFT,
NEXT_GRID_TOP,
NEXT_GRID_LEFT + (GRID_WIDTH + 2)*3 - 2,
NEXT_GRID_TOP + GRID_HEIGHT);
m_rectScore.SetRect(4, 2, 4 + 4*30, 2 + 42);
m_bfSelect.BlendOp = AC_SRC_OVER;
m_bfSelect.BlendFlags = 0;
m_bfSelect.SourceConstantAlpha = 0;
m_bfSelect.AlphaFormat = 0;
m_bfDisappear.BlendOp = AC_SRC_OVER;
m_bfDisappear.BlendFlags = 0;
m_bfDisappear.SourceConstantAlpha = 0;
m_bfDisappear.AlphaFormat = 0;
m_nTimerSelected = SetTimer(FLASH_SELECT, m_gameModel.m_nSelectInterval, 0);
m_posCurMove = NULL;
m_bIsMoving = FALSE;
m_bIsDisappearing = FALSE;
//OnGameNew();
return TRUE; // return TRUE unless you set the focus to a control
}
void CFivePlusDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
if ((nID & 0xFFF0) == IDM_ABOUTBOX)
{
CAboutDlg dlgAbout;
dlgAbout.DoModal();
}
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 CFivePlusDlg::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
{
CPaintDC dc(this);
dc.BitBlt(0, 0, 360, 410, &m_dcBK,
0, 0, SRCCOPY);
this->DrawScore(&dc);
DrawNextBalls(&dc);
this->DrawGrid(&dc);
CDialog::OnPaint();
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CFivePlusDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
// Automation servers should not exit when a user closes the UI
// if a controller still holds on to one of its objects. These
// message handlers make sure that if the proxy is still in use,
// then the UI is hidden but the dialog remains around if it
// is dismissed.
void CFivePlusDlg::OnClose()
{
if (CanExit())
CDialog::OnClose();
}
void CFivePlusDlg::OnOK()
{
if (CanExit())
CDialog::OnOK();
}
void CFivePlusDlg::OnCancel()
{
if (CanExit())
CDialog::OnCancel();
}
BOOL CFivePlusDlg::CanExit()
{
// If the proxy object is still around, then the automation
// controller is still holding on to this application. Leave
// the dialog around, but hide its UI.
if (m_pAutoProxy != NULL)
{
ShowWindow(SW_HIDE);
return FALSE;
}
if ( m_bIsDisappearing || m_bIsMoving )
return FALSE;
return TRUE;
}
void CFivePlusDlg::OnGameNew()
{
// TODO: Add your command handler code here
m_gameModel.NewGame();
InvalidateRect(&m_rectPlayArea);
InvalidateRect(&m_rectNextBalls);
InvalidateRect(&m_rectScore);
}
BOOL CFivePlusDlg::DrawGrid(CDC* dc)
{
for ( int i = 0; i < GRID_NUM_HOR; i++ ){
for ( int j = 0; j < GRID_NUM_VER; j++ ){
if ( m_gameModel.m_grid[i][j] != NOTHING ){
if ( m_gameModel.m_bHasSel && ( m_gameModel.m_ptSel.x == i )
&& ( m_gameModel.m_ptSel.y == j ) ){
}else{
dc->BitBlt(1 + i*(GRID_WIDTH+2),
PLAY_AREA_TOP + 1 + j*(GRID_HEIGHT+2),
GRID_WIDTH,
GRID_HEIGHT,
&m_dcGrid,
(m_gameModel.m_grid[i][j] - 1)*GRID_WIDTH,
0,
SRCCOPY);
}
}
}
}
return TRUE;
}
BOOL CFivePlusDlg::DrawNextBalls(CDC *dc)
{
for ( int i = 0; i < 3; i++ ){
if ( m_gameModel.m_currentGrid[i] != NOTHING ){
//m_dcGrid.SelectObject(&m_bmpGrid[m_gameModel.m_currentGrid[i]]);
dc->BitBlt(NEXT_GRID_LEFT + i*(GRID_WIDTH+2),
NEXT_GRID_TOP,
GRID_WIDTH,
GRID_HEIGHT,
&m_dcGrid,
(m_gameModel.m_currentGrid[i] - 1)*GRID_WIDTH,
0,
SRCCOPY);
}
}
return TRUE;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -