Fenster Drag & Drop

  • Hi com,

    ich habe lange nichts mehr gefragt, es war auch nie wirklich nötig.
    Aber jetzt bin ich ratlos. Dieses Beispiel is nur simpel gehalten, aber es will einfach nicht funktionieren, warum?

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <Misc.au3>
    HotKeySet("{F3}", "_Exit")
    Global $hWnd = GUICreate("Untitled", 100, 100, Default, Default, -$WS_POPUP)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUISetState(@SW_SHOW)
    While 1
    _WinAPI_CheckWinMove($hWnd)
    WEnd
    Func _Exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _WinAPI_CheckWinMove
    ; Description ...: Checks if a Gui need to move While dragging
    ; Syntax.........: _WinAPI_CheckWinMove($hWnd[, $sMCode])
    ; Parameters ....: $hWnd - Handle to the Gui
    ; [optional] $sMCode - Code of Button (Please use Mouse Codes) for func _Ispressed()
    ; Return values .: none
    ; Author ........: black_skorpi
    ; Modified.......:
    ; Remarks .......: Pauses the Script
    ; Related .......:
    ; Link ..........:
    ; Example .......: Yes
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_CheckWinMove($hWnd, $sMCode = "01")
    Global $aMPos, $aWPos, $aMPosOld = MouseGetPos()
    While _IsPressed("01")
    $aMPos = MouseGetPos()
    $aWPos = WinGetPos(WinGetTitle($hWnd, ""))
    If Not ($aMPos[0] = $aMPosOld) And ($aMPos[1] = $aMPosOld[1]) Then
    WinMove(WinGetTitle($hWnd, ""), "", $aWPos[0] - ($aMPosOld[0] - $aMPos[0]), $aWPos[1] - ($aMPosOld[1] - $aMPos[1]), $aWPos[2], $aWPos[3])
    EndIf
    $aMPosOld = $aMPos
    WEnd
    EndFunc

    [/autoit]

    Das Fenster sollte sich mit der Maus bewegen, wenn man die linke Maustaste gedrückt hält.
    Dass das auch außerhalb eines Gui funktioniert, beachte ich noch nicht.

  • Versuchs doch mal so:

    [autoit]

    #include <WindowsConstants.au3>
    #include <GUIConstants.au3>
    #include <Misc.au3>
    HotKeySet("{F3}", "_Exit")
    Global $hWnd = GUICreate("Untitled", 100, 100, Default, Default, -$WS_POPUP)
    GUICtrlSetColor(-1, 0xFFFFFF)

    [/autoit][autoit][/autoit][autoit]

    GUICtrlCreateLabel("", 0, 0, 100, 100, -1, $GUI_WS_EX_PARENTDRAG)

    [/autoit][autoit][/autoit][autoit]

    GUISetState(@SW_SHOW)

    [/autoit][autoit][/autoit][autoit]

    While 1
    Sleep(10)
    WEnd
    Func _Exit()
    Exit
    EndFunc

    [/autoit]

    Das mit der Taste grdückt halten, kann man ja irgendwie implementieren ;)

  • versuch es mal hiermit:

    [autoit]

    #include <WindowsConstants.au3>
    #include <Misc.au3>
    #include <GUIConstantsEx.au3>
    Opt("GuiOnEventMode", 1)

    [/autoit][autoit][/autoit][autoit]

    HotKeySet("{F3}", "_Exit")

    [/autoit][autoit][/autoit][autoit]

    Global $hWnd = GUICreate("Untitled", 100, 100, Default, Default, -$WS_POPUP)
    GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "move")
    GUISetBkColor(0x000000, $hwnd)
    GUISetState(@SW_SHOW)
    $xys = WinGetHandle ("[ACTIVE]")
    While 1
    sleep(20);_WinAPI_CheckWinMove($hWnd)
    WEnd

    [/autoit][autoit][/autoit][autoit]

    func move()
    DllCall("user32.dll","int","SendMessage","hWnd", $xys,"int",$WM_NCLBUTTONDOWN,"int", $HTCAPTION,"int", 0)
    EndFunc

    [/autoit][autoit][/autoit][autoit]

    Func _Exit()
    Exit
    EndFunc

    [/autoit]
    • Offizieller Beitrag

    Versuch es mal so:

    Spoiler anzeigen
    [autoit]

    #include <WindowsConstants.au3>
    #include <Misc.au3>
    HotKeySet("{F3}", "_Exit")
    Global $hWnd = GUICreate("Untitled", 100, 100, Default, Default, -$WS_POPUP)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUISetState(@SW_SHOW)
    While 1
    _WinAPI_CheckWinMove($hWnd)
    WEnd
    Func _Exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit]

    ; #FUNCTION# ====================================================================================================================
    ; Name...........: _WinAPI_CheckWinMove
    ; Description ...: Checks if a Gui need to move While dragging
    ; Syntax.........: _WinAPI_CheckWinMove($hWnd[, $sMCode])
    ; Parameters ....: $hWnd - Handle to the Gui
    ; [optional] $sMCode - Code of Button (Please use Mouse Codes) for func _Ispressed()
    ; Return values .: none
    ; Author ........: black_skorpi
    ; Modified.......:
    ; Remarks .......: Pauses the Script
    ; Related .......:
    ; Link ..........:
    ; Example .......: Yes
    ; ===============================================================================================================================

    [/autoit] [autoit][/autoit] [autoit]

    Func _WinAPI_CheckWinMove($hWnd, $sMCode = "01")
    Global $aMPos, $aWPos, $aMPosOld = MouseGetPos()
    While _IsPressed("01")
    $aMPos = MouseGetPos()
    $aWPos = WinGetPos(WinGetTitle($hWnd, ""))
    If Not ($aMPos[0] = $aMPosOld[0]) And Not ($aMPos[1] = $aMPosOld[1]) Then
    WinMove(WinGetTitle($hWnd, ""), "", $aMPos[0] - $aWPos[2] /2 , $aMPos[1] - $aWpos[3]/2, $aWPos[2],$aWpos[3])
    EndIf
    $aMPosOld = $aMPos
    WEnd
    EndFunc

    [/autoit]
  • Oder so:

    Spoiler anzeigen
    [autoit]


    #include <WindowsConstants.au3>
    #include <Misc.au3>
    HotKeySet('{F3}', '_Exit')
    $x=100
    $y=100
    Global $hWnd = GUICreate('Untitled', $x, $y, Default, Default, -$WS_POPUP)
    GUICtrlSetColor(-1, 0xFFFFFF)
    GUISetState(@SW_SHOW)
    While 1
    Sleep(100)
    _WinMove($hWnd)
    WEnd
    Func _Exit()
    Exit
    EndFunc

    [/autoit] [autoit][/autoit] [autoit][/autoit] [autoit]

    Func _WinMove($hWnd, $sMCode = 01)
    Global $aMPos, $aWPos, $aMPosOld = MouseGetPos(), $acursorinfo
    While _IsPressed(01)
    $aMPos = MouseGetPos()
    $aWPos = WinGetPos(WinGetTitle($hWnd, ""))
    $acursorinfo=GUIGetCursorInfo($hWnd)
    if $acursorinfo[0] < $x and $acursorinfo[1] < $y then
    WinMove(WinGetTitle($hWnd, ""), "", $aWPos[0] - ($aMPosOld[0] - $aMPos[0]), $aWPos[1] - ($aMPosOld[1] - $aMPos[1]), $aWPos[2], $aWPos[3])
    EndIf
    $aMPosOld = $aMPos
    WEnd
    EndFunc

    [/autoit]
    • Offizieller Beitrag

    Warum so kompliziert?
    Einmal in die Hilfe geschaut:

    Zitat

    You can enable window draging for GUI without $WS_CAPTION by using $WS_EX_CONTROLPARENT in the exStyle parameter.

    und schon hast Du ein Fenster, dass sich auf Mausklick verschiebt:

    [autoit]


    #include <WindowsConstants.au3>
    $hGui = GUICreate('Test', 600, 400, -1, -1, $WS_POPUP, $WS_EX_CONTROLPARENT)
    GUISetBkColor(0xff0000)
    GUISetState()
    Do
    Until GUIGetMsg() = -3

    [/autoit]