⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 pictur~1.cpp

📁 visual c++ 时尚编程百例 全部源代码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
// PictureGameDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PictureGame.h"
#include "PictureGameDlg.h"
#include"math.h"
#include"stdio.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()

/////////////////////////////////////////////////////////////////////////////
// CPictureGameDlg dialog

CPictureGameDlg::CPictureGameDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CPictureGameDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CPictureGameDlg)
		// 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);
}

void CPictureGameDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPictureGameDlg)
		// NOTE: the ClassWizard will add DDX and DDV calls here
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPictureGameDlg, CDialog)
	//{{AFX_MSG_MAP(CPictureGameDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_COMMAND(ID_PICTURE1, OnPicture1)
	ON_COMMAND(ID_PICTURE2, OnPicture2)
	ON_COMMAND(ID_PICTURE4, OnPicture4)
	ON_COMMAND(ID_PICTURE3, OnPicture3)
	ON_COMMAND(ID_OWNER, OnOwner)
	ON_COMMAND(ID_EASY, OnEasy)
	ON_COMMAND(ID_HARD, OnHard)
	ON_COMMAND(ID_3D, On3d)
	ON_COMMAND(ID_FLAT, OnFlat)
	ON_BN_CLICKED(IDC_STATIC1, OnStatic1)
	ON_BN_CLICKED(IDC_STATIC10, OnStatic10)
	ON_BN_CLICKED(IDC_STATIC11, OnStatic11)
	ON_BN_CLICKED(IDC_STATIC12, OnStatic12)
	ON_BN_CLICKED(IDC_STATIC13, OnStatic13)
	ON_BN_CLICKED(IDC_STATIC14, OnStatic14)
	ON_BN_CLICKED(IDC_STATIC15, OnStatic15)
	ON_BN_CLICKED(IDC_STATIC16, OnStatic16)
	ON_BN_CLICKED(IDC_STATIC2, OnStatic2)
	ON_BN_CLICKED(IDC_STATIC3, OnStatic3)
	ON_BN_CLICKED(IDC_STATIC4, OnStatic4)
	ON_BN_CLICKED(IDC_STATIC5, OnStatic5)
	ON_BN_CLICKED(IDC_STATIC6, OnStatic6)
	ON_BN_CLICKED(IDC_STATIC7, OnStatic7)
	ON_BN_CLICKED(IDC_STATIC8, OnStatic8)
	ON_BN_CLICKED(IDC_STATIC9, OnStatic9)
	ON_COMMAND(ID_HELP, OnForHelp)
	ON_WM_TIMER()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPictureGameDlg message handlers

BOOL CPictureGameDlg::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
	pMainMenu=GetMenu();
	SetWindowPos(NULL,0,0,358,346,SWP_NOMOVE);
	/*SetTimer(10,1000,NULL);
	m_wndstatusBar.Create(WS_CHILD|WS_VISIBLE|CCS_BOTTOM|CCS_NODIVIDER,
		CRect(0,0,0,0),this,102);
/*	m_wndstatusBar.SetParts(3,strParDim);
	m_wndstatusBar.SetText("Time con",1,0);
	m_wndstatusBar.SetText("Computer74",2,0);*/
	OnBegin();
	
	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CPictureGameDlg::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 CPictureGameDlg::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();
		SetImage();
	}
/*	if(pkDC)
		pkDC->DeleteDC();*/
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CPictureGameDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}
void CPictureGameDlg::OnRun(UINT nBitmapID,UINT nMenuID)
{
	pSubMenu=pMainMenu->GetSubMenu(1);
	pSubMenu->CheckMenuItem(ID_PICTURE1,MF_UNCHECKED);
	pSubMenu->CheckMenuItem(ID_PICTURE2,MF_UNCHECKED);
	pSubMenu->CheckMenuItem(ID_PICTURE3,MF_UNCHECKED);
	pSubMenu->CheckMenuItem(ID_PICTURE4,MF_UNCHECKED);
	pSubMenu->CheckMenuItem(nMenuID,MF_CHECKED);
	count=0;
	IsLong=FALSE;
	CanCount=FALSE;
	IsRnd=FALSE;
	Advan=FALSE;
    bitmap.DeleteObject();
	bitmap.LoadBitmap(nBitmapID);
	SetPos();
	SetImage();
	IsWin();
}

void CPictureGameDlg::OnPicture1() 
{
	OnRun(IDB_BITMAP1,ID_PICTURE1);
	// TODO: Add your command handler code here
	
}

