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

📄 xingyu~1.cpp

📁 用VC++编制的一款幸运52小游戏
💻 CPP
字号:
// XingyunDlg.cpp : implementation file
//

#include "stdafx.h"
#include "Xingyun.h"
#include "XingyunDlg.h"

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

/////////////////////////////////////////////////////////////////////////////
// CXingyunDlg dialog

CXingyunDlg::CXingyunDlg(CWnd* pParent /*=NULL*/)
	: CDialog(CXingyunDlg::IDD, pParent)
{
  cmmdty[0]="康佳29寸纯平彩电";
  cmmdty[1]="松下掌上电脑";
  cmmdty[2]="JNC MP3播放器891";
  cmmdty[3]="捷视可视电话机2000T";
  cmmdty[4]="索尼随身听EX2000 ";
  cmmdty[5]="索尼数码相机DSC-P1";
  cmmdty[6]="松下剃须刀ES365A";
  cmmdty[7]="日本ESP电吉它";
  cmmdty[8]="Nokiya 8210手机";
  cmmdty[9]="奔驰500";

  price[0]=4390;
  price[1]=5230;
  price[2]=2079;
  price[3]=5380;
  price[4]=1224;
  price[5]=7140;
  price[6]=273;
  price[7]=5230;
  price[8]=2810;
  price[9]=120000;

  CurrentCommodityIndex=1;

  Bitmap[0].LoadBitmap(IDB_BITMAP10);
  Bitmap[1].LoadBitmap(IDB_BITMAP3);
  Bitmap[2].LoadBitmap(IDB_BITMAP9);
  Bitmap[3].LoadBitmap(IDB_BITMAP8);
  Bitmap[4].LoadBitmap(IDB_BITMAP1);
  Bitmap[5].LoadBitmap(IDB_BITMAP11);
  Bitmap[6].LoadBitmap(IDB_BITMAP7);
  Bitmap[7].LoadBitmap(IDB_BITMAP4);
  Bitmap[8].LoadBitmap(IDB_BITMAP6);
  Bitmap[9].LoadBitmap(IDB_BITMAP2);


	//{{AFX_DATA_INIT(CXingyunDlg)
	m_STATIC1 = "商品";
	m_EDIT1 = 0;
	//}}AFX_DATA_INIT
	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
}

void CXingyunDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CXingyunDlg)
	DDX_Control(pDX, IDC_PICTURE, m_Pic_Control);
	DDX_Control(pDX, IDOK, m_OK);
	DDX_Control(pDX, IDCANCEL, m_CANCEL);
	DDX_Control(pDX, IDC_BUTTON1, m_BUTTON1);
	DDX_Text(pDX, IDC_STATIC1, m_STATIC1);
	DDX_Text(pDX, IDC_EDIT1, m_EDIT1);
	//}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CXingyunDlg, CDialog)
	//{{AFX_MSG_MAP(CXingyunDlg)
	ON_WM_PAINT()
	ON_WM_QUERYDRAGICON()
	ON_BN_CLICKED(IDC_BUTTON1, OnButton1)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CXingyunDlg message handlers

BOOL CXingyunDlg::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
	
	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 CXingyunDlg::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 CXingyunDlg::OnQueryDragIcon()
{
	return (HCURSOR) m_hIcon;
}

void CXingyunDlg::OnButton1() 
{
	// TODO: Add your control notification handler code here
  m_EDIT1=0;    //清空Edit1
  srand(time(NULL));
  CurrentCommodityIndex=rand()%10;
  m_STATIC1.Format("%s",cmmdty[CurrentCommodityIndex]);
 
  UpdateData(FALSE);
	
   if(CurrentCommodityIndex==0)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[0]) );
 else if(CurrentCommodityIndex==1)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[1]) );
 else if(CurrentCommodityIndex==2)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[2]) );
 else if(CurrentCommodityIndex==3)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[3]) );
 else if(CurrentCommodityIndex==4)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[4]) );
 else if(CurrentCommodityIndex==5)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[5]) );
 else if(CurrentCommodityIndex==6)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[6]) );
 else if(CurrentCommodityIndex==7)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[7]) );
 else if(CurrentCommodityIndex==8)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[8]) );
 else if(CurrentCommodityIndex==9)
   ((CStatic *)GetDlgItem(IDC_PICTURE))->SetBitmap(HBITMAP(  Bitmap[9]) );


}

void CXingyunDlg::OnOK() 
{
	// TODO: Add extra validation here
	UpdateData();
   int priceTemp=m_EDIT1;
	if(priceTemp>price[CurrentCommodityIndex])
   {
    MessageBox("您想用这么多的钱买这个破东西?高了高了!!","猜错了",MB_OK);

   }
 else if(priceTemp<price[CurrentCommodityIndex])
   {
    MessageBox("您想用这么少的钱买这个好东西?低了低了!!","猜错了",MB_OK);
 
   }
 else
   {
    MessageBox("恭喜恭喜!!","猜对了",MB_OK);
   
   }

}

⌨️ 快捷键说明

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