zhoujinshi 发表于 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
页: [1]
查看完整版本: 指定范围内移动的窗口