void CPictureGameDlg::OnPicture2() 
{
	OnRun(IDB_BITMAP2,ID_PICTURE2);
	// TODO: Add your command handler code here
	
}

void CPictureGameDlg::OnPicture4() 
{
	OnRun(IDB_BITMAP4,ID_PICTURE4);
	// TODO: Add your command handler code here
	
}

void CPictureGameDlg::OnPicture3() 
{

	OnRun(IDB_BITMAP3,ID_PICTURE3);
}

void CPictureGameDlg::OnOwner() 
{
CFileDialog dlg(TRUE,NULL,NULL,NULL,"位图文件(*.bmp)|*.bmp");
				INT Result=dlg.DoModal();
				if(Result=IDOK)
				{
					count=0;
					CanCount=FALSE;
					IsRnd=FALSE;
					Advan=TRUE;
					hBitmap=(HBITMAP)::LoadImage(NULL,dlg.GetFileName(),IMAGE_BITMAP,
						0,0,LR_LOADFROMFILE);
					BITMAP bm;
					::GetObject(hBitmap,sizeof(BITMAP),&bm);
					if(bm.bmWidth>=bm.bmHeight)
					{
						hBitmap=(HBITMAP)::LoadImage(NULL,dlg.GetFileName(),
							IMAGE_BITMAP,350,280,LR_LOADFROMFILE);
						Width=350;Height=280;
						IsLong=FALSE;
					}
					else if(bm.bmWidth<=bm.bmHeight)
					{
						hBitmap=(HBITMAP)::LoadImage(NULL,dlg.GetFileName(),IMAGE_BITMAP,
							200,310,LR_LOADFROMFILE);
						Width=200;Height=280;
						IsLong=TRUE;
					}
				}
				else if(Result==IDCANCEL)
					return;

}

void CPictureGameDlg::OnEasy() 
{
	pSubMenu=pMainMenu->GetSubMenu(0);
	pSubMenu->CheckMenuItem(ID_HARD,MF_UNCHECKED);
	pSubMenu->CheckMenuItem(ID_EASY,MF_CHECKED);
	Easy=TRUE;IsRnd=FALSE;
	CanCount=FALSE;
	m_wndstatusBar.SetText("加油",0,0);
	// TODO: Add your command handler code here
	
}

