在vc2010内使用CBrush实现画刷功能
2012-06-30 21:19
459 查看
首先在过程内建立一个位图,然后以该位图作为画笔原型。程序如下:
参考:
VC++2010开发权威指南,尹成,pp.431
// lessonMyBrushView.cpp : implementation of the ClessonMyBrushView class // #include "stdafx.h" // SHARED_HANDLERS can be defined in an ATL project implementing preview, thumbnail // and search filter handlers and allows sharing of document code with that project. #ifndef SHARED_HANDLERS #include "lessonMyBrush.h" #endif #include "lessonMyBrushDoc.h" #include "lessonMyBrushView.h" #ifdef _DEBUG #define new DEBUG_NEW #endif // ClessonMyBrushView IMPLEMENT_DYNCREATE(ClessonMyBrushView, CView) BEGIN_MESSAGE_MAP(ClessonMyBrushView, CView) // Standard printing commands ON_COMMAND(ID_FILE_PRINT, &CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_DIRECT, &CView::OnFilePrint) ON_COMMAND(ID_FILE_PRINT_PREVIEW, &ClessonMyBrushView::OnFilePrintPreview) ON_WM_CONTEXTMENU() ON_WM_RBUTTONUP() ON_WM_LBUTTONUP() ON_WM_LBUTTONDOWN() END_MESSAGE_MAP() // ClessonMyBrushView construction/destruction ClessonMyBrushView::ClessonMyBrushView() : myPoint(0) { // TODO: add construction code here } ClessonMyBrushView::~ClessonMyBrushView() { } BOOL ClessonMyBrushView::PreCreateWindow(CREATESTRUCT& cs) { // TODO: Modify the Window class or styles here by modifying // the CREATESTRUCT cs return CView::PreCreateWindow(cs); } // ClessonMyBrushView drawing void ClessonMyBrushView::OnDraw(CDC* /*pDC*/) { ClessonMyBrushDoc* pDoc = GetDocument(); ASSERT_VALID(pDoc); if (!pDoc) return; // TODO: add draw code for native data here } // ClessonMyBrushView printing void ClessonMyBrushView::OnFilePrintPreview() { #ifndef SHARED_HANDLERS AFXPrintPreview(this); #endif } BOOL ClessonMyBrushView::OnPreparePrinting(CPrintInfo* pInfo) { // default preparation return DoPreparePrinting(pInfo); } void ClessonMyBrushView::OnBeginPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add extra initialization before printing } void ClessonMyBrushView::OnEndPrinting(CDC* /*pDC*/, CPrintInfo* /*pInfo*/) { // TODO: add cleanup after printing } void ClessonMyBrushView::OnRButtonUp(UINT /* nFlags */, CPoint point) { ClientToScreen(&point); OnContextMenu(this, point); } void ClessonMyBrushView::OnContextMenu(CWnd* /* pWnd */, CPoint point) { #ifndef SHARED_HANDLERS theApp.GetContextMenuManager()->ShowPopupMenu(IDR_POPUP_EDIT, point.x, point.y, this, TRUE); #endif } // ClessonMyBrushView diagnostics #ifdef _DEBUG void ClessonMyBrushView::AssertValid() const { CView::AssertValid(); } void ClessonMyBrushView::Dump(CDumpContext& dc) const { CView::Dump(dc); } ClessonMyBrushDoc* ClessonMyBrushView::GetDocument() const // non-debug version is inline { ASSERT(m_pDocument->IsKindOf(RUNTIME_CLASS(ClessonMyBrushDoc))); return (ClessonMyBrushDoc*)m_pDocument; } #endif //_DEBUG // ClessonMyBrushView message handlers void ClessonMyBrushView::OnLButtonUp(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default //CBitmap bitmap; /*CBrush brush(RGB(255,0,0)); CClientDC ccdc(this); ccdc.FillRect(CRect(myPoint,point),&brush); */ CBitmap bitmap; bitmap.LoadBitmap(IDB_BITMAP1); CBrush brush(&bitmap); CClientDC ccdc(this); ccdc.FillRect(CRect(myPoint,point),&brush); CView::OnLButtonUp(nFlags, point); } void ClessonMyBrushView::OnLButtonDown(UINT nFlags, CPoint point) { // TODO: Add your message handler code here and/or call default myPoint=point; CView::OnLButtonDown(nFlags, point); }
参考:
VC++2010开发权威指南,尹成,pp.431
相关文章推荐
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息。
- [VC/MFC]使用CTabCtrl控件实现属性页功能
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息
- (libgdx学习)使用Pixmap来实现涂抹功能(类似于画刷)
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息。
- 在托管VC++中使用函数指针进行回调(实现回调函数功能)
- [VC/MFC]使用CTabCtrl控件实现属性页功能
- 在VC2010内使用CBrush构建透明笔刷
- [VC/MFC]使用CTabCtrl控件实现属性页功能
- 使用CTabCtrl控件实现属性页功能-界面类编程-VC
- VC2010 MFC中实现printf调试功能,即MFC程序利用控制台输出调试信息
- asp.net留言板 利用富文本编辑器实现美化功能xheditor在asp.net网页的配置和使用
- 使用thinkphp框架实现登录注册功能
- Socket 功能在 Service 中实现【这才是实际的使用情况】
- 在VC中使用SendInput函数实现中文的自动输入
- 关于使用DataGrid的ButtonColumn,动态添加DataGrid列,实现不定列n个文件的下载功能
- Python 使用 pylab 库实现画线功能的方法详解
- 使用科大讯飞SDK实现语音功能