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

📄 dlgdemoview.cpp

📁 VC++6开发指南的源代码第7章-第11章
💻 CPP
字号:
// DlgDemoView.cpp : implementation of the CDlgDemoView class
//

#include "stdafx.h"
#include "DlgDemo.h"

#include "DlgDemoDoc.h"
#include "DlgDemoView.h"
#include "MyDialog.h"

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

/////////////////////////////////////////////////////////////////////////////
// CDlgDemoView

IMPLEMENT_DYNCREATE(CDlgDemoView, CView)

BEGIN_MESSAGE_MAP(CDlgDemoView, CView)
	//{{AFX_MSG_MAP(CDlgDemoView)
	ON_COMMAND(ID_CREATEDLG, OnCreatedlg)
	ON_COMMAND(ID_CREATEDLG2, OnCreatedlg2)
	//}}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()

/////////////////////////////////////////////////////////////////////////////
// CDlgDemoView construction/destruction

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

}

CDlgDemoView::~CDlgDemoView()
{
}

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

	return CView::PreCreateWindow(cs);
}

/////////////////////////////////////////////////////////////////////////////
// CDlgDemoView drawing

void CDlgDemoView::OnDraw(CDC* pDC)
{
	CDlgDemoDoc* pDoc = GetDocument();
	ASSERT_VALID(pDoc);
	// TODO: add draw code for native data here
}

/////////////////////////////////////////////////////////////////////////////
// CDlgDemoView printing

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDlgDemoView diagnostics

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

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

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

/////////////////////////////////////////////////////////////////////////////
// CDlgDemoView message handlers

void CDlgDemoView::OnCreatedlg() 
{
	MyDialog dlg;//创建对话框类实例
	int nRet=dlg.DoModal();//显示对话框	
	CString szOut;
	szOut.Format("模态对话框的返回值为 %d",nRet);
	CClientDC dc(this);
	dc.TextOut(30,30,szOut);
}


void CDlgDemoView::OnCreatedlg2() 
{
	// TODO: Add your command handler code here
	MyDialog* pDialog;									//对话框类对象指针 
	pDialog = new MyDialog();							
   //Check if new succeeded and we got a valid pointer to a dialog object
   if(pDialog != NULL)
   {
	  BOOL ret = pDialog->Create(IDD_DIALOG1,this);	//创建非模态对话框
      if(!ret)   //创建失败
      AfxMessageBox("Error creating Dialog");
	  CRect clientRect,dlgRect;
	  GetClientRect(&clientRect);//获取客户区窗口大小
	  ClientToScreen(clientRect);//转换为屏幕坐标
	  pDialog->GetWindowRect(&dlgRect);//获取对话框窗口大小
	  pDialog->MoveWindow(clientRect.left+30, clientRect.top+50,dlgRect.Width(),dlgRect.Height());//移动对话框窗口
      pDialog->ShowWindow(SW_SHOW);				//显示对话框
	  CClientDC dc(this);
	  dc.TextOut(30,30,"成功创建非模态对话框!");//客户区显示提示信息
   }
   else
      AfxMessageBox("Error Creating Dialog Object");
}

	

⌨️ 快捷键说明

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