东软总结04-对话框01

打开资源视图,在Dialog右键插入

 

// Dialog2View.cpp : implementation of the CDialog2View class
//

#include "stdafx.h"
#include "Dialog2.h"

#include "Dialog2Doc.h"
#include "Dialog2View.h"
#include "MyDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialog2View

IMPLEMENT_DYNCREATE(CDialog2View, CView)

BEGIN_MESSAGE_MAP(CDialog2View, CView)
	//{{AFX_MSG_MAP(CDialog2View)
	ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialog2View construction/destruction

CDialog2View::CDialog2View()
{
	// TODO: add construction code here

}

CDialog2View::~CDialog2View()
{
}

BOOL CDialog2View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDialog2View drawing

void CDialog2View::OnDraw(CDC* pDC)
{
	CDialog2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	pDC->TextOut(20, 20, strName);
}

/////////////////////////////////////////////////////////////////////////////
// CDialog2View printing

BOOL CDialog2View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDialog2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CDialog2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDialog2View diagnostics

#ifdef _DEBUG
void CDialog2View::AssertValid() const
{
	CView::AssertValid();
}

void CDialog2View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CDialog2Doc* CDialog2View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDialog2Doc)));
	return (CDialog2Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDialog2View message handlers

void CDialog2View::OnMenuitem32771() 
{
	// TODO: Add your command handler code here
	MyDialog my;
	my.DoModal();

	if (my.DoModal() == IDOK)
	{
//		MessageBox(my.m_strName);
		strName = my.m_strName;
		Invalidate();
	}
}

 

用control时,绑定控件类型,只能在MyDialog类内使用,添加一个中间变量strID。

// Dialog2View.cpp : implementation of the CDialog2View class
//

#include "stdafx.h"
#include "Dialog2.h"

#include "Dialog2Doc.h"
#include "Dialog2View.h"
#include "MyDialog.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CDialog2View

IMPLEMENT_DYNCREATE(CDialog2View, CView)

BEGIN_MESSAGE_MAP(CDialog2View, CView)
	//{{AFX_MSG_MAP(CDialog2View)
	ON_COMMAND(ID_MENUITEM32771, OnMenuitem32771)
	//}}AFX_MSG_MAP
	// Standard printing commands
	ON_COMMAND(ID_FILE_PRINT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_DIRECT, CView::OnFilePrint)
	ON_COMMAND(ID_FILE_PRINT_PREVIEW, CView::OnFilePrintPreview)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDialog2View construction/destruction

CDialog2View::CDialog2View()
{
	// TODO: add construction code here

}

CDialog2View::~CDialog2View()
{
}

BOOL CDialog2View::PreCreateWindow(CREATESTRUCT& cs)
{
	// TODO: Modify the Window class or styles here by modifying
	//  the CREATESTRUCT cs

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDialog2View drawing

void CDialog2View::OnDraw(CDC* pDC)
{
	CDialog2Doc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
	pDC->TextOut(20, 20, strName);
}

/////////////////////////////////////////////////////////////////////////////
// CDialog2View printing

BOOL CDialog2View::OnPreparePrinting(CPrintInfo* pInfo)
{
	// default preparation
	return DoPreparePrinting(pInfo);
}

void CDialog2View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add extra initialization before printing
}

void CDialog2View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
	// TODO: add cleanup after printing
}

/////////////////////////////////////////////////////////////////////////////
// CDialog2View diagnostics

#ifdef _DEBUG
void CDialog2View::AssertValid() const
{
	CView::AssertValid();
}

void CDialog2View::Dump(CDumpContext& dc) const
{
	CView::Dump(dc);
}

CDialog2Doc* CDialog2View::GetDocument() // non-debug version is inline
{
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CDialog2Doc)));
	return (CDialog2Doc*)m_pDocument;
}
#endif //_DEBUG

/////////////////////////////////////////////////////////////////////////////
// CDialog2View message handlers

void CDialog2View::OnMenuitem32771() 
{
	// TODO: Add your command handler code here
	MyDialog my;
	my.DoModal();

//	if (my.DoModal() == IDOK)
	{
//		MessageBox(my.m_strName);
		strName = my.m_strName + " " + my.strID;
		Invalidate();
	}
}

你可能感兴趣的:(东软总结04-对话框01)