#include <WinapiEx.au3>
#include <WindowsConstants.au3>
Global $iWidth = 400, $iHeight = 300
$hWnd = GUICreate('画直线,无法固定到GUI', $iWidth, $iHeight)
$iPic = GUICtrlCreatePic('', 0, 0, $iWidth, $iHeight)
$hPic = GUICtrlGetHandle($iPic)
GUISetState()
$hDC = _WinAPI_GetDC($hPic)
$hMemDC = _WinAPI_CreateCompatibleDC($hDC) ;建立兼容DC,即内存中的DC
$hBitmap = _WinAPI_CreateCompatibleBitmapEx($hDC, $iWidth, $iHeight, _WinAPI_SwitchColor(_WinAPI_GetSysColor($COLOR_3DFACE))) ;创建hBitmap
$hSv = _WinAPI_SelectObject($hMemDC, $hBitmap) ;调入DC作图对象,即把图形画在$hBitmap上
$hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x00FFFF)
$oPen = _WinAPI_SelectObject($hMemDC, $hPen)
_WinAPI_DrawLine($hMemDC, 20, 27, 26, 27)
_WinAPI_DrawLine($hMemDC, 67, 27, 300, 27)
_WinAPI_DrawLine($hMemDC, 300, 27, 300, 108)
_WinAPI_DrawLine($hMemDC, 20, 109, 300, 109)
_WinAPI_DrawLine($hMemDC, 20, 27, 20, 108)
;释放创建的对象及DC
_WinAPI_SelectObject($hMemDC, $hSv)
_WinAPI_SelectObject($hMemDC, $oPen)
_WinAPI_DeleteDC($hMemDC)
_WinAPI_ReleaseDC($hPic, $hDC)
;设置hBitmap到pic控件
$oldObj = _SendMessage($hPic, 0x0172, 0, $hBitmap) ;$STM_SETIMAGE = 0x0172
_WinAPI_DeleteObject($oldObj)
Local $hObj = _SendMessage($hPic, 0x0173) ;$STM_GETIMAGE = 0x0173
If $hObj <> $hBitmap Then
_WinAPI_DeleteObject($hBitmap)
EndIf
While True
$msg = GUIGetMsg()
Switch $msg
Case -3
Exit
EndSwitch
WEnd