请教LineDDA的用法(50分)

Y

yysun

Unregistered / Unconfirmed
GUEST, unregistred user!
Win API中的LineDDA是如何使用的?可以提供个例子吗?
 
老孙一定知道常用的画线算法(DDA)是怎么一回事, LineDDA是用用户的DDA来代替
GDI中的DDA来画某些特殊效果的线(我从来没用过).

从MSDN中查到一段例子, 贴到这里吧:

BOOL LineDDA(
int nXStart, // x-coordinate of line's starting point
int nYStart, // y-coordinate of line's starting point
int nXEnd, // x-coordinate of line's ending point
int nYEnd, // y-coordinate of line's ending point
LINEDDAPROC lpLineFunc, // pointer to callback function
LPARAM lpData // pointer to application-defined data);

The following code fragment draws 50 random Excel-style lines. Note
that the LineProc function must be listed as an EXPORT in the module
definition (DEF) file:

case WM_PAINT:
{
HDC hDC;
int nIndex;
PAINTSTRUCT ps;

hDC = BeginPaint(hWnd, &ps);
for (nIndex = 0; nIndex < 50; nIndex++)
LineDDA(rand() / 110, rand() / 110, rand() / 110,
rand() / 110, lpfnLineProc, (LPSTR)hDC);
EndPaint(hWnd, &amp;ps);
break;
}

void FAR PASCAL LineProc(x, y, lpData)
short x, y; LPSTR lpData; {
static short nTemp = 0;

if (nTemp == 1)
SetPixel((HDC)lpData, x, y, 0L);

nTemp = (nTemp + 1) % 2;
}
从这个例子里面可以看出, lpData实际上是HDC.
 
void WINAPI LineDDA(int,int,int,int,LINEDDAPROC,LPARAM)

LineDDA函数用来做动画特别方便,前四个参数指定屏幕上任意两点坐标,
此函数将以Bresenham算法计算出通过两点的每一个屏幕像素坐标,
每计算出一个坐标,就调用第五个参数指定CALLBACK函数

这个函数类型是
void (CALLBACK* LINEDDAPROC)(int,int,LPARAM);

Windows的接龙游戏结束时的动画就由这个函数完成

例子吗...有
C++的

 
顶部