关于VC中LineDDA函数的调用

来源:互联网 发布:c语言数据类型举例 编辑:程序博客网 时间:2024/06/01 07:38

在项目里碰到这个函数,不知道怎么使用,记录在这里。

该函数的原型如下: 
BOOL LineDDA(int nXStart, int nYStart, int nXEnd, int nYEnd, LINEDDAPROC lpLineFunc, LPARAM lpData); 
参数说明如下: 
nXStart:起点的X值 
nYStart:起点的Y值 
nXEnd:终点的X值 
nYEnd:终点的Y值 
lpLineFunc:回调函数的地址
lpData:用户自定义参数(这个参数会传给回调函数) 


这个函数和动画其实没什么关系,它的功能就是计算出连接两点的线段上的每一个屏幕像素的坐标,这两个点的坐标已经在函数的前四个参数中给出。
每计算出一个坐标,该函数就会调用第五个参数所指的回调函数,我们可以在回调函数中完成一些简单的操作,以实现动画效果。 
回调函数的原型是: VOID CALLBACK LineDDAProc(int X, int Y, LPARAM lpData); 
前两个参数是点的坐标,第三个参数就是由LineDDA传过来的自定义参数,是由我们自己指定的,传什么都行。 :) 
详解:
实现以复杂线条为基础的图形绘图
在GIS(地理信息系统)类软件设计中经常需要在绘图时使用一些相对固定但又频繁使用的一些用以代表地理状态的符号如河流、铁路、海岸线等等。每一种符号均有其各自的风格,但在不同的位置的具体表示却不尽相同,比如代表铁路的符号是一段黑白相间的细矩形,但有时是平直的,在拐弯时用弯曲的矩形来表示。因此对于上述符号的绘制一般不易用固定的图标去实现,而多采用灵活多变的用函数来直接绘制的方法。显然作为GIS基本符号的图形一般都是相对比较复杂的线条,在MFC提供的基本类库中并未提供可以直接使用的相关函数。即使是在绘图功能比较强大的CDC中也仅仅提供了LineTo()、SetPixel()等一些通用的最基本的绘图函数,虽然也可以使用这些基本函数来绘制GIS里的基本符号,但这是效率比较低下的一种办法,这在大量的绘图操作中将会表现的比较明显,因此不宜提倡。本文下面将介绍一种使用Win32 API函数LineDDA来绘制复杂风格线条的方法来解决上述类似问题。

运行的程序代码:

void CMyFrameWnd::OnPaint(){CPaintDC dc(this);CRect rect;GetClientRect(rect);dc.SetTextAlign(TA_BOTTOM | TA_CENTER);::LineDDA(50, 50, rect.right / 2, rect.bottom / 2,(LINEDDAPROC)LineDDACallback, (LPARAM)(LPVOID)&dc);}//--------------------------------------------------------------------VOID CALLBACK CMyFrameWnd::LineDDACallback(int x, int y, LPARAM lpData){CDC* pDC = (CDC*)lpData;pDC->SetPixel(x, y+ sin(x), RGB(255, 0, 0));Sleep(1); //延时一下,以便观察}
MSDN的解释的地址:

https://msdn.microsoft.com/query/dev14.query?appId=Dev14IDEF1&l=ZH-CN&k=k(WINGDI%2FLineDDA);k(LineDDA);k(DevLang-C%2B%2B);k(TargetOS-Windows)&rd=true

LineDDA functionThe LineDDA function determines which pixels should be highlighted for a line defined by the specified starting and ending points.SyntaxC++BOOL LineDDA(  _In_ int         nXStart,  _In_ int         nYStart,  _In_ int         nXEnd,  _In_ int         nYEnd,  _In_ LINEDDAPROC lpLineFunc,  _In_ LPARAM      lpData);ParametersnXStart [in]Specifies the x-coordinate, in logical units, of the line's starting point.nYStart [in]Specifies the y-coordinate, in logical units, of the line's starting point.nXEnd [in]Specifies the x-coordinate, in logical units, of the line's ending point.nYEnd [in]Specifies the y-coordinate, in logical units, of the line's ending point.lpLineFunc [in]Pointer to an application-defined callback function. For more information, see the LineDDAProc callback function.lpData [in]Pointer to the application-defined data.Return valueIf the function succeeds, the return value is nonzero.If the function fails, the return value is zero.RemarksThe LineDDA function passes the coordinates for each point along the line, except for the line's ending point, to the application-defined callback function. In addition to passing the coordinates of a point, this function passes any existing application-defined data.The coordinates passed to the callback function match pixels on a video display only if the default transformations and mapping modes are used.RequirementsMinimum supported clientWindows 2000 Professional [desktop apps only]Minimum supported serverWindows 2000 Server [desktop apps only]HeaderWingdi.h (include Windows.h)LibraryGdi32.libDLLGdi32.dll

1. 五子棋游戏开发

http://edu.csdn.net/course/detail/5487
2. RPG游戏从入门到精通
http://edu.csdn.net/course/detail/5246
3. WiX安装工具的使用
http://edu.csdn.net/course/detail/5207
4. 俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/5110
5. boost库入门基础
http://edu.csdn.net/course/detail/5029
6.Arduino入门基础
http://edu.csdn.net/course/detail/4931
7.Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/4810
8. TensorFlow API攻略
http://edu.csdn.net/course/detail/4495
9. TensorFlow入门基本教程
http://edu.csdn.net/course/detail/4369
10. C++标准模板库从入门到精通 
http://edu.csdn.net/course/detail/3324
11.跟老菜鸟学C++
http://edu.csdn.net/course/detail/2901
12. 跟老菜鸟学python
http://edu.csdn.net/course/detail/2592
13. 在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/2590
14. 在Windows下SVN的版本管理与实战 
http://edu.csdn.net/course/detail/2579
15.Visual Studio 2015开发C++程序的基本使用 
http://edu.csdn.net/course/detail/2570
16.在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/2582
17.在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672