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

📄 pukeadddlg.cpp

📁 MFC做的随机选取4张牌求和,很简单,没难度,纯属娱乐!
💻 CPP
字号:
// PuKeAddDlg.cpp : implementation file
//

#include "stdafx.h"
#include "PuKeAdd.h"
#include "PuKeAddDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CPuKeAddDlg dialog

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

void CPuKeAddDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CPuKeAddDlg)
	DDX_Control(pDX, IDC_STATIC4, m_Static4);
	DDX_Control(pDX, IDC_STATIC3, m_Static3);
	DDX_Control(pDX, IDC_STATIC2, m_Static2);
	DDX_Control(pDX, IDC_STATIC1, m_Static1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CPuKeAddDlg, CDialog)
	//{{AFX_MSG_MAP(CPuKeAddDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON_RESET, OnButtonReset)
	ON_BN_CLICKED(IDC_BUTTON_RESULT1, OnButtonResult1)
	ON_BN_CLICKED(IDC_BUTTON_RESULT2, OnButtonResult2)
	ON_BN_CLICKED(IDC_BUTTON_RESULT3, OnButtonResult3)
	ON_BN_CLICKED(IDC_BUTTON_RESULT4, OnButtonResult4)
	ON_BN_CLICKED(IDC_BUTTON_RESULT5, OnButtonResult5)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CPuKeAddDlg message handlers

BOOL CPuKeAddDlg::OnInitDialog()
{
	CDialog::OnInitDialog();

	// 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
	
	GetDlgItem(IDC_BUTTON_RESET)->SetWindowText("start");
	return TRUE;  // return TRUE  unless you set the focus to a control
}

// 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 CPuKeAddDlg::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();
	}
}

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

void CPuKeAddDlg::OnButtonReset() 
{
	// TODO: Add your control notification handler code here
	GetDlgItem(IDC_BUTTON_RESET)->SetWindowText("reset");
	m_Add = AddResult();
	SetInt();
	PutIntOnButton();
	GetDlgItem(IDC_STATIC_RESULT)->SetWindowText("WAIT......");
}

int CPuKeAddDlg::AddResult()
{
	srand(time(0));
	int ia = (rand()%31)%13+1;
	int ib = (rand()%32)%13+1;
	int ic = (rand()%33)%13+1;
	int id = (rand()%34)%13+1;
	m_Static1.SetBitmap(::LoadBitmap(AfxGetResourceHandle(),MAKEINTRESOURCE(LPCTSTR(ia+128))));
	m_Static2.SetBitmap(::LoadBitmap(AfxGetResourceHandle(),MAKEINTRESOURCE(LPCTSTR(ib+128))));
	m_Static3.SetBitmap(::LoadBitmap(AfxGetResourceHandle(),MAKEINTRESOURCE(LPCTSTR(ic+128))));
	m_Static4.SetBitmap(::LoadBitmap(AfxGetResourceHandle(),MAKEINTRESOURCE(LPCTSTR(id+128))));
	int result = ia+ib+ic+id;
	return result;
}

void CPuKeAddDlg::SetInt()
{
	srand(time(0));
	int itemp = rand()%5+1;
	if (itemp == 1)
	{
		result1 = m_Add;
		result2 = m_Add + 1;
		result3 = m_Add + 2;
		result4 = m_Add + 3;
		result5 = m_Add + 4;
	} 
	else
	{
		if (itemp == 2)
		{
			result1 = m_Add - 1;
			result2 = m_Add;
			result3 = m_Add + 1;
			result4 = m_Add + 2;
			result5 = m_Add + 3;	
		} 
		else
		{
			if (itemp == 3)
			{
				result1 = m_Add - 2;
				result2 = m_Add - 1;
				result3 = m_Add;
				result4 = m_Add + 1;
				result5 = m_Add + 2;
			} 
			else
			{
				if (itemp == 4)
				{
					result1 = m_Add - 3;
					result2 = m_Add - 2;
					result3 = m_Add - 1;
					result4 = m_Add;
					result5 = m_Add + 1;
				} 
				else
				{
					result1 = m_Add - 4;
					result2 = m_Add - 3;
					result3 = m_Add - 2;
					result4 = m_Add - 1;
					result5 = m_Add;
				}
			}
		}
	}
}

void CPuKeAddDlg::ResultMessage(int id)
{
	if (id == m_Add)
		GetDlgItem(IDC_STATIC_RESULT)->SetWindowText("RIGHT!");
	else
		GetDlgItem(IDC_STATIC_RESULT)->SetWindowText("WRONG!");
}

void CPuKeAddDlg::OnButtonResult1() 
{
	// TODO: Add your control notification handler code here
	CString cs_GetAdd;
	GetDlgItem(IDC_BUTTON_RESULT1)->GetWindowText(cs_GetAdd);
	int id = atoi(cs_GetAdd);
	ResultMessage(id);
}

void CPuKeAddDlg::OnButtonResult2() 
{
	// TODO: Add your control notification handler code here
	CString cs_GetAdd;
	GetDlgItem(IDC_BUTTON_RESULT2)->GetWindowText(cs_GetAdd);
	int id = atoi(cs_GetAdd);
	ResultMessage(id);
}

void CPuKeAddDlg::OnButtonResult3() 
{
	// TODO: Add your control notification handler code here
	CString cs_GetAdd;
	GetDlgItem(IDC_BUTTON_RESULT3)->GetWindowText(cs_GetAdd);
	int id = atoi(cs_GetAdd);
	ResultMessage(id);
}

void CPuKeAddDlg::OnButtonResult4() 
{
	// TODO: Add your control notification handler code here
	CString cs_GetAdd;
	GetDlgItem(IDC_BUTTON_RESULT4)->GetWindowText(cs_GetAdd);
	int id = atoi(cs_GetAdd);
	ResultMessage(id);
}

void CPuKeAddDlg::OnButtonResult5() 
{
	// TODO: Add your control notification handler code here
	CString cs_GetAdd;
	GetDlgItem(IDC_BUTTON_RESULT5)->GetWindowText(cs_GetAdd);
	int id = atoi(cs_GetAdd);
	ResultMessage(id);
}

void CPuKeAddDlg::PutIntOnButton()
{
	char *Text1,*Text2,*Text3,*Text4,*Text5;
	Text1 = new char[10];
	Text2 = new char[10];
	Text3 = new char[10];
	Text4 = new char[10];
	Text5 = new char[10];
	memset(Text1,0,10);
	memset(Text2,0,10);
	memset(Text3,0,10);
	memset(Text4,0,10);
	memset(Text5,0,10);
	itoa(result1,Text1,10);
	itoa(result2,Text2,10);
	itoa(result3,Text3,10);
	itoa(result4,Text4,10);
	itoa(result5,Text5,10);
	GetDlgItem(IDC_BUTTON_RESULT1)->SetWindowText(Text1);
	GetDlgItem(IDC_BUTTON_RESULT2)->SetWindowText(Text2);
	GetDlgItem(IDC_BUTTON_RESULT3)->SetWindowText(Text3);
	GetDlgItem(IDC_BUTTON_RESULT4)->SetWindowText(Text4);
	GetDlgItem(IDC_BUTTON_RESULT5)->SetWindowText(Text5);
	delete Text1;
	delete Text2;
	delete Text3;
	delete Text4;
	delete Text5;
}

⌨️ 快捷键说明

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