www.pudn.com > ColorDlg-v1.1.rar > ColorDlgView.cpp


// ColorDlgView.cpp : implementation of the CColorDlgView class 
// 
 
#include "stdafx.h" 
#include "ColorDlg.h" 
 
#include  
#include  
#include  
 
#include "ColorDlgDoc.h" 
#include "ColorDlgView.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CColorDlgView 
 
IMPLEMENT_DYNCREATE(CColorDlgView, CView) 
 
BEGIN_MESSAGE_MAP(CColorDlgView, CView) 
	//{{AFX_MSG_MAP(CColorDlgView) 
	ON_COMMAND(ID_COLOR, OnColor) 
	ON_COMMAND(ID_GCOLOR, OnGcolor) 
	ON_WM_TIMER() 
	ON_WM_CREATE() 
	ON_WM_DESTROY() 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CColorDlgView construction/destruction 
 
CColorDlgView::CColorDlgView() 
{ 
	// TODO: add construction code here 
	csdlg.n1=0;csdlg.n2=0;csdlg.n3=0; 
	m_clr1=RGB(0,0,0); 
	m_clr2=RGB(0,0,0); 
	m_clr3=RGB(0,0,0); 
//	csdlg.m_nR=csdlg.n1; 
//	csdlg.m_nG=csdlg.n2; 
//	csdlg.m_nB=csdlg.n3; 
 
} 
 
CColorDlgView::~CColorDlgView() 
{ 
} 
 
BOOL CColorDlgView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CColorDlgView drawing 
 
void CColorDlgView::OnDraw(CDC* pDC) 
{ 
	CColorDlgDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
	CRect rect; 
	GetClientRect(rect); 
 
	CBrush brush1,brush2,brush3; 
	brush1.CreateSolidBrush(m_clr1); 
	pDC->SelectObject(&brush1); 
	pDC->Ellipse(50,50,100,100); 
 
	brush2.CreateSolidBrush(m_clr2); 
	pDC->SelectObject(&brush2); 
	pDC->Ellipse(50,120,100,170); 
 
//	csdlg.m_nR=csdlg.n1; 
//	csdlg.m_nG=csdlg.n2; 
//	csdlg.m_nB=csdlg.n3; 
	csdlg.n1=csdlg.m_nR; 
	csdlg.n2=csdlg.m_nG; 
	csdlg.n3=csdlg.m_nB; 
//	brush3.CreateSolidBrush(m_clr3); 
//	pDC->SelectObject(&brush3); 
//	pDC->Ellipse(50,190,100,240); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CColorDlgView printing 
 
BOOL CColorDlgView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CColorDlgView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CColorDlgView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CColorDlgView diagnostics 
 
#ifdef _DEBUG 
void CColorDlgView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CColorDlgView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CColorDlgDoc* CColorDlgView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CColorDlgDoc))); 
	return (CColorDlgDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CColorDlgView message handlers 
 
void CColorDlgView::OnColor()  
{ 
	// TODO: Add your command handler code here 
	//csdlg.DoModal(); 
 
	if(IDOK==csdlg.DoModal()) 
	{ 
//		csdlg.n1=csdlg.m_nR; 
//		csdlg.n2=csdlg.m_nG; 
//		csdlg.n3=csdlg.m_nB; 
		m_clr1=RGB(csdlg.m_nR,csdlg.m_nG,csdlg.m_nB); 
//		m_clr1=RGB(csdlg.n1,csdlg.n2,csdlg.n3); 
	} 
 
	Invalidate(); 
	 
} 
 
void CColorDlgView::OnGcolor()  
{ 
	// TODO: Add your command handler code here 
 
	//gcdlg.DoModal(); 
 
	if(IDOK==gcdlg.DoModal()) 
	{ 
		m_clr2=gcdlg.m_cc.rgbResult; 
	} 
 
	Invalidate(); 
 
} 
 
void CColorDlgView::OnTimer(UINT nIDEvent)  
{ 
	// TODO: Add your message handler code here and/or call default 
	CClientDC dc(this); 
	CBrush brushR; 
	CBrush *pOldBrush; 
	srand( (unsigned)time( NULL ) ); 
	brushR.CreateSolidBrush(RGB(rand()%250,rand()%150,rand()%100)); 
	pOldBrush=dc.SelectObject(&brushR); 
	dc.Ellipse(50,190,100,240); 
	dc.SelectObject(pOldBrush); 
	/*CRect rg; 
	rg.left=50; 
	rg.right=190; 
	rg.top=100; 
	rg.bottom=240; 
	InvalidateRect(rg);*/ 
	CView::OnTimer(nIDEvent); 
} 
 
int CColorDlgView::OnCreate(LPCREATESTRUCT lpCreateStruct)  
{ 
	if (CView::OnCreate(lpCreateStruct) == -1) 
		return -1; 
	 
	// TODO: Add your specialized creation code here 
	SetTimer(1,100,NULL); 
	return 0; 
} 
 
void CColorDlgView::OnDestroy()  
{ 
	CView::OnDestroy(); 
	KillTimer(1); 
	// TODO: Add your message handler code here 
	 
}