Jump to content

Draggable windows


Dampe
 Share

Recommended Posts

Try this:

#include <GuiConstants.au3>
#include <WindowsConstants.au3>

;Global Const $HTCLIENT = 0x1
;Global Const $HTCAPTION = 0x2

$hGui = GUICreate("Test", 300, 200)

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

GUISetState()

Do
Until GUIGetMsg() = -3

Func WM_NCHITTEST($hWnd, $Msg, $wParam, $lParam)
    Local $iProc
    
    $iProc = DllCall("user32.dll", "int", "DefWindowProc", "hwnd", $hWnd, "int", $Msg, "wparam", $wParam, "lparam", $lParam)
    $iProc = $iProc[0]
    
    If $iProc = $HTCLIENT Then Return $HTCAPTION
    
    Return $GUI_RUNDEFMSG
EndFunc
Link to comment
Share on other sites

like this :)

CODE

#include <GuiConstants.au3>

#include <WindowsConstants.au3>

Opt ("GUIOnEventMode", 1)

;$GUI_EVENT_CLOSE

;$GUI_EVENT_MINIMIZE

;$GUI_EVENT_RESTORE

;$GUI_EVENT_MAXIMIZE

;$GUI_EVENT_PRIMARYDOWN

;$GUI_EVENT_PRIMARYUP

;$GUI_EVENT_SECONDARYDOWN

;$GUI_EVENT_SECONDARYUP

;$GUI_EVENT_MOUSEMOVE

;$GUI_EVENT_RESIZED

;$GUI_EVENT_DROPPED

;Global Const $HTCLIENT = 0x1

;Global Const $HTCAPTION = 0x2

Global $MousePos, $WinPos, $PosDiff[2]

Global $user32_dll = DllOpen ("user32.dll")

$hGui = GUICreate("Test", 300, 200,-1,-1,BitOR($WS_POPUP, $WS_BORDER))

TrayTip ( "", "Click left button to move and right button to exit",30)

GUISetOnEvent($GUI_EVENT_PRIMARYDOWN, "_MoveGui")

GUISetOnEvent($GUI_EVENT_SECONDARYDOWN, "_Exit")

GUIRegisterMsg($WM_NCHITTEST, "WM_NCHITTEST")

GUISetState()

While 1

Sleep(100)

WEnd

Func WM_NCHITTEST($hWnd, $Msg, $wParam, $lParam)

Local $iProc

$iProc = DllCall("user32.dll", "int", "DefWindowProc", "hwnd", $hWnd, "int", $Msg, "wparam", $wParam, "lparam", $lParam)

$iProc = $iProc[0]

If $iProc = $HTCLIENT Then Return $HTCAPTION

Return $GUI_RUNDEFMSG

EndFunc

func _MoveGui()

GUISetCursor (9, 1)

While 1

$MousePos = MouseGetPos ()

$WinPos = WinGetPos ("Test")

$PosDiff[0] = $WinPos[0] - $MousePos[0]

$PosDiff[1] = $WinPos[1] - $MousePos[1]

If _IsPressed ("01", $user32_dll) Then

While _IsPressed ("01", $user32_dll)

$MousePos = MouseGetPos ()

WinMove ("Test", "", $MousePos[0] + $PosDiff[0], $MousePos[1] + $PosDiff[1])

$WinPos = WinGetPos ("Test")

Sleep (10)

WEnd

GUISetCursor ()

ExitLoop

EndIf

Sleep (10)

WEnd

EndFunc

Func _IsPressed($s_hexKey, $v_dll = 'user32.dll')

Local $a_R = DllCall($v_dll, "int", "GetAsyncKeyState", "int", '0x' & $s_hexKey)

If Not @error And BitAND($a_R[0], 0x8000) = 0x8000 Then Return 1

Return 0

EndFunc ;==>_IsPressed

Func _Exit()

MsgBox(0,"","exit...",1)

Exit

EndFunc

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...