函数参考


_WinAPI_LineDDA

确定直线上的高亮像素

#Include <WinAPIEx.au3>
_WinAPI_LineDDA ( $X1, $Y1, $X2, $Y2, $pLineProc [, $pData] )

参数

$X1 直线起点的逻辑单位x坐标
$Y1 直线起点的逻辑单位y坐标
$X2 直线终点的逻辑单位x坐标
$Y2 直线终点的逻辑单位y坐标
$pLineProc 预定义回调函数的指针
$pData [可选参数] 应用程序定义的数据的指针

返回值

成功: 返回 1
失败: 返回 0设置@error 非0

注意/说明

_WinAPI_LineDDA()函数传递沿直线每个点的坐标给应用程序预定义的回调函数, 线终点除外. 除了传递点坐标, 该函数传递任何存在的应用程序定义的数据.

相关

详情参考

在MSDN中搜索


示例/演示


#Include <APIConstants.au3>
#Include <WinAPIEx.au3>

Opt('MustDeclareVars', 1)

Global Const $STM_SETIMAGE = 0x0172
Global Const $STM_GETIMAGE = 0x0173

Global $hForm, $Pic, $hPic, $hObj, $hBitmap, $hPen, $hDC, $hMemDC, $hMemSv, $Count = 0, $Color = True
Global $hLineProc = DllCallbackRegister('_LineProc', 'none', 'int;int;lparam')
Global $pLineProc = DllCallBackGetPtr($hLineProc)

; 创建 GUI
$hForm = GUICreate('MyGUI', 280, 280)
$Pic = GUICtrlCreatePic('', 0, 0, 281, 281)
$hPic = GUICtrlGetHandle($Pic)

; 创建位图
$hDC = _WinAPI_GetDC($hPic)
$hMemDC = _WinAPI_CreateCompatibleDC($hDC)
$hBitmap = _WinAPI_CreateCompatibleBitmapEx($hDC, 280, 280, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE)))
$hMemSv = _WinAPI_SelectObject($hMemDC, $hBitmap)
_WinAPI_LineDDA(40, 40, 240, 40, $pLineProc, $hMemDC)
_WinAPI_LineDDA(240, 40, 240, 240, $pLineProc, $hMemDC)
_WinAPI_LineDDA(240, 240, 40, 240, $pLineProc, $hMemDC)
_WinAPI_LineDDA(40, 240, 40, 40, $pLineProc, $hMemDC)
_WinAPI_ReleaseDC($hPic, $hDC)
_WinAPI_SelectObject($hMemDC, $hMemSv)
_WinAPI_DeleteDC($hMemDC)

; 设置位图到控件
_SendMessage($hPic, $STM_SETIMAGE, 0, $hBitmap)
$hObj = _SendMessage($hPic, $STM_GETIMAGE)
If $hObj <> $hBitmap Then
    _WinAPI_DeleteObject($hBitmap)
EndIf

GUISetState()

Do
Until GUIGetMsg() = -3

DllCallbackFree($hLineProc)

Func _LineProc($iX, $iY, $hDC)
    If Not Mod($Count, 10) Then
        $Color = Not $Color
    EndIf
    If $Color Then
        _WinAPI_SetPixel($hDC, $iX, $iY, 0xFF0000)
    Else
        _WinAPI_SetPixel($hDC, $iX, $iY, 0xFFFFFF)
    EndIf
    $Count += 1
EndFunc   ;==>_LineProc