?? shududlg.cpp
字號:
// ShuDuDlg.cpp : implementation file
//
#include "stdafx.h"
#include "ShuDu.h"
#include "ShuDuDlg.h"
#include "CreateData.h"
#include <stdlib.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
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)
// No message handlers
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShuDuDlg dialog
CShuDuDlg::CShuDuDlg(CWnd* pParent /*=NULL*/)
: CDialog(CShuDuDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CShuDuDlg)
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CShuDuDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CShuDuDlg)
DDX_Control(pDX, IDC_GAMENOTE, m_Note);
DDX_Control(pDX, IDC_SHOWSELNUM, m_ShowSelNumBtn);
DDX_Control(pDX, IDC_LEVELNORMAL, m_LevelNormalBtn);
DDX_Control(pDX, IDC_LEVELHARD, m_LevelHardBtn);
DDX_Control(pDX, IDC_STARTNEWGAME, m_StartBtn);
DDX_Control(pDX, IDC_SAVEGAME, m_SaveBtn);
DDX_Control(pDX, IDC_RESTART, m_RestartBtn);
DDX_Control(pDX, IDC_MAINMENU, m_MainRect);
DDX_Control(pDX, IDC_OPTION, m_OptionRect);
DDX_Control(pDX, IDC_LEVELEASY, m_LevelEasyBtn);
DDX_Control(pDX, IDC_EXIT, m_ExitBtn);
DDX_Control(pDX, IDC_DISPLAYTRACK, m_ShowTrackBtn);
DDX_Control(pDX, IDC_DISPLAYNUM, m_ShowNumBtn);
DDX_Control(pDX, IDC_LEVELGROUP, m_LevelRect);
DDX_Control(pDX, IDC_UNDO, m_UndoBtn);
DDX_Control(pDX, IDC_SHUDU, m_sdCtrl);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CShuDuDlg, CDialog)
//{{AFX_MSG_MAP(CShuDuDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_STARTNEWGAME, OnStartnewgame)
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
ON_BN_CLICKED(IDC_UNDO, OnUndo)
ON_BN_CLICKED(IDC_SAVEGAME, OnSavegame)
ON_BN_CLICKED(IDC_RESTART, OnRestart)
ON_BN_CLICKED(IDC_LEVELNORMAL, OnLevelnormal)
ON_BN_CLICKED(IDC_LEVELHARD, OnLevelhard)
ON_BN_CLICKED(IDC_LEVELEASY, OnLeveleasy)
ON_BN_CLICKED(IDC_EXIT, OnExit)
ON_BN_CLICKED(IDC_DISPLAYTRACK, OnDisplaytrack)
ON_BN_CLICKED(IDC_DISPLAYNUM, OnDisplaynum)
ON_BN_CLICKED(IDC_SHOWSELNUM, OnShowselnum)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CShuDuDlg message handlers
BOOL CShuDuDlg::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
MoveWindow(0,0,700,600,FALSE);
CenterWindow();
m_sdCtrl.MoveWindow(20,20,505,445,FALSE);
m_UndoBtn.MoveWindow(530,60,80,30,FALSE);
m_MainRect.MoveWindow(530,15,150,170);
m_StartBtn.MoveWindow(540,30,130,25);
m_RestartBtn.MoveWindow(540,60,130,25);
m_UndoBtn.MoveWindow(540,90,130,25);
m_SaveBtn.MoveWindow(540,120,130,25);
m_ExitBtn.MoveWindow(540,150,130,25);
m_OptionRect.MoveWindow(530,215,150,110);
m_ShowNumBtn.MoveWindow(540,230,130,25);
m_ShowTrackBtn.MoveWindow(540,260,130,25);
m_ShowSelNumBtn.MoveWindow(540,290,130,25);
m_ShowNumBtn.SetCheck(0);
m_ShowTrackBtn.SetCheck(1);
m_ShowSelNumBtn.SetCheck(1);
m_LevelRect.MoveWindow(530,355,150,110);
m_LevelEasyBtn.MoveWindow(540,370,130,25);
m_LevelNormalBtn.MoveWindow(540,400,130,25);
m_LevelHardBtn.MoveWindow(540,430,130,25);
m_LevelNormalBtn.SetCheck(1);
m_Note.MoveWindow(20,475,660,95);
CString str;
str.LoadString(IDS_ABOUTGAME);
m_Note.SetWindowText(str);
return TRUE; // return TRUE unless you set the focus to a control
}
void CShuDuDlg::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 CShuDuDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
if (IsIconic())
{
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 CShuDuDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CShuDuDlg::OnStartnewgame()
{
// TODO: Add your control notification handler code here
CreateShuDuMetrix(m_GameData);
m_sdCtrl.StartGame(m_GameData);
}
void CShuDuDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
CDialog::OnLButtonDown(nFlags, point);
}
void CShuDuDlg::OnLButtonUp(UINT nFlags, CPoint point)
{
CDialog::OnLButtonUp(nFlags, point);
}
void CShuDuDlg::OnMouseMove(UINT nFlags, CPoint point)
{
CDialog::OnMouseMove(nFlags, point);
}
void CShuDuDlg::OnUndo()
{
// TODO: Add your control notification handler code here
m_sdCtrl.UnDo();
}
void CShuDuDlg::OnSavegame()
{
CFileDialog fd(TRUE,"txt",NULL,OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT|OFN_NOCHANGEDIR,
"Text File(*.txt)|*.txt||",this);
if(fd.DoModal() == IDOK)
{
CString strFile = fd.GetPathName();
FILE *fp = fopen(strFile,"wt");
if(fp != NULL)
{
for (int i=0; i<9;i++)
{
for(int j=0;j<9;j++)
{
fprintf(fp,"%d ",m_GameData[i][j]);
}
fprintf(fp,"\n");
}
fclose(fp);
}
}
}
void CShuDuDlg::OnRestart()
{
m_sdCtrl.StartGame(m_GameData);
}
void CShuDuDlg::OnLevelnormal()
{
m_LevelEasyBtn.SetCheck(0);
m_LevelHardBtn.SetCheck(0);
m_LevelNormalBtn.SetCheck(1);
if( CurrentLevel == 1)return;
else
{
CurrentLevel = 1;
m_sdCtrl.SetGameLevel(1);
}
}
void CShuDuDlg::OnLevelhard()
{
m_LevelNormalBtn.SetCheck(0);
m_LevelEasyBtn.SetCheck(0);
if( CurrentLevel == 2)return;
else
{
CurrentLevel = 2;
m_sdCtrl.SetGameLevel(2);
}
}
void CShuDuDlg::OnLeveleasy()
{
m_LevelNormalBtn.SetCheck(0);
m_LevelHardBtn.SetCheck(0);
if( CurrentLevel == 0)return;
else
{
CurrentLevel = 0;
m_sdCtrl.SetGameLevel(0);
}
}
void CShuDuDlg::OnExit()
{
EndDialog(0);
}
void CShuDuDlg::OnDisplaytrack()
{
m_sdCtrl.EnableAreas(m_ShowTrackBtn.GetCheck());
}
void CShuDuDlg::OnDisplaynum()
{
m_sdCtrl.EnableNumbers(m_ShowNumBtn.GetCheck());
}
void CShuDuDlg::OnShowselnum()
{
m_sdCtrl.EnableSelectNum(m_ShowSelNumBtn.GetCheck());
}
BOOL CShuDuDlg::PreTranslateMessage(MSG* pMsg)
{
// TODO: Add your specialized code here and/or call the base class
if(pMsg->message == WM_GAMECOMPLETED)
{
MessageBox("恭喜過關");
}
return CDialog::PreTranslateMessage(pMsg);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -