smooth 发表于 2019-12-14 10:05:18

_WinAPI_DrawLine画的线无法固定到GUI【已解决】

本帖最后由 smooth 于 2019-12-15 08:57 编辑

_WinAPI_DrawLine画的线无法固定到GUI,每当界面最小化再弹起,画的线就消失了。论坛搜索_WinAPI_DrawLine,显示“对不起,没有找到匹配结果。”
谢谢!

#include <APIConstants.au3>
#include <WinAPIEx.au3>
GUICreate('画直线,无法固定到GUI', 400, 300)
GUISetState(@SW_SHOW)
;画状态栏的一根直线和竖线
$ctrlId = GUICtrlCreatePic("", 0, 0)
$hWnd = GUICtrlGetHandle($ctrlId)
$hDC = _WinAPI_GetDC($hWnd)
$hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x00FFFF)
$oldPen = _WinAPI_SelectObject($hDC, $hPen)
_WinAPI_DrawLine($hDC, 20, 27, 26, 27)
_WinAPI_DrawLine($hDC, 67, 27, 300, 27)
_WinAPI_DrawLine($hDC, 300, 27, 300, 108)
_WinAPI_DrawLine($hDC, 20, 109, 300, 109)
_WinAPI_DrawLine($hDC, 20, 27, 20, 108)
;画状态栏的一根直线和竖线
$ctrlId = GUICtrlCreatePic("", 0, 0)
$hWnd = GUICtrlGetHandle($ctrlId)
$hDC = _WinAPI_GetDC($hWnd)
$hPen = _WinAPI_CreatePen($PS_SOLID, 2, 0x00FFFF)
$oldPen = _WinAPI_SelectObject($hDC, $hPen)
_WinAPI_DrawLine($hDC, 0, 574, 640, 574)
_WinAPI_DrawLine($hDC, 484, 574, 484, 600)
While True
$msg = GUIGetMsg()
Switch $msg
Case -3
   Exit
EndSwitch
WEnd

水木子 发表于 2019-12-14 12:35:02

本帖最后由 水木子 于 2019-12-14 12:36 编辑

#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

smooth 发表于 2019-12-14 15:34:30

水木子 发表于 2019-12-14 12:35
#include
#include



厉害,谢谢水版。
页: [1]
查看完整版本: _WinAPI_DrawLine画的线无法固定到GUI【已解决】