// HDC画直线
CPoint m_ptOrigin ;
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin = point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
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); CView::OnLButtonUp(nFlags, point);
} // CDC画直线
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin = point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
CDC *pDC = GetDC();
pDC->MoveTo(m_ptOrigin);
pDC->LineTo(point);
ReleaseDC(pDC); CView::OnLButtonUp(nFlags, point);
} // CClientDC、CWindowDC画直线
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin = point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
CClientDC dc(this); //画到客户区
CClientDC dc(GetParent()); //画到客户区+工具栏
CWindowDC dc(this); //画到客户区
CWindowDC dc(GetParent()); //画到客户区+工具栏+菜单栏+标题栏
CWindowDC dc(GetDesktopWindow()); //画到整个屏幕窗口
dc.MoveTo(m_ptOrigin);
dc.LineTo(point); CView::OnLButtonUp(nFlags, point);
} //带颜色的直线
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin = point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
CPen pen(PS_SOLID, , RGB(, , ));
CClientDC dc(this);
CPen *pOldPen = dc.SelectObject(&pen);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
dc.SelectObject(pOldPen); CView::OnLButtonUp(nFlags, point);
} //画刷
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin = point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
CBrush brush(RGB(, , ));
CClientDC dc(this);
dc.FillRect(CRect(m_ptOrigin, point), &brush); CView::OnLButtonUp(nFlags, point);
}
//位图画刷
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin = point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
CBitmap bitmap;
bitmap.LoadBitmap(IDB_BITMAP1);
CBrush brush(&bitmap);
CClientDC dc(this);
dc.FillRect(CRect(m_ptOrigin, point), &brush); CView::OnLButtonUp(nFlags, point);
}
//透明画刷
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin = point;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
CClientDC dc(this);
// dc.Rectangle(CRect(m_ptOrigin, point)); //不透明
CBrush *pBrush = CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));
CBrush *pOldBrush = dc.SelectObject(pBrush);
dc.Rectangle(CRect(m_ptOrigin, point));
dc.SelectObject(pOldBrush); //透明 CView::OnLButtonUp(nFlags, point);
}
//用画笔写字
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin = point;
m_bDraw = TRUE;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bDraw = FALSE;
CView::OnLButtonUp(nFlags, point);
}
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc(this);
CPen pen(PS_SOLID, , RGB(, , ));
CPen *pOldPen = dc.SelectObject(&pen);
if(m_bDraw == TRUE)\
{
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
m_ptOrigin = point;
}
dc.SelectObject(pOldPen); CView::OnMouseMove(nFlags, point);
} //画扇形
CPoint m_ptOld;
void CDrawView::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptOrigin = m_ptOld = point;
m_bDraw = TRUE;
CView::OnLButtonDown(nFlags, point);
}
void CDrawView::OnLButtonUp(UINT nFlags, CPoint point)
{
m_bDraw = FALSE;
CView::OnLButtonUp(nFlags, point);
}
void CDrawView::OnMouseMove(UINT nFlags, CPoint point)
{
CClientDC dc(this);
CPen pen(PS_SOLID, , RGB(, , ));
CPen *pOldPen = dc.SelectObject(&pen);
if(m_bDraw == TRUE)\
{
dc.MoveTo(m_ptOrigin);
dc.LineTo(m_ptOld);
// dc.MoveTo(m_ptOrigin); // 不带边线
dc.MoveTo(m_ptOld); // 带边线
dc.LineTo(point);
m_ptOld = point;
}
dc.SelectObject(pOldPen); CView::OnMouseMove(nFlags, point);
}

