MFC画线 矩形 画刷 透明画刷 连续线条

// TestView.cpp : implementation of the CTestView class
//


#include "stdafx.h"
#include "Test.h"


#include "TestDoc.h"
#include "TestView.h"


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


/
// CTestView


IMPLEMENT_DYNCREATE(CTestView, CView)


BEGIN_MESSAGE_MAP(CTestView, CView)
//{{AFX_MSG_MAP(CTestView)
ON_WM_CREATE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MOUSEMOVE()
//}}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()


/
// CTestView construction/destruction


CTestView::CTestView()
{
// TODO: add construction code here
m_ptOrigin.x=0;
m_ptOrigin.y=0;
m_bDraw = FALSE;


}


CTestView::~CTestView()
{
}


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


return CView::PreCreateWindow(cs);
}


/
// CTestView drawing


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


/
// CTestView printing


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


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


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


/
// CTestView diagnostics


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


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


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


/
// CTestView message handlers


int CTestView::OnCreate(LPCREATESTRUCT lpCreateStruct) 
{
if (CView::OnCreate(lpCreateStruct) == -1)
return -1;
/* m_btn.Create("按钮", WS_CHILD | BS_DEFPUSHBUTTON, CRect(0,0, 100, 100), this, 456);
// m_btn.Create("按钮", WS_CHILD | BS_DEFPUSHBUTTON, CRect(0,0, 100, 100), GetParent(), 456);
m_btn.ShowWindow(SW_SHOWNORMAL);*/
// TODO: Add your specialized creation code here

return 0;
}




void CTestView::OnLButtonDown(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
m_bDraw = TRUE;
m_ptOrigin=point;
m_ptOld=point;
// MessageBox("View");
CView::OnLButtonDown(nFlags, point);
}


void CTestView::OnLButtonUp(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default


/* HDC hdc;
hdc = ::GetDC(m_hWnd);
MoveToEx(hdc, m_ptOrigin.x, m_ptOrigin.y, NULL);
LineTo(hdc, point.x, point.y);
::ReleaseDC(m_hWnd, hdc);  //全局函数
*/




/*
CDC * pDC = GetDC();
pDC->MoveTo(m_ptOrigin);
pDC->LineTo(point);
ReleaseDC(pDC); //成员函数
*/


/*
CClientDC dc(this);
// CClientDC dc(GetParent());
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
*/




/* CWindowDC dc(this);
// CWindowDC dc(GetParent());
// CWindowDC dc(GetDesktopWindow());
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);*/




/*
// CPen pen(PS_SOLID, 10, RGB(255,0,0));
// CPen pen(PS_DASH, 1, RGB(255,0,0));
CPen pen(PS_DOT, 1, RGB(255,0,0));
CClientDC dc(GetParent());
CPen * pOldPen = dc.SelectObject(&pen);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
dc.SelectObject(pOldPen);
*/


/*
CBrush brush(RGB(255,0,0));
CClientDC dc(this);
dc.FillRect(CRect(m_ptOrigin, point), &brush);
*/


/*
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);


CBrush brush(&bitmap);
CClientDC dc(this);
dc.FillRect(CRect(m_ptOrigin, point), &brush);
*/


/*
CClientDC dc(this);
dc.Rectangle(CRect(m_ptOrigin, point));
*/


/*
CClientDC dc(this);
CBrush *pBrush = CBrush::FromHandle((HBRUSH) GetStockObject(NULL_BRUSH));
CBrush *pOldBrush = dc.SelectObject(pBrush);
dc.Rectangle(CRect(m_ptOrigin, point));
dc.SelectObject(pOldBrush);
*/
m_bDraw = FALSE;








CView::OnLButtonUp(nFlags, point);
}


void CTestView::OnMouseMove(UINT nFlags, CPoint point) 
{
// TODO: Add your message handler code here and/or call default
/* CClientDC dc(this);


CPen pen(PS_SOLID, 1, RGB(255,0,0));
CPen *pOldPen = dc.SelectObject(&pen);




if(m_bDraw == TRUE)
{
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
m_ptOrigin = point;
}


dc.SelectObject(pOldPen);*/




CClientDC dc(this);
// dc.SetROP2(R2_MERGENOTPEN);
dc.SetROP2(R2_BLACK);
CPen pen(PS_SOLID, 1, RGB(255,0,0));
CPen *pOldPen = dc.SelectObject(&pen);
if(m_bDraw == TRUE)
{
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
dc.LineTo(m_ptOld);
m_ptOld = point;
}
dc.SelectObject(pOldPen);






CView::OnMouseMove(nFlags, point);
}

你可能感兴趣的:(vc++)