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

该函数的原型如下: 
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/54872. RPG游戏从入门到精通
http://edu.csdn.net/course/detail/5246
3. WiX安装工具的使用
http://edu.csdn.net/course/detail/52074. 俄罗斯方块游戏开发
http://edu.csdn.net/course/detail/51105. boost库入门基础
http://edu.csdn.net/course/detail/50296.Arduino入门基础
http://edu.csdn.net/course/detail/49317.Unity5.x游戏基础入门
http://edu.csdn.net/course/detail/48108. TensorFlow API攻略
http://edu.csdn.net/course/detail/44959. TensorFlow入门基本教程
http://edu.csdn.net/course/detail/436910. C++标准模板库从入门到精通 
http://edu.csdn.net/course/detail/332411.跟老菜鸟学C++
http://edu.csdn.net/course/detail/290112. 跟老菜鸟学python
http://edu.csdn.net/course/detail/259213. 在VC2015里学会使用tinyxml库
http://edu.csdn.net/course/detail/259014. 在Windows下SVN的版本管理与实战 
http://edu.csdn.net/course/detail/257915.Visual Studio 2015开发C++程序的基本使用 
http://edu.csdn.net/course/detail/257016.在VC2015里使用protobuf协议
http://edu.csdn.net/course/detail/258217.在VC2015里学会使用MySQL数据库
http://edu.csdn.net/course/detail/2672

关于VC中LineDDA函数的调用的更多相关文章

  1. 转:VC中UpdateData()函数的使用

    VC中UpdateData()函数的使用 UpdateData(FALSE)与UpdateData(TRUE)是相反的过程     UpdateData(FALSE)是把程序中改变的值更新到控件中去  ...

  2. java中main函数怎么调用外部非static方法

    使用外部方法时(不管是static还是非static),都要先new一个对象,才能使用该对象的方法. 举例如下: 测试函数(这是错误的): public class Test { public sta ...

  3. 关于MFC中重载函数是否调用基类相对应函数的问题

    在重载CDialog的OnInitDialog()函数的时候,在首行会添加一句:CDialongEx::OnInitDialog();语句,这是为什么呢?什么时候添加,什么时候不添加? 实际上,我们在 ...

  4. VC中function函数解析

    C++标准库是日常应用中非常重要的库,我们会用到C++标准库的很多组件,C++标准库的作用,不单单是一种可以很方便使用的组件,也是我们学习很多实现技巧的重要宝库.我一直对C++很多组件的实现拥有比较强 ...

  5. PHP中嵌套函数被调用时出现报错的问题

    对于初入门的PHP新手来说,在学习关于PHP函数嵌套的知识点时可能会有一定的难度.比如有的朋友在练习PHP函数嵌套相关问题时,会遇到调用内部函数时就会出现报错的情况等. 那么本篇文章就为大家详细得分析 ...

  6. Java中, 函数的调用、随机数字

    函数:     独立完成某个功能的代码模块.(方法) 作用是为了让代码结构更加良好.模块清晰,实现重用. 函数的四要素:名称,输入值,加工过程,返回值 Java中函数的语法 static 返回类型 函 ...

  7. Java中main函数只能调用同类中的静态方法?

    如果想调用本类中的非静态方法可以这么来写: public class TT{ public static void main(String[] args){ TT t = new TT(); t.fu ...

  8. C/C++中虚函数的调用

    代码: #include <iostream> using namespace std; class A{ public: virtual void print(){ cout<&l ...

  9. js中的写出想jquery中的函数一样调用

    1.IIFE: Immediately-Invoked function Expression 函数模块自调用 2.代码实现 <!DOCTYPE html> <html lang=& ...

随机推荐

  1. java之简单工厂

    1.使用步骤 创建抽象/接口产品类,定义具体产品的公共接口方法:(产品接口类) 创建具体产品类,是继承抽象产品类的:(产品接口实现类) 创建工厂类,通过创建静态方法根据传入不同参数从而创建不同具体产品 ...

  2. 120. Triangle(动态规划 三角形最小路径 难 想)

    Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent n ...

  3. 【运维技术】windows安装apache服务器,实现域名对应端口的解析跳转

    linux 安装参考搭建dede项目的功能 windows 安装虚拟机的指南参考:http://jingyan.baidu.com/article/29697b912f6539ab20de3cf8.h ...

  4. Git review :error: unpack failed: error Missing tree

    环境 git version 1.9.1 Gerrit Code Review (2.11.3) 1 2 现象 修改后调用 git review可以提交到Gerrit上,然后只要一用 git comm ...

  5. Ajax请求304问题

    ajax默认是开启缓存的,所以get请求如果路径一样,会先找缓存,如果缓存存在就用缓存. 解决方案: 1.在修改url为动态变化的,如url后面加一个&timestamp=Date.parse ...

  6. tomcat config https 443

    设置https: <Connector port="443" protocol="HTTP/1.1" SSLEnabled="true" ...

  7. 在 if 条件句中使用向量

    上述例子的函数中,都只输入了单一值.如果我们提供一个向量,那么这个函数将产生警告,这是因为 if 语句不能与多值向量共存.check_ _positive(c(1,-1,0))## Warning i ...

  8. WPF特效和例子

    https://www.cnblogs.com/AaronYang/p/4710428.html

  9. 将keras模型在django中应用时出现的小问题——ValueError: Tensor Tensor("dense_2/Softmax:0", shape=(?, 8), dtype=float32) is not an element of this graph.

    本文原出处(感谢作者提供):https://zhuanlan.zhihu.com/p/27101000 将keras模型在django中应用时出现的小问题 王岳王院长 10 个月前 keras 一个做 ...

  10. 剑指 offer面试题20 顺时针打印矩阵

    [题目描述] 输入一个矩阵,按照从外向里以顺时针的顺序依次打印出每一个数字,例如,如果输入如下矩阵: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 则依次打印出数字1, ...