几种画直线的方法-孙鑫C++笔记的更多相关文章

  1. SDL系列之 - 用画直线的方法来画正弦曲线

    线段长度无限短后就成为点,所以,现在让我们用画直线的方法来画正弦曲线吧 #include <SDL.h> #include <stdlib.h> #include <st ...

  2. javascript画直线和画圆的方法(非HTML5的方法)

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. 孙鑫视频学习:改变窗口过程函数中出现error C2440错误的解决方法

    在Visual Studio 2010中,即使代码是完完全全按照孙鑫视频中的敲,也会在出现error C2440,这是因为开发平台由VC6.0升级至VS2010,需要将原有的项目迁移.VS2010对消 ...

  4. 孙鑫视频VC++深入详解学习笔记

    孙鑫视频VC++深入详解学习笔记 VC++深入详解学习笔记 Lesson1: Windows程序运行原理及程序编写流程 Lesson2: 掌握C++基本语法 Lesson3: MFC框架程序剖析 Le ...

  5. 孙鑫VC学习系列教程

    教程简介 1.循序渐进 从Win32SDK编程开始讲解,帮助大家理解掌握Windows编程的核心 -- 消息循环机制. 2.通俗易懂 编程语言枯燥难懂,然而通过孙鑫老师形象化的讲解,Windows和M ...

  6. 孙鑫VC学习笔记:多线程编程

    孙鑫VC学习笔记:多线程编程 SkySeraph Dec 11st 2010  HQU Email:zgzhaobo@gmail.com    QQ:452728574 Latest Modified ...

  7. android布局中画线的方法

    1.自定义View画线 http://fariytale.iteye.com/blog/1264225 下面介绍几种简单的方法 2.textView和View画直线 <TextView andr ...

  8. 孙鑫视频学习:关于Visual Studio 2010中MFC工程的消息WM_INITDIALOG找不到的问题

    学习孙鑫的那个深入详解C++视频时,有一处给编辑框空间改写窗口过程函数的例子,其中需要添加一个WM_INITDIALOG消息响应函数,但在类向导的消息栏下找不到WM_INITDIALOG消息.解决方法 ...

  9. 纯JS画点、画线、画圆的方法

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

随机推荐

  1. 转:C#整数三种强制类型转换int、Convert.ToInt32()、int.Parse()的区别

    1.int适合简单数据类型之间的转换,C#的默认整型是int32(不支持bool型); 2.int.Parse(string sParameter)是个构造函数,参数类型只支持string类型; 3. ...

  2. JS delete 用法(删除对象属性及变量)

    1,对象属性删除 function fun(){ this.name = 'mm'; } var obj = new fun(); console.log(obj.name);//mm delete ...

  3. hasClass方法 动画方法说明

    $(this).hasClass("selected");判断是否含有selected样式

  4. [汇编语言]-第九章 在屏幕中间分别显示绿底红色,白底蓝色字符串"welcome to masm!"

    ;在屏幕中间分别显示绿色,绿底红色,白底蓝色字符串"welcome to masm!" assume cs:codesg,ds:datasg,ss:stacksg datasg s ...

  5. MySQL命令记录1

    mysql命令行 开启:net start mysql56关闭:net start mysql56(这两种情况必须有管理员权限) 登陆:mysql -h localhost -u root -p(lo ...

  6. SQL Server 创建索引的 5 种方法

    前期准备: create table Employee (            ID int not null primary key,            Name nvarchar(4),  ...

  7. Qt-4.6动画Animation快速入门三字决

    Qt-4.6动画Animation快速入门三字决 Qt-4.6新增了Animation Framework(动画框架),让我们能够方便的写一些生动的程序.不必像以前的版本一样,所有的控件都枯燥的呆在伟 ...

  8. 【HDU】1754 I hate it ——线段树 单点更新 区间最值

    I Hate It Time Limit: 9000/3000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total S ...

  9. 【LeetCode练习题】Copy List with Random Pointer

    Copy List with Random Pointer A linked list is given such that each node contains an additional rand ...

  10. iOS断言

    来自:http://my.oschina.net/panyong/blog/205573 在看到xmpp项目中的一些代码时,看到如下,不懂该代码是啥意思, 如下: NSAssert(_xmppStre ...