ex18view.cpp
来自「一些VC++的经典实例」· C++ 代码 · 共 143 行
CPP
143 行
// ex18View.cpp : implementation of the CEx18View class
//
#include "stdafx.h"
#include "ex18.h"
#include "ex18Doc.h"
#include "ex18View.h"
#include "ModellessDlg.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
/////////////////////////////////////////////////////////////////////////////
// CEx18View
IMPLEMENT_DYNCREATE(CEx18View, CView)
BEGIN_MESSAGE_MAP(CEx18View, CView)
ON_MESSAGE(WM_GOODBYE, OnGoodbye)
//{{AFX_MSG_MAP(CEx18View)
ON_WM_LBUTTONDOWN()
ON_WM_RBUTTONDOWN()
ON_WM_KEYDOWN()
//}}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()
/////////////////////////////////////////////////////////////////////////////
// CEx18View construction/destruction
CEx18View::CEx18View()
{
// TODO: add construction code here
m_pDlg = new CModellessDlg(this);
}
CEx18View::~CEx18View()
{
delete m_pDlg;
}
BOOL CEx18View::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
return CView::PreCreateWindow(cs);
}
/////////////////////////////////////////////////////////////////////////////
// CEx18View drawing
void CEx18View::OnDraw(CDC* pDC)
{
CEx18Doc* pDoc = GetDocument();
ASSERT_VALID(pDoc);
// TODO: add draw code for native data here
pDC->TextOut(0,0,"请在窗口内点击鼠标左键生成非模式对话框!点击右键关闭非模式对话框!");
pDC->TextOut(0,50,"按下任何非系统键出现模式对话框!");
}
/////////////////////////////////////////////////////////////////////////////
// CEx18View printing
BOOL CEx18View::OnPreparePrinting(CPrintInfo* pInfo)
{
// default preparation
return DoPreparePrinting(pInfo);
}
void CEx18View::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add extra initialization before printing
}
void CEx18View::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/)
{
// TODO: add cleanup after printing
}
/////////////////////////////////////////////////////////////////////////////
// CEx18View diagnostics
#ifdef _DEBUG
void CEx18View::AssertValid() const
{
CView::AssertValid();
}
void CEx18View::Dump(CDumpContext& dc) const
{
CView::Dump(dc);
}
CEx18Doc* CEx18View::GetDocument() // non-debug version is inline
{
ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CEx18Doc)));
return (CEx18Doc*)m_pDocument;
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CEx18View message handlers
void CEx18View::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
if (m_pDlg->GetSafeHwnd() == 0) {
m_pDlg->Create(); // 显示非模式对话框
}
CView::OnLButtonDown(nFlags, point);
}
void CEx18View::OnRButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
m_pDlg->DestroyWindow();
CView::OnRButtonDown(nFlags, point);
}
LRESULT CEx18View::OnGoodbye(WPARAM wParam, LPARAM lParam)
{
//非模式对话框点击确定或者取消的消息响应函数
m_pDlg->DestroyWindow();
return 0L;
}
void CEx18View::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
// TODO: Add your message handler code here and/or call default
m_ModelDlg=new CModellessDlg(CWnd::GetDlgItem(IDD_DIALOG1));
m_ModelDlg->DoModal();
delete m_ModelDlg;
CView::OnKeyDown(nChar, nRepCnt, nFlags);
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?