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

📄 magicdlg.cpp

📁 本人自己写的一个游戏源代码:神奇读心术!
💻 CPP
字号:
// magicDlg.cpp : implementation file
//

#include "stdafx.h"
#include "magic.h"
#include "magicDlg.h"
#include "Result.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About
#include "StarWarsCtrl.h"
#include "HyperlinkStatic.h"

class CAboutDlg : public CDialog
{
public:
	CAboutDlg();
// Dialog Data
	//{{AFX_DATA(CAboutDlg)
	enum { IDD = IDD_ABOUTBOX };
	CHyperlinkStatic	m_web;
	CStarWarsCtrl	m_star;
	//}}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)
	m_web.SetHyperlink("www.gamedevelop.net");
	m_star.SetScrollSpeed(1);
	m_star.AddTextLine("谢谢您使用本程序");
	m_star.AddTextLine("");
	m_star.AddTextLine("程序开发:@J--S Studio");
	m_star.AddTextLine("");
	m_star.AddTextLine("作者:Johnhans");
	m_star.AddTextLine("");
	m_star.AddTextLine("欢迎访问中国游戏开发技术资讯网");
	m_star.AddTextLine("www.gamedevelop.net");
	m_star.AddTextLine("");
	m_star.AddTextLine("欢迎访问中国游戏开发技术资讯社区");
	m_star.AddTextLine("bbs.gamedevelop.net");
	//}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CAboutDlg)
	DDX_Control(pDX, IDC_WEB, m_web);
	DDX_Control(pDX, IDC_STAR, m_star);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
	//{{AFX_MSG_MAP(CAboutDlg)
		// No message handlers
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMagicDlg dialog

CMagicDlg::CMagicDlg(CWnd* pParent /*=NULL*/)
: CDialog(CMagicDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CMagicDlg)
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_Key=-1;
	m_State=0;
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CMagicDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CMagicDlg)
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CMagicDlg, CDialog)
	//{{AFX_MSG_MAP(CMagicDlg)
	ON_WM_SYSCOMMAND()
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_WM_TIMER()
	ON_WM_DESTROY()
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CMagicDlg message handlers

BOOL CMagicDlg::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

	srand(GetTickCount());
	m_Key=-rand()%25-1;
	SetTimer(7,100,NULL);
	// TODO: Add extra initialization here

	return TRUE;  // return TRUE  unless you set the focus to a control
}

void CMagicDlg::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 CMagicDlg::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
	{
		dc.SetBkMode(TRANSPARENT);
//		dc.SetTextColor(RGB(0,0,255));
		CBrush b;
		b.CreateSolidBrush(RGB(100,0,0));
		CRect rect;
		GetWindowRect(rect);
		int height=rect.Height();
		rect.top=0;
		POINT pt;
		rect.bottom=height;

		// draw background
		for(int i=0;i<10;i++)
		{
			rect.left=60*i;
			rect.right=rect.left+30;
			dc.FillRect(rect,&b);
		}

		// draw grid
		for(i=0;i<=10;i++)	// draw horizontal lines
		{
			pt.x=20*30;pt.y=30*i;
			dc.MoveTo(0,30*i);dc.LineTo(pt);
		}
		for(i=0;i<=20;i++)	// draw vertical lines
		{
			pt.x=30*i;pt.y=0;
			dc.MoveTo(30*i,height);dc.LineTo(pt);
		}

		LOGFONT lf;
		ZeroMemory(&lf,sizeof(lf));
		lstrcpy(lf.lfFaceName,"宋体");
		CFont f;
		f.CreateFontIndirect(&lf);
		CFont *old = (CFont*)dc.SelectObject(f);
		CString num;
		int val=0;
		for(i=0;i<100;i++)
		{
			val=99-i;
			num.Format("%d",val);
			pt.x=(i%10)*60;pt.y=(i/10)*30;
			dc.SetTextColor(RGB(255,255,0));
			dc.TextOut(pt.x+(pt.y==270?11:7),pt.y+7,num);
			dc.SetTextColor(RGB(0,0,0));
			dc.TextOut(pt.x+37,pt.y+7,(m_Key<0 || (val<82 && val%9==0))?(Alphabet[abs(m_Key)]):Alphabet[rand()%26]);
		}
		DeleteObject(old);
	}
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CMagicDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CMagicDlg::OnTimer(UINT nIDEvent) 
{
	// TODO: Add your message handler code here and/or call default
	if(nIDEvent==7)
	{
		KillTimer(7);
		CString ques;
		const char title[]="神奇读心术";
		switch(m_State)
		{
		case 0:
			m_Key=-rand()%25-1;
			Invalidate(true);
			ques.LoadString(IDS_QUES1);
			if(MessageBox(ques,title,MB_YESNO|MB_ICONQUESTION)==IDYES)
			{
				m_State=1;
				SetTimer(7,100,NULL);
			}
			else
				OnOK();
			break;
		case 1:
			ques.LoadString(IDS_QUES2);
			if(MessageBox(ques,title,MB_YESNO|MB_ICONQUESTION)==IDYES)
				m_State=2;
			else
				m_State=0;
			SetTimer(7,100,NULL);
			break;
		case 2:
			ques.LoadString(IDS_QUES3);
			if(MessageBox(ques,title,MB_YESNO|MB_ICONQUESTION)==IDYES)
				m_State=3;
			else
				m_State=1;
			SetTimer(7,100,NULL);
			break;
		case 3:
			ques.LoadString(IDS_QUES4);
			if(MessageBox(ques,title,MB_YESNO|MB_ICONQUESTION)==IDYES)
			{
				m_State=4;
				SetTimer(7,10000,NULL);
				m_Key=rand()%26;
				Invalidate(true);
			}
			else
			{
				m_State=2;
				SetTimer(7,100,NULL);
			}
			break;
		case 4:
			CResult r;
			r.m_Result=Alphabet[m_Key];
			if(r.DoModal()==IDOK)
			{
				m_State=0;
				SetTimer(7,100,NULL);
			}
			else
				OnOK();
			break;
		}
	}
	CDialog::OnTimer(nIDEvent);
}

void CMagicDlg::OnDestroy() 
{
	// TODO: Add your message handler code here
	CAboutDlg a;
	a.DoModal();
	CDialog::OnDestroy();
}

⌨️ 快捷键说明

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