关于VC中LineDDA函数的调用

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

该函数的原型如下: 
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 function

The LineDDA function determines which pixels should be highlighted for a line defined by the specified starting and ending points.
Syntax
C++

BOOL LineDDA(
  _In_ int         nXStart,
  _In_ int         nYStart,
  _In_ int         nXEnd,
  _In_ int         nYEnd,
  _In_ LINEDDAPROC lpLineFunc,
  _In_ LPARAM      lpData
);

Parameters
nXStart [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 value
If the function succeeds, the return value is nonzero.
If the function fails, the return value is zero.
Remarks
The 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.
Requirements
Minimum supported client
Windows 2000 Professional [desktop apps only]
Minimum supported server
Windows 2000 Server [desktop apps only]
Header
Wingdi.h (include Windows.h)
Library
Gdi32.lib
DLL
Gdi32.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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

caimouse

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值