要做路径规划东东了,仿真需要陈vc,先扫扫盲吧!
1.使用SDK获取DC句柄
HDC hdc;
hdc=::GetDc(m_hWnd);<wbr><wbr><wbr>//获取DC句柄<br>
MoveToEx(hdc,m_ptOrigin.x,m_ptOrigin.y,NULL);<br>
LineTo(hdc,point.x,point.y);<br>
::ReleaseDC(m_hWnd,hdc);<wbr><wbr><wbr>//释放DC</wbr></wbr></wbr></wbr></wbr></wbr>
2.利用CDC类指针和CWin类成员函数获取DC
CDC *pDC=GetDC();
pDC->MoveTo(m_ptOrigin);
pDC->LineTo(point);
ReleaseDC(pDC);
3.利用CClientDC对象 (CClientDC类从CDC类派生来的)
<wbr> CClientDC派生自CDC<br><wbr>构造CClientDC对象的时候自动调用GetDC,而在析构的时候自动调用ReleaseDC.从而我们不需要<br><wbr> 显示的去调用这两个函数.只需要仅仅构造一个CClientDC对象.</wbr></wbr></wbr>
CClientDC dc(this);
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
----------
The CClientDC class is derived from CDC and takes care of callingthe Windows functions GetDC at construction time and ReleaseDC atdestruction time. This means that the device context associatedwith a CClientDC object is the client area of a window.
4.利用CWindowDC对象 (CWindowDC类从CDC类派生来的)
CWindowDC dc(this);//
dc.MoveTo(m_ptOrigin);
dc.LineTo(point);
-----------
The CWindowDC class is derived from CDC. It calls the WindowsfunctionsGetWindowDC at construction time andReleaseDC atdestruction time. This means that a CWindowDC object accesses theentire screen area of a CWnd (both client and nonclient areas).
5.GetParent()得到父窗口指针; GetDesktopWindow()得到屏幕窗口指针
6.利用画笔改变线条颜色和类型:
CPenpen(PS_DOT,1,RGB(0,255,0));<wbr><wbr><wbr>//构造画笔对象<br>
CClientDC dc(this);CPen*pOldPen=dc.SelectObject(&pen);<wbr><wbr><wbr>//将画笔选入DC<br>
dc.MoveTo(m_ptOrigin);<br>
dc.LineTo(point);<br>
dc.SelectObject(pOldPen);<wbr><wbr><wbr>//恢复先前的画笔</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
7.使用画刷 (通常利用画刷去填充矩形区域):
使用单色画刷
CBrushbrush(RGB(255,0,0));<wbr><wbr><wbr>//构造画刷对象<br>
CClientDC dc(this);<br>
dc.FillRect(CRect(m_ptOrigin,point),&brush);<wbr><wbr><wbr>//用指定的画刷去填充矩形区域</wbr></wbr></wbr></wbr></wbr></wbr>
使用位图画刷
CBitmap bitmap;//构造位图对象 (使用前需要初试化)
bitmap.LoadBitmap(IDB_BITMAP1);<wbr><wbr><wbr>//初试化位图对象<br>
CBrushbrush(&bitmap);<wbr><wbr><wbr>//构造位图画刷<br>
CClientDC dc(this);<br>
dc.FillRect(CRect(m_ptOrigin,point),&brush);<wbr><wbr><wbr>//用指定的位图画刷去填充矩形区域</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
使用透明画刷
CBrush*pBrush=CBrush::FromHandle((HBRUSH)GetStockObject(NULL_BRUSH));<wbr><wbr><wbr>//获取透明画刷对象指针<br>
CClientDC dc(this);<br>
CBrush *pOldBrush=dc.SelectObject(pBrush); //将透明画刷选入DC<br>
dc.Rectangle(CRect(m_ptOrigin,point));<br>
dc.SelectObject(pOldBrush);//释放透明画刷<br>
----------<br>
The GetStockObject function retrieves a handle to one of thepredefined stock pens, brushes, fonts, or palettes.<br>
HGDIOBJ GetStockObject(<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>int fnObject<wbr><wbr> // type of
stockobject<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>);</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
Returns a pointer to a CBrush object when given a handle to aWindows HBRUSH object.
static CBrush* PASCAL FromHandle( HBRUSH hBrush);//FromHandle是一个静态方法.故可用CBrush::FromHandle()形式调用。
----------
1)静态方法不属于某一个具体对象.而属于类本身.在类加载的时候就已经为类静态方法分配了代码去.故可用CBrush::FromHandle()形式调用。
2)静态方法中.不能引用非静态的数据成员和方法。
3)静态数据成员需要在类外单独做初始化.形式如: 变量类型 类名::变量名=初始值;
8.CDC::SetROP2方法
int SetROP2( int nDrawMode );
Sets the current drawing mode.
画线:
CClientDC dc(this);
dc.SetROP2( R2_NOT);
dc.MoveTo(p_Orgpt);
dc.LineTo(p_Endpt);
dc.MoveTo(p_Orgpt);
dc.LineTo(p_Endpt);
p_Endpt = point;//这里要记住哦!
分享到:
相关推荐
VC绘图程序设计技巧与实例教程,对有兴趣VC图形处理的程序员有所帮助
一个非常好用的vc绘图工具,和windows的绘图功能很象了。
GDI绘图GDI绘图GDI绘图GDI绘图GDI绘图GDI绘图GDI绘图GDI绘图
VC绘图资料大全 VC绘图资料大全 VC绘图资料大全
用vc语言编制的简单绘图程序源码,内有圆形,矩形, 扇形等
共包含四个实例,都带有源代码和工程文件, 一个可以绘制类似matlub的图形 一个是封装好的可以在指定位置显示png图形的类 一个是使用双缓冲技术绘图的实例 一个是有对图形进行缩放移动功能的实例
绘图控件,给编程带来很大方便。具体操作,在示例程序中都有。
简单的绘图板,没什么功能,就是孙鑫书上的实现
VC下开源的绘图控件,功能强大,使用稳定方便,在VC平台和VS平台都可以使用,无需破解注册
vc做的绘图程序,可以运行,程序源代码中有怎么样使用画笔,做出了一个整炫曲线。
VC绘图(曲线-清除显示-块复制-控件播放动画) 正弦,抛物线,光栅
本人编写用VC绘图最基本的操作,代码很少,有如何建立工程、以及演示结果,适合VC初学者
vc画图和vc图片的全面操作方法和函数介绍及举例.通过此文档,学者可以方便的掌握vc绘图方面的专业技能。从此vc绘图不再是难题。
OpenGL三维绘图vc绘图源码,我看到别人分拉的很高,免费才是硬道理
适合VC初学者,学习VC绘图的基本操作,包括对设备环境、用户坐标、视口等概念的理解
vc绘图:gis绘图程序(简单矢量图形绘制).rar
用VC写的绘图程序源码--用VC写的绘图程序源码--用VC写的绘图程序源码
常用绘图函数实例: 在2DCAD工程中视图类的OnDraw函数中添加绘图代码
VC 绘图实例-多线程,源码包中包括了Lib、对话框作图实例、衰减振荡曲线(单线程)、衰减振荡曲线(多线程)和调试说明。里面用到了第三方控件,已打包在源码包中,编译时请发在Exe程序同级目录下。
vc API绘图小例程vc API绘图小例程vc API绘图小例程vc API绘图小例程vc API绘图小例程vc API绘图小例程vc API绘图小例程vc API绘图小例程vc API绘图小例程vc API绘图小例程vc API绘图小例程vc API绘图小例程