Sign in to follow this  
Followers 0
Justmobile

Drag drop multiple windows

5 posts in this topic

Hi all,

im not so good at dll calls e.t.

but i have a code which create a simple gui window, when i run this multiple times de desktop will show many gui's

simple, but when i drag one window the focus of the mouse is gone, and i have click and try to catch the window which i want to move.

for dragging i use code

While _IsPressed("01")

DllCall("user32.dll", "int", "SendMessage", "hWnd", WinGetHandle("[ACTIVE]"), "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)

and gui create

$Gui = GUICreate($title, 180, 15, $Gui_X, $Gui_Y, $WS_POPUP, $WS_EX_TOOLWINDOW, WinGetHandle("[CLASS:Progman]"))

GUISetBkColor(0xFFA500)

please notice that multiple gui's have all the name $Gui, because i run the program more than ones.

can this do?

thanks

Share this post


Link to post
Share on other sites



Hi all,

im not so good at dll calls e.t.

but i have a code which create a simple gui window, when i run this multiple times de desktop will show many gui's

simple, but when i drag one window the focus of the mouse is gone, and i have click and try to catch the window which i want to move.

for dragging i use code

While _IsPressed("01")

DllCall("user32.dll", "int", "SendMessage", "hWnd", WinGetHandle("[ACTIVE]"), "int", $WM_NCLBUTTONDOWN, "int", $HTCAPTION, "int", 0)

and gui create

$Gui = GUICreate($title, 180, 15, $Gui_X, $Gui_Y, $WS_POPUP, $WS_EX_TOOLWINDOW, WinGetHandle("[CLASS:Progman]"))

GUISetBkColor(0xFFA500)

please notice that multiple gui's have all the name $Gui, because i run the program more than ones.

can this do?

thanks

Here is one way to do it. I added a bit so that the gui names could all be different, but that won't affect the way this example works.

You will need to move one gui out of the way before the next instance is started or you will never see the previous instance.

#include <guiconstantsEx.au3>
#include <windowsconstants.au3>
#include <misc.au3>
#include <sendmessage.au3>
Global Const $WM_BROADCAST = 0xFFFF
Global Const $WM_ENTERSIZEMOVE = 0x231


$gui = GUICreate("drag group", 250, 70)
$Lab1 = GUICtrlCreateLabel("no message", 20, 12)
$ButF = GUICtrlCreateButton("Finish", 20, 40, 120, 26)
GUISetState()

Global $master = 0

#Region make unique title - not required
Local $instance = True, $inst = 0
While $instance = True
    $inst += 1
    _Singleton("dragmany_script" & $inst, 1)
    $instance = @error = 183
WEnd
WinSetTitle("drag group", "", "drag No. " & $inst & " of group")
#EndRegion make unique title


;get a message number to use
$MyMsg1 = RegisterWindowMessage("drawmanywindows")
GUIRegisterMsg($MyMsg1, "GetDrag")


GUIRegisterMsg($WM_ENTERSIZEMOVE, "EnterSIzeMove")

While 1
    $Msg = GUIGetMsg()
    If $Msg = -3 Then Exit

    If $master <> 0 Then
        DoCatchup()
    EndIf

    if $Msg = $ButF Then
        _SendMessage($WM_BROADCAST,$MyMsg1,$Gui,2)
        Exit
    EndIf


WEnd


Func EnterSizeMove($hW, $iM, $WP, $Lp)
    _SendMessage($WM_BROADCAST, $MyMsg1, $gui, 1)
EndFunc   ;==>EnterSizeMove

Func GetDrag($hW, $iM, $WP, $Lp)
    if $Lp = 1 Then
    $master = $WP
    GUICtrlSetData($Lab1, "Messages from " & Hex($master))
EndIf
if $Lp = 2 Then
    Exit
    EndIf
EndFunc   ;==>GetDrag


Func DoCatchup()
    $Mp = WinGetPos($master)
    $Sp = WinGetPos($gui)
    While _IsPressed(01)
        $Np = WinGetPos($master)
        WinMove($gui, "", $Sp[0] + $Np[0] - $Mp[0], $Sp[1] + $Np[1] - $Mp[1])
    WEnd
    $master = 0

EndFunc   ;==>DoCatchup


;register window message
;returns a unique message number. if the message has already been registered then the
;the unique number for $stext is returned.
;Usefule for two windows to communicate
Func RegisterWindowMessage($sText)
    Local $aRet = DllCall('user32.dll', 'int', 'RegisterWindowMessage', 'str', $sText)
    Return $aRet[0]
EndFunc   ;==>RegisterWindowMessage

Serial port communications UDF Includes functions for binary transmission and reception.printing UDF Useful for graphs, forms, labels, reports etc.Add User Call Tips to SciTE for functions in UDFs not included with AutoIt and for your own scripts.Functions with parameters in OnEvent mode and for Hot Keys One function replaces GuiSetOnEvent, GuiCtrlSetOnEvent and HotKeySet.UDF IsConnected2 for notification of status of connected state of many urls or IPs, without slowing the script.

Share this post


Link to post
Share on other sites

nice example martin!!

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Here is one way to do it. I added a bit so that the gui names could all be different, but that won't affect the way this example works.

You will need to move one gui out of the way before the next instance is started or you will never see the previous instance.

#include <guiconstantsEx.au3>
#include <windowsconstants.au3>
#include <misc.au3>
#include <sendmessage.au3>
Global Const $WM_BROADCAST = 0xFFFF
Global Const $WM_ENTERSIZEMOVE = 0x231


$gui = GUICreate("drag group", 250, 70)
$Lab1 = GUICtrlCreateLabel("no message", 20, 12)
$ButF = GUICtrlCreateButton("Finish", 20, 40, 120, 26)
GUISetState()

Global $master = 0

#Region make unique title - not required
Local $instance = True, $inst = 0
While $instance = True
    $inst += 1
    _Singleton("dragmany_script" & $inst, 1)
    $instance = @error = 183
WEnd
WinSetTitle("drag group", "", "drag No. " & $inst & " of group")
#EndRegion make unique title


;get a message number to use
$MyMsg1 = RegisterWindowMessage("drawmanywindows")
GUIRegisterMsg($MyMsg1, "GetDrag")


GUIRegisterMsg($WM_ENTERSIZEMOVE, "EnterSIzeMove")

While 1
    $Msg = GUIGetMsg()
    If $Msg = -3 Then Exit

    If $master <> 0 Then
        DoCatchup()
    EndIf

    if $Msg = $ButF Then
        _SendMessage($WM_BROADCAST,$MyMsg1,$Gui,2)
        Exit
    EndIf


WEnd


Func EnterSizeMove($hW, $iM, $WP, $Lp)
    _SendMessage($WM_BROADCAST, $MyMsg1, $gui, 1)
EndFunc   ;==>EnterSizeMove

Func GetDrag($hW, $iM, $WP, $Lp)
    if $Lp = 1 Then
    $master = $WP
    GUICtrlSetData($Lab1, "Messages from " & Hex($master))
EndIf
if $Lp = 2 Then
    Exit
    EndIf
EndFunc   ;==>GetDrag


Func DoCatchup()
    $Mp = WinGetPos($master)
    $Sp = WinGetPos($gui)
    While _IsPressed(01)
        $Np = WinGetPos($master)
        WinMove($gui, "", $Sp[0] + $Np[0] - $Mp[0], $Sp[1] + $Np[1] - $Mp[1])
    WEnd
    $master = 0

EndFunc   ;==>DoCatchup


;register window message
;returns a unique message number. if the message has already been registered then the
;the unique number for $stext is returned.
;Usefule for two windows to communicate
Func RegisterWindowMessage($sText)
    Local $aRet = DllCall('user32.dll', 'int', 'RegisterWindowMessage', 'str', $sText)
    Return $aRet[0]
EndFunc   ;==>RegisterWindowMessage

Nice example, martin. But WM_BROADCAST works very slowly (depending on the number of windows). I think in this case will be better to use the window handle. Edited by Yashied

Share this post


Link to post
Share on other sites

Here is one way to do it. I added a bit so that the gui names could all be different, but that won't affect the way this example works.

You will need to move one gui out of the way before the next instance is started or you will never see the previous instance.

#include <guiconstantsEx.au3>
#include <windowsconstants.au3>
#include <misc.au3>
#include <sendmessage.au3>
Global Const $WM_BROADCAST = 0xFFFF
Global Const $WM_ENTERSIZEMOVE = 0x231


$gui = GUICreate("drag group", 250, 70)
$Lab1 = GUICtrlCreateLabel("no message", 20, 12)
$ButF = GUICtrlCreateButton("Finish", 20, 40, 120, 26)
GUISetState()

Global $master = 0

#Region make unique title - not required
Local $instance = True, $inst = 0
While $instance = True
    $inst += 1
    _Singleton("dragmany_script" & $inst, 1)
    $instance = @error = 183
WEnd
WinSetTitle("drag group", "", "drag No. " & $inst & " of group")
#EndRegion make unique title


;get a message number to use
$MyMsg1 = RegisterWindowMessage("drawmanywindows")
GUIRegisterMsg($MyMsg1, "GetDrag")


GUIRegisterMsg($WM_ENTERSIZEMOVE, "EnterSIzeMove")

While 1
    $Msg = GUIGetMsg()
    If $Msg = -3 Then Exit

    If $master <> 0 Then
        DoCatchup()
    EndIf

    if $Msg = $ButF Then
        _SendMessage($WM_BROADCAST,$MyMsg1,$Gui,2)
        Exit
    EndIf


WEnd


Func EnterSizeMove($hW, $iM, $WP, $Lp)
    _SendMessage($WM_BROADCAST, $MyMsg1, $gui, 1)
EndFunc   ;==>EnterSizeMove

Func GetDrag($hW, $iM, $WP, $Lp)
    if $Lp = 1 Then
    $master = $WP
    GUICtrlSetData($Lab1, "Messages from " & Hex($master))
EndIf
if $Lp = 2 Then
    Exit
    EndIf
EndFunc   ;==>GetDrag


Func DoCatchup()
    $Mp = WinGetPos($master)
    $Sp = WinGetPos($gui)
    While _IsPressed(01)
        $Np = WinGetPos($master)
        WinMove($gui, "", $Sp[0] + $Np[0] - $Mp[0], $Sp[1] + $Np[1] - $Mp[1])
    WEnd
    $master = 0

EndFunc   ;==>DoCatchup


;register window message
;returns a unique message number. if the message has already been registered then the
;the unique number for $stext is returned.
;Usefule for two windows to communicate
Func RegisterWindowMessage($sText)
    Local $aRet = DllCall('user32.dll', 'int', 'RegisterWindowMessage', 'str', $sText)
    Return $aRet[0]
EndFunc   ;==>RegisterWindowMessage

Thanks, for the help, i can now continue again...

Share this post


Link to post
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
Sign in to follow this  
Followers 0