找回密码
 加入
搜索
查看: 1567|回复: 0

[AU3基础] 指定范围内移动的窗口

[复制链接]
发表于 2013-12-21 13:16:53 | 显示全部楼层 |阅读模式
本帖最后由 zhoujinshi 于 2013-12-22 14:14 编辑
#include <StructureConstants.au3>
#include <WindowsConstants.au3>
#include <WinApi.au3>

Local $iWidth = 400, $iHeight = 300
Local $iStyle = BitOR($WS_MINIMIZEBOX, $WS_MAXIMIZEBOX, $WS_SIZEBOX)
$hGUI = GUICreate("Test", $iWidth, $iHeight, -1, -1, $iStyle)
GUISetState()

GUIRegisterMsg(0x216, "WM_MOVING")
GUIRegisterMsg($WM_SIZE, "WM_SIZE")

While GUIGetMsg() <> -3
WEnd

Func WM_SIZE($hWnd, $iMsg, $iwParam, $ilParam)
        ;$iWidth = BitAnd($ilParam, 0xFFFF)
        ;$iHeight = BitShift($ilParam, 0x10)
EndFunc   ;==>WM_SIZE

Func WM_MOVING($hWnd, $iMsg, $iwParam, $ilParam)
        Local $tBuffer, $iLeft, $iTop, $iRight, $iBottom
        Local $tRect, $iWidth, $iHeight

        $tBuffer = DllStructCreate($tagRECT, $ilParam)
        $iLeft = DllStructGetData($tBuffer, "Left")
        $iTop = DllStructGetData($tBuffer, "Top")
        $iRight = DllStructGetData($tBuffer, "Right")
        $iBottom = DllStructGetData($tBuffer, "Bottom")
        
        $tRect = _WinAPI_GetWindowRect($hWnd)
        $iWidth = DllStructGetData($tRect, "Right") - DllStructGetData($tRect, "Left")
        $iHeight = DllStructGetData($tRect, "Bottom") - DllStructGetData($tRect, "Top")
        ;$iWidth = _WinAPI_GetWindowWidth($hWnd)
        ;$iHeight = _WinAPI_GetWindowHeight($hWnd)
        ConsoleWrite($iWidth & "," & $iHeight & @CRLF)

        If ($iLeft < 0) Then
                DllStructSetData($tBuffer, "Left", 0)
                DllStructSetData($tBuffer, "Right", $iWidth)
        ElseIf ($iRight > @DesktopWidth) Then
                DllStructSetData($tBuffer, "Left", @DesktopWidth - $iWidth)
                DllStructSetData($tBuffer, "Right", @DesktopWidth)
        EndIf
        If ($iTop < 0) Then
                DllStructSetData($tBuffer, "Top", 0)
                DllStructSetData($tBuffer, "Bottom", $iHeight)
        ElseIf ($iBottom > @DesktopHeight - 35) Then
                DllStructSetData($tBuffer, "Top", @DesktopHeight - $iHeight - 35)
                DllStructSetData($tBuffer, "Bottom", @DesktopHeight - 35)
        EndIf
        $tBuffer = 0
EndFunc   ;==>WM_MOVING
您需要登录后才可以回帖 登录 | 加入

本版积分规则

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

GMT+8, 2024-9-28 15:21 , Processed in 0.084299 second(s), 19 queries .

Powered by Discuz! X3.5 Licensed

© 2001-2024 Discuz! Team.

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