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

📄 childview.cpp

📁 對話方塊
💻 CPP
字号:
// ChildView.cpp : implementation of the CChildView class
//

#include "stdafx.h"
#include "Ex10d.h"
#include "ChildView.h"

#include "GetStuInfo.h"

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

/////////////////////////////////////////////////////////////////////////////
// CChildView

CChildView::CChildView()
{
}

CChildView::~CChildView()
{
}


BEGIN_MESSAGE_MAP(CChildView,CWnd )
	//{{AFX_MSG_MAP(CChildView)
	ON_WM_PAINT()
	ON_COMMAND(ID_GETINFO, OnGetInfo)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()


/////////////////////////////////////////////////////////////////////////////
// CChildView message handlers

BOOL CChildView::PreCreateWindow(CREATESTRUCT& cs) 
{
	if (!CWnd::PreCreateWindow(cs))
		return FALSE;

	cs.dwExStyle |= WS_EX_CLIENTEDGE;
	cs.style &= ~WS_BORDER;
	cs.lpszClass = AfxRegisterWndClass(CS_HREDRAW|CS_VREDRAW|CS_DBLCLKS, 
		::LoadCursor(NULL, IDC_ARROW), HBRUSH(COLOR_WINDOW+1), NULL);

	return TRUE;
}

void CChildView::OnPaint() 
{
	CPaintDC dc(this); // device context for painting
	
	// TODO: Add your message handler code here
	
	// Do not call CWnd::OnPaint() for painting messages
}


void CChildView::OnGetInfo() 
{
  CClientDC  dc(this);
  
  CString  name;
  int      age;
  char     gender;
  BOOL     tuitionPaid;
  int      stuStatus; // 0=under,1=grad,2=special

  CGetStuInfo Dlg(this);   // Ex_Step 1:
  Dlg.m_name        = "x"; // Ex_Step 3:
  Dlg.m_age         = 20;  // Init dialog
  Dlg.m_gender      = -1;  // variables
  Dlg.m_tuitionPaid = TRUE;
  Dlg.m_stuStatus   = 0;
                           // Ex_Step 4: Invoke dialog
  if (Dlg.DoModal() == IDOK)
  {                        // Ex_Step 7: Test return val 
    name = Dlg.m_name;     // Ex_Step 8:
    age = Dlg.m_age;       // Retrieve values
    if (Dlg.m_gender == 0) // from dialog box
      gender = 'M';     
    else
      gender = 'F';
    stuStatus = Dlg.m_stuStatus;
    tuitionPaid  = Dlg.m_tuitionPaid;

    CString s;
    if (tuitionPaid)
      s.Format ("Name:%s  Age:%d  Gender:%c   PAID",
                 name, age, gender);
    else
      s.Format ("Name:%s  Age:%d  Gender:%c   NOT PAID",
                 name, age, gender);
    dc.TextOut (10,10, s);
  }
  else
    dc.TextOut (10,10,"Cancel pressed");
}

⌨️ 快捷键说明

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