zhanjunlihai 2021-04-13 13:51 采纳率: 25%
浏览 38
已结题

猜数字游戏,当填入大于999的数字时,弹出对话框,这个程序代码我怎么也找不到在哪里写的。。。

  1. // guess_numberDlg.cpp : implementation file
    //
    
    #include "stdafx.h"
    #include "guess_number.h"
    #include "guess_numberDlg.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()
    
    /////////////////////////////////////////////////////////////////////////////
    // CGuess_numberDlg dialog
    
    CGuess_numberDlg::CGuess_numberDlg(CWnd* pParent /*=NULL*/)
    	: CDialog(CGuess_numberDlg::IDD, pParent)
    {
    	//{{AFX_DATA_INIT(CGuess_numberDlg)
    	m_list = _T("");
    	m_num = 0;
    	//}}AFX_DATA_INIT
    	// Note that LoadIcon does not require a subsequent DestroyIcon in Win32
    	m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
    }
    
    void CGuess_numberDlg::DoDataExchange(CDataExchange* pDX)
    {
    	CDialog::DoDataExchange(pDX);
    	//{{AFX_DATA_MAP(CGuess_numberDlg)
    	DDX_Control(pDX, ID_Start, m_start);
    	DDX_Text(pDX, IDC_List, m_list);
    	DDX_Text(pDX, IDC_InputNum, m_num);
    	DDV_MinMaxInt(pDX, m_num, 0, 999);
    	//}}AFX_DATA_MAP
    }
    
    BEGIN_MESSAGE_MAP(CGuess_numberDlg, CDialog)
    	//{{AFX_MSG_MAP(CGuess_numberDlg)
    	ON_WM_SYSCOMMAND()
    	ON_WM_PAINT()
    	ON_WM_QUERYDRAGICON()
    	ON_BN_CLICKED(IDC_Guess, OnGuess)
    	ON_BN_CLICKED(IDC_See, OnSee)
    	ON_BN_CLICKED(ID_Start, OnStart)
    	//}}AFX_MSG_MAP
    END_MESSAGE_MAP()
    
    /////////////////////////////////////////////////////////////////////////////
    // CGuess_numberDlg message handlers
    
    BOOL CGuess_numberDlg::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
    	
    	return TRUE;  // return TRUE  unless you set the focus to a control
    }
    
    void CGuess_numberDlg::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 CGuess_numberDlg::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 CGuess_numberDlg::OnQueryDragIcon()
    {
    	return (HCURSOR) m_hIcon;
    }
    
    
    void CGuess_numberDlg::OnGuess() 
    {
    	// TODO: Add your control notification handler code here
    	UpdateData(true);
    	CString str;
    	if(m_num>rnd)
    		str="太大了";
    	else if(m_num<rnd)
    		str="太小了";
    	else 
    		{str="恭喜猜中";
    			m_start.EnableWindow(true);}
    	m_list=m_list+str+"\r\n";
        UpdateData(false); 
    }
    
    void CGuess_numberDlg::OnSee() 
    {
    	// TODO: Add your control notification handler code here
       CString str;
       str.Format("随机数:%d",rnd);
       MessageBox(str);
    }
    
    
    void CGuess_numberDlg::OnStart() 
    {
    	// TODO: Add your control notification handler code here
       srand(time(NULL));
       rnd=rand()%1000;
       m_start.EnableWindow(false);
       m_list="";
       m_num=0;
       UpdateData(false);
    }
    

     

  • 写回答

1条回答 默认 最新

  • _mervyn 2021-04-13 15:34
    关注

    183行UpdateData(true); 会触发73行DoDataExchange函数,在DoDataExchange中DDV_MinMaxInt(pDX, m_num, 0, 999);验证数据有效性时会弹出提示框。   如果你不想要这个提示框,可以不使用DDV_MinMaxInt,而是写自己的验证逻辑。

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 10月24日
  • 已采纳回答 10月24日

悬赏问题

  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误