www.pudn.com > TOOLBarSample.rar > TOOLBarSampleView.cpp, change:2006-03-28,size:4693b


// TOOLBarSampleView.cpp : implementation of the CTOOLBarSampleView class 
// 
 
#include "stdafx.h" 
#include "TOOLBarSample.h" 
//#include "TOOLBarSampleView.h" 
 
#include "TOOLBarSampleDoc.h" 
#include "TOOLBarSampleView.h" 
#include "MainFrm.h" 
 
#ifdef _DEBUG 
#define new DEBUG_NEW 
#undef THIS_FILE 
static char THIS_FILE[] = __FILE__; 
#endif 
 
///////////////////////////////////////////////////////////////////////////// 
// CTOOLBarSampleView 
 
IMPLEMENT_DYNCREATE(CTOOLBarSampleView, CView) 
 
BEGIN_MESSAGE_MAP(CTOOLBarSampleView, CView) 
	//{{AFX_MSG_MAP(CTOOLBarSampleView) 
	ON_COMMAND(ID_ELLIPSE, OnEllipse) 
	ON_UPDATE_COMMAND_UI(ID_ELLIPSE, OnUpdateEllipse) 
	ON_COMMAND(ID_RECT, OnRect) 
	ON_UPDATE_COMMAND_UI(ID_RECT, OnUpdateRect) 
	ON_WM_LBUTTONDOWN() 
	ON_CBN_SELCHANGE(IDC_FILLORNO, OnSelChangeCombo) 
	//}}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() 
 
///////////////////////////////////////////////////////////////////////////// 
// CTOOLBarSampleView construction/destruction 
 
CTOOLBarSampleView::CTOOLBarSampleView() 
{ 
	// TODO: add construction code here 
    int m_y = 0; 
	int m_x = 0 ; 
	int m_shape = 0 ; 
	 m_fill = TRUE ; 
} 
 
CTOOLBarSampleView::~CTOOLBarSampleView() 
{ 
} 
 
BOOL CTOOLBarSampleView::PreCreateWindow(CREATESTRUCT& cs) 
{ 
	// TODO: Modify the Window class or styles here by modifying 
	//  the CREATESTRUCT cs 
 
	return CView::PreCreateWindow(cs); 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CTOOLBarSampleView drawing 
 
void CTOOLBarSampleView::OnDraw(CDC* pDC) 
{ 
	CTOOLBarSampleDoc* pDoc = GetDocument(); 
	ASSERT_VALID(pDoc); 
	// TODO: add draw code for native data here 
	RECT rect ; 
	rect.left = m_x-50 ; 
	rect.right= m_x+50 ; 
	rect.top = m_y-30 ; 
    rect.bottom = m_y+30 ; 
 
	CBrush blue ; 
	blue.CreateSolidBrush(RGB(0,0,255)) ; 
 
	CBrush *PoldBrush ; 
	if (m_fill == TRUE) 
	{ 
		PoldBrush= pDC->SelectObject(&blue) ; 
		if (m_shape == 0) 
			pDC->Ellipse(&rect) ; 
		else 
			pDC->FillRect(&rect,&blue) ; 
	} 
	else  
	{ 
		PoldBrush = (CBrush*)pDC->SelectStockObject(NULL_BRUSH) ; 
		if (m_shape == 0) 
			pDC->Ellipse(&rect) ;  
		else 
            pDC->Rectangle(&rect) ; 
	} 
	pDC->SelectObject(PoldBrush) ; 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CTOOLBarSampleView printing 
 
BOOL CTOOLBarSampleView::OnPreparePrinting(CPrintInfo* pInfo) 
{ 
	// default preparation 
	return DoPreparePrinting(pInfo); 
} 
 
void CTOOLBarSampleView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add extra initialization before printing 
} 
 
void CTOOLBarSampleView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) 
{ 
	// TODO: add cleanup after printing 
} 
 
///////////////////////////////////////////////////////////////////////////// 
// CTOOLBarSampleView diagnostics 
 
#ifdef _DEBUG 
void CTOOLBarSampleView::AssertValid() const 
{ 
	CView::AssertValid(); 
} 
 
void CTOOLBarSampleView::Dump(CDumpContext& dc) const 
{ 
	CView::Dump(dc); 
} 
 
CTOOLBarSampleDoc* CTOOLBarSampleView::GetDocument() // non-debug version is inline 
{ 
	ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(CTOOLBarSampleDoc))); 
	return (CTOOLBarSampleDoc*)m_pDocument; 
} 
#endif //_DEBUG 
 
///////////////////////////////////////////////////////////////////////////// 
// CTOOLBarSampleView message handlers 
 
void CTOOLBarSampleView::OnEllipse()  
{ 
	// TODO: Add your command handler code here 
	m_shape = 0 ; 
} 
 
void CTOOLBarSampleView::OnUpdateEllipse(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(m_shape == 0) 
		pCmdUI->SetCheck(1) ; 
	else 
		pCmdUI->SetCheck(0) ; 
} 
 
void CTOOLBarSampleView::OnRect()  
{ 
	// TODO: Add your command handler code here 
	m_shape = 1 ; 
 
} 
 
void CTOOLBarSampleView::OnUpdateRect(CCmdUI* pCmdUI)  
{ 
	// TODO: Add your command update UI handler code here 
	if(m_shape == 1) 
		pCmdUI->SetCheck(1) ; 
	else 
		pCmdUI->SetCheck(0) ; 
} 
 
void CTOOLBarSampleView::OnLButtonDown(UINT nFlags, CPoint point)  
{ 
	// TODO: Add your message handler code here and/or call default 
	m_x = point.x ; 
	m_y = point.y ; 
    Invalidate() ; 
	CView::OnLButtonDown(nFlags, point); 
} 
 
void CTOOLBarSampleView::OnSelChangeCombo() 
{ 
	CString m_curstr ; 
	CMainFrame* pMFrame = (CMainFrame*)AfxGetMainWnd() ; 
	pMFrame->m_fillorno.GetLBText(pMFrame->m_fillorno.GetCurSel(),m_curstr) ; 
	if (m_curstr == "") 
		m_fill =true ; 
	else 
		m_fill = false ; 
}