void CPictureGameDlg::OnHard() 
{
	pSubMenu=pMainMenu->GetSubMenu(0);
	pSubMenu->CheckMenuItem(ID_EASY,MF_UNCHECKED);
	pSubMenu->CheckMenuItem(ID_HARD,MF_CHECKED);
	Easy=FALSE;IsRnd=FALSE;
	CanCount=FALSE;
	m_wndstatusBar.SetText("有点难吧,哈哈",0,0);
	// TODO: Add your command handler code here
	
}
void CPictureGameDlg::OnBegin()
{
	IsRnd=FALSE;
	CanCount=FALSE;
	count=0;
	SetPos();
	IsWin();
	m_wndstatusBar.SetText("加油",0,0);
}
UINT CPictureGameDlg::MapRand(UINT nMax)
{
	int nRand=rand();
	float fMap=(float)nMax/RAND_MAX;
	float fRetVal=(float)nRand*fMap+0.5f;
	return (UINT)fRetVal;
}
void CPictureGameDlg::Rnd()
{
	int xnum,ynum,level;
	UINT rand;
	if(Easy) level=8;
	else if(!Easy) level=15;
	WINDOWPLACEMENT wpnum,wp15;
	for(int a=0;a<=600;a++)
	{
		rand=MapRand(4);
		if(rand==1)
			for(int b=0;b<=level-1;b++)
			{
				m_Image[level].GetWindowPlacement(&wp15);
				m_Image[b].GetWindowPlacement(&wpnum);
				xnum=wpnum.rcNormalPosition.left;
				xnum=wpnum.rcNormalPosition.top;
				if(wpnum.rcNormalPosition.top==wp15.rcNormalPosition.top
					&&wpnum.rcNormalPosition.left==wp15.rcNormalPosition.left-x)
				{
					m_Image[b].SetWindowPos(NULL,xnum+x,ynum,0,0,SWP_NOSIZE);
					m_Image[level].SetWindowPos(NULL,xnum,ynum,0,0,SWP_NOSIZE);
				}
			}
			if(rand=2)
				for(int c=0;c<=level-1;c++)
				{
					m_Image[level].GetWindowPlacement(&wp15);
					m_Image[c].GetWindowPlacement(&wpnum);
					xnum=wpnum.rcNormalPosition.left;
					ynum=wpnum.rcNormalPosition.top;
					if(wpnum.rcNormalPosition.top==wp15.rcNormalPosition.top
						&&wpnum.rcNormalPosition.left==wp15.rcNormalPosition.left+x)
					{
						m_Image[c].SetWindowPos(NULL,xnum-x,ynum,0,0,SWP_NOSIZE);
						m_Image[level].SetWindowPos(NULL,xnum,
							ynum,0,0,SWP_NOSIZE);
					}
				}
				if(rand=3)
				for(int d=0;d<=level-1;d++)
				{
					m_Image[level].GetWindowPlacement(&wp15);
					m_Image[d].GetWindowPlacement(&wpnum);
					xnum=wpnum.rcNormalPosition.left;
					ynum=wpnum.rcNormalPosition.top;
					if(wpnum.rcNormalPosition.left==wp15.rcNormalPosition.left
						&&wpnum.rcNormalPosition.top==wp15.rcNormalPosition.top+y)
					{
						m_Image[d].SetWindowPos(NULL,xnum,ynum-y,0,0,SWP_NOSIZE);
						m_Image[level].SetWindowPos(NULL,xnum,ynum,0,0,SWP_NOSIZE);
					}
				}
				if(rand==4)
					for(int e=0;e<=level-1;e++)
					{
						m_Image[level].GetWindowPlacement(&wp15);
						m_Image[e].GetWindowPlacement(&wpnum);
						xnum=wpnum.rcNormalPosition.left;
						ynum=wpnum.rcNormalPosition.top;
						if(wpnum.rcNormalPosition.left==wp15.rcNormalPosition.left
							&&wpnum.rcNormalPosition.top==wp15.rcNormalPosition.top-y)
						{
							m_Image[e].SetWindowPos(NULL,xnum,ynum+y,0,0,SWP_NOSIZE);
							m_Image[level].SetWindowPos(NULL,xnum,ynum,0,0,SWP_NOSIZE);
						}
					}
		}
		if(Easy)m_Image[8].ShowWindow(SW_HIDE);
		else if(!Easy)
		{
			m_Image[8].ShowWindow(SW_SHOW);
			m_Image[15].ShowWindow(SW_HIDE);
		}
		pSubMenu=pMainMenu->GetSubMenu(0);
		pSubMenu->EnableMenuItem(ID_HELP,MF_ENABLED);
		IsRnd=TRUE;
		CanCount=TRUE;
	}
	void CPictureGameDlg::SetPos()
	{
		BITMAP bm;
		INT con,move;
		if(Advan==FALSE)
		{
			bitmap.GetObject(sizeof(BITMAP),&bm);
			Width=bm.bmHeight; Height=bm.bmHeight;
		}
		if(Easy)
		{
			x=Width/3;Height=Height/3;con=2;
		}
		else if(!Easy)
		{
			x=Width/4;y=Height/4;con=3;
		}
		if(IsLong) move=70;
		else
			move=0;
		for(int i=0;i<=con;i++)
		{
			m_Image[i].SetWindowPos(NULL,x*i+move,0,0,0,SWP_NOMOVE);
		}
		for(int j=0;j<=con;j++)
		{
			m_Image[con+1+j].SetWindowPos(NULL,x*j+move,y,0,0,SWP_NOSIZE);
			m_Image[con+1+j].SetWindowPos(NULL,0,0,x,y,SWP_NOMOVE);
		}
		for(int k=0;k<=con;k++)
		{
			m_Image[(con+1)*2+k].SetWindowPos(NULL,x*k+move,2*y,0,0,SWP_NOSIZE);
			m_Image[(con+1)*2+k].SetWindowPos(NULL,0,0,x,y,SWP_NOMOVE);
		}
		if(!Easy)
			for(int l=0;l<=3;l++)
			{
				m_Image[l+12].SetWindowPos(NULL,x*l+move,3*y,0,0,SWP_NOSIZE);
				m_Image[l+12].SetWindowPos(NULL,0,0,x,y,SWP_NOMOVE);
				CClientDC dc(&m_Image[l+12]);
			}
	}
	void CPictureGameDlg::SetImage()
	{
		INT con;
		HANDLE picture;
		CRect rect(0,0,x,y);
		if(Advan==TRUE)
			picture=hBitmap;
		else if(Advan==FALSE)
			picture=bitmap;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -