📄 snakemapdlg.cpp
字号:
// snakemapDlg.cpp : implementation file
//
#include "stdafx.h"
#include "snakemap.h"
#include "snakemapDlg.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()
/////////////////////////////////////////////////////////////////////////////
// CSnakemapDlg dialog
CSnakemapDlg::CSnakemapDlg(CWnd* pParent /*=NULL*/)
: CDialog(CSnakemapDlg::IDD, pParent)
{
//{{AFX_DATA_INIT(CSnakemapDlg)
m_item1 = -1;
m_dir = -1;
m_snake1x = 0;
m_snake1y = 0;
m_snake2x = 0;
m_snake2y = 0;
m_snake3x = 0;
m_snake3y = 0;
m_snakecolor1 = 0;
m_snakecolor2 = 0;
m_earth = -1;
m_curName = _T("");
m_speed = -1;
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CSnakemapDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CSnakemapDlg)
DDX_Control(pDX, IDC_LIST1, m_lvlist);
DDX_Radio(pDX, IDC_RADIO1, m_item1);
DDX_Radio(pDX, IDC_RADIO8, m_dir);
DDX_Text(pDX, IDC_EDIT2, m_snake1x);
DDX_Text(pDX, IDC_EDIT3, m_snake1y);
DDX_Text(pDX, IDC_EDIT4, m_snake2x);
DDX_Text(pDX, IDC_EDIT5, m_snake2y);
DDX_Text(pDX, IDC_EDIT6, m_snake3x);
DDX_Text(pDX, IDC_EDIT7, m_snake3y);
DDX_Text(pDX, IDC_EDIT1, m_snakecolor1);
DDX_Text(pDX, IDC_EDIT8, m_snakecolor2);
DDX_Radio(pDX, IDC_RADIO12, m_earth);
DDX_Text(pDX, IDC_EDIT9, m_curName);
DDX_Radio(pDX, IDC_RADIO15, m_speed);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CSnakemapDlg, CDialog)
//{{AFX_MSG_MAP(CSnakemapDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_BN_CLICKED(IDC_RADIO3, OnRadio3)
ON_WM_RBUTTONDOWN()
ON_WM_LBUTTONDOWN()
ON_WM_MOUSEMOVE()
ON_EN_CHANGE(IDC_EDIT2, OnChangeEdit2)
ON_EN_CHANGE(IDC_EDIT3, OnChangeEdit3)
ON_EN_CHANGE(IDC_EDIT4, OnChangeEdit4)
ON_EN_CHANGE(IDC_EDIT5, OnChangeEdit5)
ON_EN_CHANGE(IDC_EDIT6, OnChangeEdit6)
ON_EN_CHANGE(IDC_EDIT7, OnChangeEdit7)
ON_COMMAND(ID_APP_ABOUT, OnAppAbout)
ON_COMMAND(ID_MENUITEM32776, OnMenuitem32776)
ON_COMMAND(ID_MENUITEM32775, OnMenuitem32775)
ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
ON_COMMAND(ID_MENUITEM32777, OnMenuitem32777)
ON_LBN_SELCHANGE(IDC_LIST1, OnSelchangeList1)
ON_COMMAND(ID_MENUITEM32772, OnMenuitem32772)
ON_EN_CHANGE(IDC_EDIT9, OnChangeEdit9)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CSnakemapDlg message handlers
BOOL CSnakemapDlg::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
m_dir=3;
m_earth=0;
m_item1=0;
m_snake1x=7;
m_snake2x=6;
m_snake3x=5;
m_snake1y=m_snake2y=m_snake3y=10;
m_snakecolor1=2;
m_snakecolor2=2;
curX=0;
curY=0;
for(int i=0;i<480;i++){
map[i]=0;
}
openedfile=NULL;
m_speed=0;
m_curName="SnakeMap";
UpdateData(FALSE);
return TRUE; // return TRUE unless you set the focus to a control
}
void CSnakemapDlg::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 CSnakemapDlg::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();
CClientDC dc(this);
CPen pen;
pen.CreateStockObject(NULL_PEN);
CPen* oldpen=dc.SelectObject(&pen);
UpdateData(TRUE);
CBrush br[6];
br[0].CreateStockObject(NULL_BRUSH);
br[1].CreateSolidBrush(0);
br[2].CreateSolidBrush(RGB(255,255,0));
br[3].CreateSolidBrush(RGB(0,0,255));
br[4].CreateSolidBrush(RGB(0,255,0));
br[5].CreateSolidBrush(RGB(255,0,0));
CBrush* oldbr=dc.SelectObject(&br[0]);
int i,j;
for(j=0;j<24;j++){
for(i=0;i<20;i++){
dc.SelectObject(&br[map[j*20+i]]);
if(map[j*20+i]==1){
dc.Rectangle(182+i*15,11+j*15,196+i*15,25+j*15);
}else {
dc.Ellipse(182+i*15,11+j*15,196+i*15,25+j*15);
}
}
}
CPen p;
p.CreatePen(PS_SOLID,3,RGB(255,0,0));
dc.SelectObject(&p);
dc.MoveTo(189+m_snake1x*15,18+m_snake1y*15);
dc.LineTo(189+m_snake2x*15,18+m_snake2y*15);
dc.LineTo(189+m_snake3x*15,18+m_snake3y*15);
dc.SelectObject(oldbr);
dc.SelectObject(oldpen);
}
}
// The system calls this to obtain the cursor to display while the user drags
// the minimized window.
HCURSOR CSnakemapDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CSnakemapDlg::OnRadio3()
{
}
void CSnakemapDlg::OnRButtonDown(UINT nFlags, CPoint point)
{
UpdateData(TRUE);
if(point.x<182||point.x>482||point.y<11||point.y>371){}
else{
int i=(point.x-182)/15;
int j=(point.y-11)/15;
map[j*20+i]=0;
RECT rc={182+i*15,11+j*15,196+i*15,25+j*15};
InvalidateRect(&rc);
}
CDialog::OnRButtonDown(nFlags, point);
}
void CSnakemapDlg::OnLButtonDown(UINT nFlags, CPoint point)
{
UpdateData(TRUE);
//CString s;
//s.Format("x=%d,y=%d",point.x,point.y);
//AfxMessageBox(s);
if(point.x<182||point.x>482||point.y<11||point.y>371){}
else{
int i=(point.x-182)/15;
int j=(point.y-11)/15;
map[j*20+i]=m_item1;
RECT rc={182+i*15,11+j*15,196+i*15,25+j*15};
InvalidateRect(&rc);
}
CDialog::OnLButtonDown(nFlags, point);
}
void CSnakemapDlg::OnMouseMove(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if(point.x>=182&&point.x<482&&point.y>=11&&point.y<371&&(nFlags&MK_LBUTTON)){
int i=(point.x-182)/15;
int j=(point.y-11)/15;
map[j*20+i]=m_item1;
RECT rc={182+i*15,11+j*15,196+i*15,25+j*15};
InvalidateRect(&rc);
}
CDialog::OnMouseMove(nFlags, point);
}
void CSnakemapDlg::OnChangeEdit2()
{
Invalidate();
}
void CSnakemapDlg::OnChangeEdit3()
{
Invalidate();
}
void CSnakemapDlg::OnChangeEdit4()
{
Invalidate();
}
void CSnakemapDlg::OnChangeEdit5()
{
Invalidate();
}
void CSnakemapDlg::OnChangeEdit6()
{
Invalidate();
}
void CSnakemapDlg::OnChangeEdit7()
{
Invalidate();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -