www.pudn.com > PtGame.rar > PtGameDlg.cpp


// PtGameDlg.cpp : implementation file 
// 
 
#include "stdafx.h" 
#include "PtGame.h" 
#include "PtGameDlg.h" 
#include "SettingDlg.h" 
#include "LookDlg.h" 
#include  
 
#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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CPtGameDlg dialog 
 
CPtGameDlg::CPtGameDlg(CWnd* pParent /*=NULL*/) 
	: CDialog(CPtGameDlg::IDD, pParent) 
{ 
	//{{AFX_DATA_INIT(CPtGameDlg) 
		// 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); 
	hnums=AfxGetApp()->GetProfileInt(_T("游戏参数"),_T("hnums"),4); 
	vnums=AfxGetApp()->GetProfileInt(_T("游戏参数"),_T("vnums"),3); 
	gamepicture=AfxGetApp()->GetProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP3); 
	musiconoff=AfxGetApp()->GetProfileInt(_T("游戏参数"),_T("musiconoff"),FALSE); 
	musicfilename=AfxGetApp()->GetProfileString(_T("游戏参数"),_T("musicfilename"),""); 
	blacksite.x =hnums; 
	blacksite.y =vnums; 
	tracksteps=0; 
	tempsteps=0; 
	autoplay=FALSE; 
	m_bMouseTell=FALSE; 
	m_iStart=0; 
	m_strInfo="     Please Write To Me.  E-Mail:  qjqmoney@elong.com.  Thank You!!  2002-08-20     "; 
	 
} 
 
CPtGameDlg::~CPtGameDlg() 
{ 
	DeleteObject(bitmap); 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("hnums"),hnums); 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("vnums"),vnums); 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),gamepicture); 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("musiconoff"),musiconoff); 
	AfxGetApp()->WriteProfileString(_T("游戏参数"),_T("musicfilename"),musicfilename); 
 
} 
void CPtGameDlg::DoDataExchange(CDataExchange* pDX) 
{ 
	CDialog::DoDataExchange(pDX); 
	//{{AFX_DATA_MAP(CPtGameDlg) 
		// NOTE: the ClassWizard will add DDX and DDV calls here 
	//}}AFX_DATA_MAP 
} 
 
BEGIN_MESSAGE_MAP(CPtGameDlg, CDialog) 
	//{{AFX_MSG_MAP(CPtGameDlg) 
	ON_WM_SYSCOMMAND() 
	ON_WM_PAINT() 
	ON_WM_QUERYDRAGICON() 
	ON_WM_KEYDOWN() 
	ON_WM_LBUTTONDOWN() 
	ON_COMMAND(IDM_NEWGAME, OnNewgame) 
	ON_COMMAND(IDM_AUTOPLAY, OnAutoplay) 
	ON_WM_TIMER() 
	ON_COMMAND(IDM_EXIT, OnExit) 
	ON_COMMAND(IDM_SET, OnSet) 
	ON_COMMAND(IDM_USERPIC, OnUserpic) 
	ON_COMMAND(IDM_ABOUT, OnAbout) 
	ON_COMMAND(IDM_PRELOOK, OnPrelook) 
	ON_COMMAND(IDM_PIC1, OnPic1) 
	ON_COMMAND(IDM_PIC2, OnPic2) 
	ON_COMMAND(IDM_PIC3, OnPic3) 
	ON_COMMAND(IDM_PIC4, OnPic4) 
	ON_COMMAND(IDM_PIC5, OnPic5) 
	ON_COMMAND(IDM_PIC6, OnPic6) 
	ON_WM_CLOSE() 
	ON_COMMAND(IDM_MOUSETELL, OnMousetell) 
	ON_WM_MOUSEMOVE() 
	//}}AFX_MSG_MAP 
END_MESSAGE_MAP() 
 
///////////////////////////////////////////////////////////////////////////// 
// CPtGameDlg message handlers 
 
BOOL CPtGameDlg::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 
	//创建位图菜单 
	HMENU hmenu; 
	hmenu=::GetMenu(m_hWnd); 
	hmenu=::GetSubMenu(hmenu,1); 
	char * hbmp; 
	hbmp=(char *)LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_PIC1)); 
	::ModifyMenu(hmenu,2,MF_BYPOSITION|MF_BITMAP,::GetMenuItemID(hmenu,2),hbmp); 
	hbmp=(char *)LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_PIC2)); 
	::ModifyMenu(hmenu,3,MF_BYPOSITION|MF_BITMAP,::GetMenuItemID(hmenu,3),hbmp); 
	hbmp=(char *)LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_PIC3)); 
	::ModifyMenu(hmenu,4,MF_BYPOSITION|MF_BITMAP,::GetMenuItemID(hmenu,4),hbmp); 
	hbmp=(char *)LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_PIC4)); 
	::ModifyMenu(hmenu,5,MF_BYPOSITION|MF_BITMAP,::GetMenuItemID(hmenu,5),hbmp); 
	hbmp=(char *)LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_PIC5)); 
	::ModifyMenu(hmenu,6,MF_BYPOSITION|MF_BITMAP,::GetMenuItemID(hmenu,6),hbmp); 
	hbmp=(char *)LoadBitmap(AfxGetInstanceHandle(),MAKEINTRESOURCE(IDB_PIC6)); 
	::ModifyMenu(hmenu,7,MF_BYPOSITION|MF_BITMAP,::GetMenuItemID(hmenu,7),hbmp); 
	//创建状态栏 
	m_wndStatusBar.Create(WS_CHILD|WS_VISIBLE|CCS_BOTTOM,CRect(0,0,0,0),this,102); 
	int iPartDim[3]={100,370,-1}; 
	m_wndStatusBar.SetParts(3,iPartDim); 
	m_wndStatusBar.SetText("正在游戏",0,0); 
	m_wndStatusBar.SetText("用方向键移动,或用鼠标左键单击黑块周围图块",1,0); 
	CRect rc; 
	GetClientRect(&rc); 
	clientwidth=rc.Width(); 
	clientheight=rc.Height()-20; 
	cellwidth=clientwidth/hnums; 
	cellheight=clientheight/vnums; 
	bitmap.LoadBitmap(gamepicture); 
	initialsiteinfo(); 
	SetTimer(2,150,NULL); 
	// TODO: Add extra initialization here 
	 
	return TRUE;  // return TRUE  unless you set the focus to a control 
} 
 
void CPtGameDlg::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 CPtGameDlg::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 
	{ 
		int i; 
		int j; 
		struct site destsite; 
		struct site srcsite; 
		for(i = 1;i<=hnums;i++) 
		{ 
			for(j = 1;j<=vnums;j++) 
			{ 
				srcsite.x = siteinfo[i][j].x; 
				srcsite.y = siteinfo[i][j].y; 
				destsite.x = i; 
				destsite.y = j; 
				paintpic(destsite, srcsite); 
			} 
		} 
		paintline(); 
		paintblack(); 
		CDialog::OnPaint(); 
	} 
} 
 
// The system calls this to obtain the cursor to display while the user drags 
//  the minimized window. 
HCURSOR CPtGameDlg::OnQueryDragIcon() 
{ 
	return (HCURSOR) m_hIcon; 
} 
 
void CPtGameDlg::initialsiteinfo() 
{ 
	int i,j; 
	for(i=1;i<=hnums;i++) 
	{ 
		for(j=1;j<=vnums;j++) 
		{ 
			siteinfo[i][j].x =i; 
			siteinfo[i][j].y =j; 
		} 
	} 
	return; 
 
} 
 
void CPtGameDlg::paintline() 
{ 
	int i; 
	CDC *pDC=GetDC(); 
	for(i=1;iMoveTo(i*cellwidth-1,0); 
		pDC->LineTo(i*cellwidth-1,clientheight); 
	} 
	for(i=1;iMoveTo(0,i*cellheight-1); 
		pDC->LineTo(clientwidth,i*cellheight-1); 
	} 
	pDC->DeleteDC(); 
	return; 
 
} 
 
void CPtGameDlg::paintblack() 
{ 
	RECT rc; 
	rc.left =(blacksite.x-1)*cellwidth; 
	rc.top =(blacksite.y -1)*cellheight; 
	rc.right=rc.left +cellwidth; 
	rc.bottom =rc.top +cellheight; 
	CDC *pDC=GetDC(); 
	pDC->FillSolidRect(&rc,RGB(0,0,0)); 
	pDC->DeleteDC(); 
	return; 
} 
 
void CPtGameDlg::paintpic(struct site destsite, struct site srcsite) 
{ 
	CDC *pDC=GetDC(); 
	CDC memdc; 
	memdc.CreateCompatibleDC(pDC); 
	memdc.SelectObject(bitmap); 
	pDC->BitBlt((destsite.x-1)*cellwidth,(destsite.y-1)*cellheight,cellwidth,cellheight,&memdc,(srcsite.x-1)*cellwidth,(srcsite.y-1)*cellheight,SRCCOPY); 
	pDC->DeleteDC(); 
	return; 
} 
 
BOOL CPtGameDlg::PreTranslateMessage(MSG* pMsg)  
{ 
	// TODO: Add your specialized code here and/or call the base class 
	if(pMsg->message==WM_KEYDOWN) 
	{ 
		OnKeyDown((UINT)pMsg->wParam,(UINT)pMsg->lParam,(UINT)pMsg->lParam); 
	} 
	return CDialog::PreTranslateMessage(pMsg); 
} 
 
void CPtGameDlg::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)  
{ 
	// TODO: Add your message handler code here and/or call default 
	struct site tempsite; 
	switch(nChar) 
	{ 
	case VK_LEFT: 
		if(blacksite.x>1) 
		{ 
			tracksteps+=1; 
			if(tracksteps>1000) 
			{ 
				MessageBox("所定义数组空间已用完,你水平太臭了!","俄罗斯方块游戏",MB_OK|MB_ICONINFORMATION); 
				CDialog::EndDialog(0); 
			} 
			track[tracksteps]=1; 
			tempsite.x =blacksite.x-1; 
			tempsite.y =blacksite.y ; 
			siteinfo[blacksite.x][blacksite.y].x = siteinfo[tempsite.x][tempsite.y].x; 
            siteinfo[blacksite.x][blacksite.y].y = siteinfo[tempsite.x][tempsite.y].y; 
            tempsite.x = siteinfo[blacksite.x][blacksite.y].x; 
            tempsite.y = siteinfo[blacksite.x][blacksite.y].y; 
            paintpic(blacksite,tempsite);  
            blacksite.x = blacksite.x - 1; 
            paintblack(); 
            paintline(); 
            if(tracksteps > 1) 
			{ 
                if(track[tracksteps - 1]== 2) 
				{ 
                    tracksteps = tracksteps - 2; 
                } 
            } 
		} 
		break; 
	case VK_RIGHT: 
		if(blacksite.x1000) 
			{ 
				MessageBox("所定义数组空间已用完,你水平太臭了!","俄罗斯方块游戏",MB_OK|MB_ICONINFORMATION); 
				CDialog::EndDialog(0); 
			} 
			track[tracksteps]=2; 
			tempsite.x =blacksite.x+1; 
			tempsite.y =blacksite.y ; 
			siteinfo[blacksite.x][blacksite.y].x = siteinfo[tempsite.x][tempsite.y].x; 
            siteinfo[blacksite.x][blacksite.y].y = siteinfo[tempsite.x][tempsite.y].y; 
            tempsite.x = siteinfo[blacksite.x][blacksite.y].x; 
            tempsite.y = siteinfo[blacksite.x][blacksite.y].y; 
            paintpic(blacksite,tempsite);  
            blacksite.x = blacksite.x + 1; 
            paintblack(); 
            paintline(); 
            if(tracksteps > 1) 
			{ 
                if(track[tracksteps - 1]== 1) 
				{ 
                    tracksteps = tracksteps - 2; 
                } 
            } 
		} 
		break; 
	case VK_UP: 
		if(blacksite.y>1) 
		{ 
			tracksteps+=1; 
			if(tracksteps>1000) 
			{ 
				MessageBox("所定义数组空间已用完,你水平太臭了!","俄罗斯方块游戏",MB_OK|MB_ICONINFORMATION); 
				CDialog::EndDialog(0); 
			} 
			track[tracksteps]=3; 
			tempsite.x =blacksite.x; 
			tempsite.y =blacksite.y-1 ; 
			siteinfo[blacksite.x][blacksite.y].x = siteinfo[tempsite.x][tempsite.y].x; 
            siteinfo[blacksite.x][blacksite.y].y = siteinfo[tempsite.x][tempsite.y].y; 
            tempsite.x = siteinfo[blacksite.x][blacksite.y].x; 
            tempsite.y = siteinfo[blacksite.x][blacksite.y].y; 
            paintpic(blacksite,tempsite);  
            blacksite.y = blacksite.y - 1; 
            paintblack(); 
            paintline(); 
            if(tracksteps > 1) 
			{ 
                if(track[tracksteps - 1]== 4) 
				{ 
                    tracksteps = tracksteps - 2; 
                } 
            } 
		} 
		break; 
	case VK_DOWN: 
		if(blacksite.y1000) 
			{ 
				MessageBox("所定义数组空间已用完,你水平太臭了!","俄罗斯方块游戏",MB_OK|MB_ICONINFORMATION); 
				CDialog::EndDialog(0); 
			} 
			track[tracksteps]=4; 
			tempsite.x =blacksite.x; 
			tempsite.y =blacksite.y+1 ; 
			siteinfo[blacksite.x][blacksite.y].x = siteinfo[tempsite.x][tempsite.y].x; 
            siteinfo[blacksite.x][blacksite.y].y = siteinfo[tempsite.x][tempsite.y].y; 
            tempsite.x = siteinfo[blacksite.x][blacksite.y].x; 
            tempsite.y = siteinfo[blacksite.x][blacksite.y].y; 
            paintpic(blacksite,tempsite);  
            blacksite.y = blacksite.y + 1; 
            paintblack(); 
            paintline(); 
            if(tracksteps > 1) 
			{ 
                if(track[tracksteps - 1]== 3) 
				{ 
                    tracksteps = tracksteps - 2; 
                } 
            } 
		} 
		break; 
	} 
	CDialog::OnKeyDown(nChar, nRepCnt, nFlags); 
} 
 
void CPtGameDlg::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	struct site mousesite; 
	mousesite.x =point.x/cellwidth+1; 
	mousesite.y =point.y/cellheight+1; 
	if(abs(mousesite.x-blacksite.x)+abs(mousesite.y-blacksite.y)==1) 
	{ 
		if(mousesite.x - blacksite.x == 1) 
		{ 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_RIGHT,0); 
		} 
        if(mousesite.x - blacksite.x == -1) 
		{ 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_LEFT,0); 
		} 
		if(mousesite.y - blacksite.y == 1) 
		{ 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_DOWN,0); 
		} 
		if(mousesite.y - blacksite.y == -1) 
		{ 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_UP,0); 
		} 
	} 
	winornot();//判断是否已赢得这局游戏 
	CDialog::OnLButtonDown(nFlags, point); 
} 
 
void CPtGameDlg::OnNewgame()  
{ 
	// TODO: Add your command handler code here 
	tracksteps=0; 
	cellwidth=clientwidth/hnums; 
	cellheight=clientheight/vnums; 
	initialsiteinfo(); 
	blacksite.x =hnums; 
	blacksite.y =vnums; 
	Invalidate(FALSE); 
	initialgame(); 
} 
 
void CPtGameDlg::initialgame() 
{ 
	int i,temp; 
	srand(time(NULL)); 
	for(i=1;i<300;i++) 
	{ 
		temp=rand()%4+1; 
		switch(temp) 
		{ 
		case 1: 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_LEFT,0); 
			break; 
		case 2: 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_RIGHT,0); 
			break; 
		case 3: 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_UP,0); 
			break; 
		case 4: 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_DOWN,0); 
			break; 
		} 
	} 
} 
 
void CPtGameDlg::OnAutoplay()  
{ 
	// TODO: Add your command handler code here 
	tempsteps=tracksteps; 
	HMENU hmenu; 
	hmenu=::GetSubMenu(::GetMenu(m_hWnd),0); 
	if(autoplay==FALSE) 
	{ 
		if(tempsteps>0) 
		{ 
		m_wndStatusBar.SetText("正在自动拼图",0,0); 
		autoplay=TRUE; 
		::ModifyMenu(hmenu,1,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,1),"停止自动拼图"); 
		SetTimer(1,300,NULL); 
		} 
	} 
	else 
	{ 
		autoplay=FALSE; 
		KillTimer(1); 
		::ModifyMenu(hmenu,1,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,1),"自动拼图"); 
		m_wndStatusBar.SetText("正在游戏",0,0); 
	} 
} 
 
void CPtGameDlg::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	switch(nIDEvent) 
	{ 
	case 1: 
		switch(track[tempsteps]) 
		{ 
		case 1: 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_RIGHT,0); 
			break; 
		case 2: 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_LEFT,0); 
			break; 
		case 3: 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_DOWN,0); 
			break; 
		case 4: 
			::SendMessage(m_hWnd,WM_KEYDOWN,VK_UP,0); 
			break; 
		} 
		tempsteps-=1; 
		if(tracksteps==0) 
		{ 
			KillTimer(1); 
			paintpic(blacksite,blacksite); 
			autoplay=FALSE; 
			MessageBox("自动拼图已完成!","拼图游戏",MB_OK|MB_ICONINFORMATION); 
			HMENU hmenu; 
			hmenu=::GetSubMenu(::GetMenu(m_hWnd),0); 
			::ModifyMenu(hmenu,1,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,1),"自动拼图"); 
			m_wndStatusBar.SetText("正在游戏",0,0); 
		} 
		break; 
	case 2: 
		m_iStart+=1; 
		m_wndStatusBar.SetText(m_strInfo.Mid(m_iStart),2,0); 
		if(m_iStart>=m_strInfo.GetLength())m_iStart=0; 
		break; 
	} 
	CDialog::OnTimer(nIDEvent); 
} 
 
void CPtGameDlg::OnExit()  
{ 
	// TODO: Add your command handler code here 
	KillTimer(1); 
	CDialog::EndDialog(0); 
} 
 
void CPtGameDlg::OnSet()  
{ 
	// TODO: Add your command handler code here 
	CSettingDlg set; 
	if(set.DoModal()==IDOK) 
	{ 
		hnums=set.m_iCols; 
		vnums=set.m_iRows; 
		musiconoff=set.m_bMusic; 
		musicfilename=set.m_strMusicFileName; 
		if(musiconoff==TRUE) 
		{ 
			PlayMusic(); 
		} 
		else 
		{ 
			MCI_GENERIC_PARMS mciGP; 
			mciSendCommand(m_wID,MCI_STOP,MCI_NOTIFY,(DWORD)(LPVOID)&mciGP); 
		} 
		CPtGameDlg::OnNewgame(); 
	} 
} 
 
void CPtGameDlg::winornot() 
{ 
	int i,j; 
	for(i = 1;i<=hnums;i++) 
	{ 
		for(j = 1;j<=vnums;j++) 
		{ 
			if(i !=blacksite.x || j != blacksite.y) 
				if(siteinfo[i][j].x !=i || siteinfo[i][j].y !=j) 
					return; 
		} 
	} 
	paintpic(blacksite, blacksite); 
	paintline(); 
	MessageBox("恭喜你,你已赢得这局游戏,要重新开始,请单击 '新游戏' ","拼图游戏",MB_OK|MB_ICONINFORMATION); 
	tracksteps = 0; 
	return; 
} 
 
void CPtGameDlg::OnUserpic()  
{ 
	// TODO: Add your command handler code here 
	CString filter="BMP文件(*.bmp)|*.bmp"; 
	CFileDialog picfile(TRUE,NULL,NULL,OFN_HIDEREADONLY|OFN_OVERWRITEPROMPT,filter); 
	if(picfile.DoModal()==IDOK) 
	{ 
		HBITMAP hbitmap; 
		hbitmap=(HBITMAP)::LoadImage(NULL,picfile.GetPathName(),IMAGE_BITMAP,500,350,LR_LOADFROMFILE); 
		bitmap.Detach(); 
		bitmap.Attach(hbitmap); 
		CPtGameDlg::OnNewgame(); 
	} 
 
} 
 
void CPtGameDlg::OnAbout()  
{ 
	// TODO: Add your command handler code here 
	CAboutDlg about; 
	about.DoModal(); 
} 
 
 
 
void CPtGameDlg::PlayMusic() 
{ 
	MCI_GENERIC_PARMS mciGP; 
	mciSendCommand(m_wID,MCI_CLOSE,MCI_NOTIFY,(DWORD)(LPVOID)&mciGP); 
	MCI_OPEN_PARMS mciOP; 
	DWORD dwReturn; 
	mciOP.lpstrDeviceType=NULL; 
	mciOP.lpstrElementName=musicfilename; 
	dwReturn=mciSendCommand(NULL,MCI_OPEN,MCI_OPEN_ELEMENT,(DWORD)(LPVOID)&mciOP); 
	if(dwReturn==0) 
	{ 
		m_wID=mciOP.wDeviceID; 
	} 
	MCI_PLAY_PARMS mciPP; 
	mciSendCommand(m_wID,MCI_PLAY,MCI_NOTIFY,(DWORD)(LPVOID)&mciPP); 
} 
 
void CPtGameDlg::OnPrelook()  
{ 
	// TODO: Add your command handler code here 
	CLookDlg look; 
	look.DoModal(); 
} 
 
void CPtGameDlg::OnPic1()  
{ 
	// TODO: Add your command handler code here 
	gamepicture=IDB_BITMAP1; 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP1); 
	bitmap.Detach(); 
	bitmap.LoadBitmap(IDB_BITMAP1); 
	CPtGameDlg::OnNewgame(); 
} 
 
void CPtGameDlg::OnPic2()  
{ 
	// TODO: Add your command handler code here 
	gamepicture=IDB_BITMAP2; 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP2); 
	bitmap.Detach(); 
	bitmap.LoadBitmap(IDB_BITMAP2); 
	CPtGameDlg::OnNewgame(); 
	 
} 
 
void CPtGameDlg::OnPic3()  
{ 
	// TODO: Add your command handler code here 
	gamepicture=IDB_BITMAP3; 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP3); 
	bitmap.Detach(); 
	bitmap.LoadBitmap(IDB_BITMAP3); 
	CPtGameDlg::OnNewgame(); 
	 
} 
 
void CPtGameDlg::OnPic4()  
{ 
	// TODO: Add your command handler code here 
	gamepicture=IDB_BITMAP4; 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP4); 
	bitmap.Detach(); 
	bitmap.LoadBitmap(IDB_BITMAP4); 
	CPtGameDlg::OnNewgame(); 
	 
} 
 
void CPtGameDlg::OnPic5()  
{ 
	// TODO: Add your command handler code here 
	gamepicture=IDB_BITMAP5; 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP5); 
	bitmap.Detach(); 
	bitmap.LoadBitmap(IDB_BITMAP5); 
	CPtGameDlg::OnNewgame(); 
	 
} 
 
void CPtGameDlg::OnPic6()  
{ 
	// TODO: Add your command handler code here 
	gamepicture=IDB_BITMAP6; 
	AfxGetApp()->WriteProfileInt(_T("游戏参数"),_T("gamepicture"),IDB_BITMAP6); 
	bitmap.Detach(); 
	bitmap.LoadBitmap(IDB_BITMAP6); 
	CPtGameDlg::OnNewgame(); 
	 
} 
 
void CPtGameDlg::OnClose()  
{ 
	// TODO: Add your message handler code here and/or call default 
	KillTimer(1); 
	KillTimer(2); 
	CDialog::OnClose(); 
} 
 
void CPtGameDlg::OnMousetell()  
{ 
	// TODO: Add your command handler code here 
	HMENU hmenu; 
	hmenu=::GetSubMenu(::GetMenu(m_hWnd),0); 
	if(m_bMouseTell==FALSE) 
	{ 
		m_bMouseTell=TRUE; 
		::ModifyMenu(hmenu,2,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,2),"取消鼠标提示"); 
	} 
	else 
	{ 
		m_bMouseTell=FALSE; 
		::ModifyMenu(hmenu,2,MF_BYPOSITION|MF_STRING,::GetMenuItemID(hmenu,2),"鼠标提示"); 
	} 
} 
 
 
void CPtGameDlg::OnMouseMove(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	struct site mousesite; 
	mousesite.x = point.x/cellwidth+1; 
	mousesite.y = point.y/cellheight+1; 
	if(m_bMouseTell==TRUE) 
	{	 
		CString str; 
		char buffer[5]; 
		str="该图块在原始图片中的位置: ( 第 " ; 
		_itoa(siteinfo[mousesite.x][mousesite.y].y,buffer,10); 
		str+=buffer; 
		str+=" 行, 第 "; 
		_itoa(siteinfo[mousesite.x][mousesite.y].x,buffer,10); 
		str+=buffer; 
		str+=" 列 )"; 
		m_wndStatusBar.SetText(str,1,0); 
	} 
	else 
		m_wndStatusBar.SetText("用方向键移动,或用鼠标左键单击黑块周围图块",1,0); 
	 
	CDialog::OnMouseMove(nFlags, point); 
}