www.pudn.com > VisualC6.0.rar > CommonDlgDemoView.cpp, change:2007-08-02,size:4013b


// CommonDlgDemoView.cpp : implementation of the CCommonDlgDemoView class 
// 
 
#include "stdafx.h" 
#include "CommonDlgDemo.h" 
 
#include "CommonDlgDemoDoc.h" 
#include "CommonDlgDemoView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CCommonDlgDemoView 
 
IMPLEMENT_DYNCREATE(CCommonDlgDemoView, CView) 
 
BEGIN_MESSAGE_MAP(CCommonDlgDemoView, CView) 
	//{{AFX_MSG_MAP(CCommonDlgDemoView) 
	ON_COMMAND(ID_FONT, OnFont) 
	ON_COMMAND(ID_COLOR, OnColor) 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CCommonDlgDemoView construction/destruction 
 
CCommonDlgDemoView::CCommonDlgDemoView() 
{ 
	// TODO: add construction code here 
	crColor=RGB(255,0,0);//圆的初始颜色红色 
	fntColor=RGB(0,0,255);//字体的初始颜色蓝色 
	memset(&fnt,0,sizeof(LOGFONT)); 
	fnt.lfHeight=30;//字体初始高度30 
	strcpy(fnt.lfFaceName,"Arial");//初始字体名称 
	fnt.lfWeight=400;//初始字体浓淡 
} 
 
CCommonDlgDemoView::~CCommonDlgDemoView() 
{ 
} 
 
BOOL CCommonDlgDemoView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CCommonDlgDemoView drawing 
 
void CCommonDlgDemoView::OnDraw(CDC* pDC) 
{ 
	CCommonDlgDemoDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
	CPen mypen; 
	mypen.CreatePen(PS_SOLID,3,crColor);//创建画笔 
	pDC->SelectObject(&mypen);//载入画笔 
	pDC->Ellipse(100,100,250,250);//画圆 
 
	pDC->SetTextColor(fntColor);//字体的颜色 
	CFont myfont; 
	myfont.CreateFontIndirect(&fnt);//创建字体 
	pDC->SelectObject(&myfont);//载入字体 
	pDC->TextOut(50,50,"字体对话框设置字体");//输出文字 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CCommonDlgDemoView printing 
 
BOOL CCommonDlgDemoView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CCommonDlgDemoView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CCommonDlgDemoView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CCommonDlgDemoView diagnostics 
 
#ifdef _DEBUG 
void CCommonDlgDemoView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CCommonDlgDemoView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CCommonDlgDemoDoc* CCommonDlgDemoView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CCommonDlgDemoDoc))); 
	return (CCommonDlgDemoDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CCommonDlgDemoView message handlers 
 
void CCommonDlgDemoView::OnFont()  
{ 
	// TODO: Add your command handler code here 
	CFontDialog fontdialog(&fnt);//初始化字体对象 
	fontdialog.m_cf.rgbColors=fntColor;//字体对话框初始化 
 
	if(fontdialog.DoModal()==IDOK)//显示字体对话框 
	{ 
		fontdialog.GetCurrentFont(&fnt);//获取字体信息 
		fntColor=fontdialog.GetColor();//获取字体颜色 
	} 
	Invalidate(true);	//重绘窗口 
} 
 
void CCommonDlgDemoView::OnColor()  
{ 
	// TODO: Add your command handler code here 
	CColorDialog colordialog(crColor,CC_FULLOPEN);//初始化颜色对话框对象 
	if(colordialog.DoModal()==IDOK)//创建颜色对话框 
	{ 
		crColor=colordialog.m_cc.rgbResult; 
		//crColor=colordialog.GetColor();//获取设置颜色 
		Invalidate(true);//重绘窗口 
	} 
}