// 趣味拼图Dlg.cpp : implementation file
//
#include "stdafx.h"
#include "趣味拼图.h"
#include "趣味拼图Dlg.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()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg dialog
CMyDlg::CMyDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMyDlg::IDD, pParent)
{
GameStart=FALSE;
IsCtrl=FALSE;
IsChange=FALSE;
firstrun=TRUE;
GetModuleFileName(AfxGetApp()->m_hInstance,filename,255);
for(int i=strlen(filename)-1;i>=0;i--)
{
if (filename[i]=='\\') break;
}
filename[i+1]='\0';
image.InitBitmapFromResource(IDB_PICTURE);
//{{AFX_DATA_INIT(CMyDlg)
m_player = _T("");
//}}AFX_DATA_INIT
// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}
void CMyDlg::DoDataExchange(CDataExchange* pDX)
{
CDialog::DoDataExchange(pDX);
//{{AFX_DATA_MAP(CMyDlg)
DDX_Text(pDX, IDC_BOX, m_player);
DDX_Control(pDX, IDC_OCX1, m_player1);
//}}AFX_DATA_MAP
}
BEGIN_MESSAGE_MAP(CMyDlg, CDialog)
//{{AFX_MSG_MAP(CMyDlg)
ON_WM_SYSCOMMAND()
ON_WM_PAINT()
ON_WM_QUERYDRAGICON()
ON_COMMAND(IDM_EXIT, OnExit)
ON_WM_DESTROY()
ON_COMMAND(IDM_PICTURE, OnPicture)
ON_WM_LBUTTONDOWN()
ON_COMMAND(IDM_NEW, OnNew)
ON_COMMAND(IDM_ABOUT, OnAbout)
ON_COMMAND(IDM_ENDGAME, OnEndgame)
ON_WM_TIMER()
ON_WM_MOUSEMOVE()
ON_COMMAND(IDC_OPEN, OnOpen)
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
/////////////////////////////////////////////////////////////////////////////
// CMyDlg message handlers
BOOL CMyDlg::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);
}
// 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
m_time.SubclassDlgItem(IDC_TIME,this);
m_time.SetWindowText("");
m_times.SubclassDlgItem(IDC_TIMES,this);
m_times.SetWindowText("");
m_box.SubclassDlgItem(IDC_BOX,this);
m_box.SetWindowText("");
// TODO: Add extra initialization here
return TRUE; // return TRUE unless you set the focus to a control
}
void CMyDlg::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 CMyDlg::OnPaint()
{
CPaintDC dc(this); // device context for painting
//////////////////////////////////////////
//
if(GameStart==FALSE) InitDat();
CPen pen;
pen.CreatePen(PS_SOLID,1,RGB(0,0,255));
dc.SelectObject(&pen);
dc.MoveTo(8,8);
dc.LineTo(8,258);
dc.LineTo(321,258);
dc.LineTo(321,8);
dc.LineTo(8,8);
pen.CreatePen(PS_SOLID,1,RGB(0,0,0));
dc.SelectObject(&pen);
image.InitDeviceDC(&dc);
image.PutImageUseDrawDib(330,10,430,90);
for(int i=330;i<=430;i+=20)
{
dc.MoveTo(i,10);
dc.LineTo(i,90);
}
for(int j=10;j<=90;j+=20)
{
dc.MoveTo(330,j);
dc.LineTo(430,j);
}
dc.FillSolidRect(410,70,20,20,RGB(192,192,192));
pen.DeleteObject();
//
for(i=0;i<5;i++)
for(int j=0;j<4;j++)
{
if (Box[i][j].HavePic)
image.PutImageUseDrawDib(Box[i][j].x,Box[i][j].y,Box[i][j].x+WIDTH,Box[i][j].y+HEIGH,Box[i][j].bx,Box[i][j].by,Box[i][j].bx+dx,Box[i][j].by+dy);
else
{
CPen pen;
pen.CreatePen(PS_SOLID,1,BACKCOLOR);
dc.SelectObject(&pen);
CBrush brush;
brush.CreateSolidBrush(BACKCOLOR);
dc.SelectObject(&brush);
dc.Rectangle(Box[i][j].x,Box[i][j].y,Box[i][j].x+WIDTH,Box[i][j].y+HEIGH);
pen.DeleteObject();
brush.DeleteObject();
}
}
//
//////////////////////////////////////////
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 CMyDlg::OnQueryDragIcon()
{
return (HCURSOR) m_hIcon;
}
void CMyDlg::OnExit()
{
// TODO: Add your command handler code here
CMyDlg::EndDialog(0);
}
void CMyDlg::OnDestroy()
{
CDialog::OnDestroy();
// TODO: Add your message handler code here
}
void CMyDlg::OnPicture()
{
CFileDialog dlg(FALSE,
"", //缺省扩展名
"*.bmp",
OFN_HIDEREADONLY|OFN_FILEMUSTEXIST, //文件必须存在
"位图 files(*.bmp)|*.bmp|",
this);
dlg.m_ofn.lpstrInitialDir=filename;
if (dlg.DoModal()==IDOK)
{
ASSERT(dlg.GetPathName());
image.InitBitmapFromFile(dlg.GetPathName());
CMyDlg::Invalidate();
}
}
void CMyDlg::InitDat()
{
times=0;mm=0;ss=0;
dx=image.GetBitmapWidth()/5;
dy=image.GetBitmapHeigh()/4;
for(int i=0;i<5;i++)
for(int j=0;j<4;j++)
{
Box[i][j].x=i*(WIDTH+2)+10;
Box[i][j].y=j*(HEIGH+2)+10;
Box[i][j].bx=i*dx;
Box[i][j].by=j*dy;
Box[i][j].HavePic=TRUE;
CheckBox[i][j].x=i*(WIDTH+2)+10;
CheckBox[i][j].y=j*(HEIGH+2)+10;
CheckBox[i][j].bx=i*dx;
CheckBox[i][j].by=j*dy;
CheckBox[i][j].HavePic=TRUE;
}
Box[4][3].HavePic=FALSE;
CheckBox[4][3].HavePic=FALSE;
}
void CMyDlg::ChangePic(int i1,int j1,int i2,int j2,BOOL Repaint)
{
BOOL mid=Box[i1][j1].HavePic;
Box[i1][j1].HavePic=Box[i2][j2].HavePic;
Box[i2][j2].HavePic=mid;
int x,y;
x=Box[i1][j1].bx;
y=Box[i1][j1].by;
Box[i1][j1].bx=Box[i2][j2].bx;
Box[i1][j1].by=Box[i2][j2].by;
Box[i2][j2].bx=x;
Box[i2][j2].by=y;
if (Repaint)
{
CClientDC dc(this);
CDC memdc;
memdc.CreateCompatibleDC(&dc);
memdc.SelectObject(&image.Bitmap);
image.InitDeviceDC(&dc);
if (Box[i1][j1].HavePic)
image.PutImageUseDrawDib(Box[i1][j1].x,Box[i1][j1].y,Box[i1][j1].x+WIDTH,Box[i1][j1].y+HEIGH,Box[i1][j1].bx,Box[i1][j1].by,Box[i1][j1].bx+dx,Box[i1][j1].by+dy);
else
{
CPen pen;
pen.CreatePen(PS_SOLID,1,BACKCOLOR);
dc.SelectObject(&pen);
CBrush brush;
brush.CreateSolidBrush(BACKCOLOR);
dc.SelectObject(&brush);
dc.Rectangle(Box[i1][j1].x,Box[i1][j1].y,Box[i1][j1].x+WIDTH,Box[i1][j1].y+HEIGH);
pen.DeleteObject();
brush.DeleteObject();
}
趣味拼图.rar
需积分: 0 80 浏览量
2007-05-05
23:59:56
上传
评论
收藏 1.58MB RAR 举报
lanxin991
- 粉丝: 4
- 资源: 84
最新资源
- python-leetcode面试题解之第157题用Read4读取N个字符-题解.zip
- python-leetcode面试题解之第156题上下翻转二叉树-题解.zip
- python-leetcode面试题解之第155题最小栈-题解.zip
- python-leetcode面试题解之第153题寻找旋转排序数组中的最小值-题解.zip
- python-leetcode面试题解之第152题乘积最大子数组-题解.zip
- python-leetcode面试题解之第151题反转字符串中的单词-题解.zip
- python-leetcode面试题解之第150题逆波兰表达式求值-题解.zip
- python-leetcode面试题解之第149题直线上最多的点数-题解.zip
- python-leetcode面试题解之第148题排序链表-题解.zip
- python-leetcode面试题解之第147题对链表进行插入排序-题解.zip
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
评论0