找回密码
 加入
搜索
查看: 1827|回复: 2

[网络通信] _WinAPI_DrawLine画的线无法固定到GUI【已解决】

[复制链接]
发表于 2019-12-14 10:05:18 | 显示全部楼层 |阅读模式
本帖最后由 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
 楼主| 发表于 2019-12-14 15:34:30 | 显示全部楼层

厉害,谢谢水版。
您需要登录后才可以回帖 登录 | 加入

本版积分规则

QQ|手机版|小黑屋|AUTOIT CN ( 鲁ICP备19019924号-1 )谷歌 百度

GMT+8, 2024-11-16 08:52 , Processed in 0.104402 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表