@wolf_II , thank you for the script
just tried to add x y w h variable to the last example from iPhilip
( define the first and followed positions )
EDIT1 : attached 3 ahk GUI examples and 2 programs
EDIT2 : used last changed function
EDIT3: added a 2nd example : Listbox , send selected commands to DOS
Code: Select all
;- modified = 20180212
;- created = 20180208
#warn
#NoEnv
;#SingleInstance Force
setworkingdir,%a_scriptdir%
DetectHiddenWindows, ON
Handles := []
i=0
x1:=1
y1:=1
w1:=350
w1a:=(w1+7)
h1:=200
aa=a1,a2,a3
stringsplit,a,aa,`,
total1:=a0
;----- 3 AHK-GUI together ----------------------------------------
Loop, %total1%
{
Gui, %A_Index%: New, hwndhWin%A_Index%, Window %A_Index%
c:= % A%a_index%
if i=0
{
gosub,%c%
Gui, Show, x%x1% y%y1% w%w1% h%h1%,TEST-%a_index% ( -drag- )
}
else
{
gosub,%c%
Gui, Show, % "x" (I*w1a)+x1 . "y" . y1 . "w" . w1 . " h" . h1,TEST-%a_index% ( -drag- )
}
Handles.Push(hWin%A_Index%)
i++
}
;-------------------------------------------------------------------
;----------- next- attached window NOTEPAD ----------
diff:=27
x2:=x1
y2:=(y1+h1+diff)
w2:=(3*w1a)
h2:=200
Run, Notepad, , , pid1
WinWaitActive, ahk_pid %pid1%
sleep,200
WinMove, ahk_pid %pid1%, , x2, y2, w2, h2
;----------- next- attached window DOS ----------
x3:=x1
y3:=(y2+h2)
w3:=(3*w1a)
h3:=500
e4x=
(ltrim join&
dir
ver
)
title2=AutoHotkey DOS
;Run, %COMSPEC% /k %e4x%,,hide,pid2
Run %COMSPEC% /k "title %title2% & mode con lines=4048 cols=254&COLOR 02&CD\",,,pid2 ; define title / lines / colons / color
WinWaitActive, ahk_pid %pid2%
sleep,200
WinMove, ahk_pid %pid2%, , x3, y3, w3, h3
sleep,200
controlsend,,ver`n,ahk_pid %pid2%
;--------------------------------------------------------
Handles.Push(WinExist("A")) ;- dos is lastactive
IfWinNotActive ,ahk_pid %pid1%,,WinActivate,ahk_pid %pid1%
WinWaitActive,ahk_pid %pid1%
Handles.Push(WinExist("A")) ;- add notepad also
controlsend,,Line1`nLine2`n,ahk_pid %pid1%
MoveTogether(Handles)
Return
Esc::
GuiClose:
2GuiClose:
3GuiClose:
WinClose, ahk_pid %pid1%
WinWaitClose,ahk_pid %pid1%
WinClose, ahk_pid %pid2%
WinWaitClose,ahk_pid %pid2%
ExitApp
;==================== 3 GUI-Examples =====================================
a1:
Gui,1:default
;Gui,1: +AlwaysOnTop -Sysmenu
Gui,1: -Sysmenu
Gui,1:Color,Black
Gui,1:Color,ControlColor, Black
Gui,1:Font,s12 cYellow ,Lucida Console
Gui,1:add,Edit, x20 y10 w320 h100 left vInp1 ,test_1
Gui,1:add,Button, x20 y130 w100 h26 vB1 gB1 , Button1
return
a2:
Gui,2:default
;Gui,2: +AlwaysOnTop -Sysmenu
Gui,2: -Sysmenu
Gui,2:Color,Gray
Gui,2:Color,ControlColor, Gray
Gui,2:Font,s14 cBlack ,Lucida Console
Gui,2:add,Edit, x20 y10 w320 h100 left vInp2 ,test_2
Gui,2:add,Button, x20 y130 w100 h26 vB2 gB2 , Button2
return
a3:
Gui,3:default
;Gui,3: +AlwaysOnTop
Gui,3:Font,cDefault ,Fixedsys
Gui,3:Color,Teal
Gui,3:Color,ControlColor, Teal
Gui,3:add,Edit, x20 y10 w320 h100 cBlack left vInp3 ,test_3
Gui,3:add,Button, x20 y130 w100 h26 vB3 gB3 , Button3
return
B1:
msgbox,Button1
return
B2:
msgbox,Button2
return
B3:
msgbox,Button3
return
;========== END 3- GUI examples ===========================================
;-------------------------------------------------------------------------------
MoveTogether(wParam, lParam = "", _ = "", hWnd = "") { ; using DeferWindowPos
;-------------------------------------------------------------------------------
; call MoveTogether(Handles) with an array of handles
; to set up a bundle of AHK Gui's that move together
;---------------------------------------------------------------------------
; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402
; version 2018.02.08
static init := OnMessage(0xA1, "MoveTogether") ; WM_NCLBUTTONDOWN
static Handles
If IsObject(wParam) ; detect a set up call
Return, Handles := wParam ; store the array of handles
If (wParam != 2) ; HTCAPTION
Return
; changing AHK settings here will have no side effects
CoordMode, Mouse, Screen ; for MouseGetPos
SetBatchLines, -1 ; for onMessage
SetWinDelay, -1 ; for WinActivate, WinMove
M_old_X := lParam & 0xFFFF, M_old_Y := lParam >> 16 & 0xFFFF
WinActivate, ahk_id %hWnd%
Win := {}
For each, Handle in Handles {
WinGetPos, X, Y, W, H, ahk_id %Handle%
Win[Handle] := {X: X, Y: Y, W: W, H: H}
}
While GetKeyState("LButton", "P") {
MouseGetPos, M_new_X, M_new_Y
dX := M_new_X - M_old_X, M_old_X := M_new_X
, dY := M_new_Y - M_old_Y, M_old_Y := M_new_Y
If GetKeyState("Shift", "P")
WinMove, ahk_id %hWnd%,, Win[hWnd].X += dX, Win[hWnd].Y += dY
Else { ; DeferWindowPos cycle
hDWP := DllCall("BeginDeferWindowPos", "Int", Handles.Length(), "Ptr")
For each, Handle in Handles
hDWP := DllCall("DeferWindowPos", "Ptr", hDWP
, "Ptr", Handle, "Ptr", 0
, "Int", Win[Handle].X += dX
, "Int", Win[Handle].Y += dY
, "Int", Win[Handle].W
, "Int", Win[Handle].H
, "UInt", 0x214, "Ptr")
DllCall("EndDeferWindowPos", "Ptr", hDWP)
}
}
}
;================================= END SCRIPT ========================================
2nd Example : Listbox , send selected commands to DOS
Code: Select all
;-------- https://autohotkey.com/boards/viewtopic.php?t=43192 -------------
;- script moveTogether() with 3 attached ahk-examples > from user= Wolf_II
;--------- LISTBOX send selected commands to DOS --------------------------
;- example : Listbox with attached DOS Window
; drag at Listbox to move both windows
; close Listbox > also closes DOS
;---------------------------------------------------------------------------
;-modified = 20180212
;-created = 20180211
;-https://autohotkey.com/boards/viewtopic.php?f=5&t=44098
;---------------------------------------------------------------------------
#warn
#NoEnv
;#SingleInstance Force
setworkingdir,%a_scriptdir%
DetectHiddenWindows, ON
SetKeyDelay,20,20
sendmode,input
Handles := []
;------------ ahk script Listbox --------------------
i=0
x1:=0
y1:=0
w1:=200
h1:=935
lb=
(ltrim join|
cd\
ver
dir
vol
cmd /?
help
date /t
time /t
path
ping /?
ping -n 4 -w 1000 www.google.com
netstat /?
netstat
netstat -an
netstat -e -s
ipconfig /?
ipconfig /all
logoff /?
shutdown /?
sfc /?
mem /?
copy /?
xcopy /?
mode /?
label /?
start /?
subst /?
verify /?
Format /?
fc /?
find /?
findstr /?
convert /?
color /?
at /?
attrib /?
)
sort,lb,D|
;- create ahk GUI = Listbox
Gui,1: New, hwndhWin, Window 1
Gui,1:default
Gui,1:Color,Black
Gui,1:Color,ControlColor, Black
Gui,1:Font,s12 cYellow ,Lucida Console
Gui,1:add,Listbox,x%x1% y%y1% w%w1% h%h1% gLb1 vLbx cYellow,%lb%
Gui,1:Show, x%x1% y%y1% w%w1% h%h1%,Drag & Close here
Handles.Push(hWin)
;----------- next-attached window > DOS ----------
x3:=205
y3:=1
w3:=1220
h3:=950
;-- example-1 send to DOS
e4x=
(Ltrim Join&
cd\
dir
)
title2=AutoHotkey DOS
;Run, %COMSPEC% /k %e4x%,,,pid2 ;- start DOS and send different commands
;----------------------------
;- example-2
Run, %COMSPEC% /S /U /Q /F:ON /k "title %title2% & mode con lines=4048 cols=120&COLOR 02&CD\",,,pid2 ; define title / lines / colons / color
;----------------------------
WinWaitActive, ahk_pid %pid2%
sleep,200
WinMove, ahk_pid %pid2%, , x3, y3, w3, h3 ;- move DOS to the right position
sleep,200
sendinput,ver`n ;- send another command to DOS if needed
IfWinNotActive ,ahk_pid %pid2%,,WinActivate,ahk_pid %pid2% ;- Activate DOS
WinWaitActive,ahk_pid %pid2%
Handles.Push(WinExist("A")) ;- DOS is lastactive
MoveTogether(Handles)
Return
;-------------------------------------------------------------------------------------------------------------
Guiclose: ;- when close Listbox-GUI close also attached DOS
WinClose, ahk_pid %pid2% ;- if close only DOS , ahk-script freeze but you can close it
WinWaitClose,ahk_pid %pid2%
exitapp
;------------------------------------
Lb1: ;- send commands to DOS and let DOS active
Gui,1:submit,nohide
IfWinNotActive ,ahk_pid %pid2%,,WinActivate,ahk_pid %pid2%
WinWaitActive,ahk_pid %pid2%
controlsend,,`n%lbx%`n,ahk_pid %pid2% ;- send command from Listbox to DOS
return
;==============================================================================
;-------------------------------------------------------------------------------
MoveTogether(wParam, lParam = "", _ = "", hWnd = "") { ; using DeferWindowPos
;-------------------------------------------------------------------------------
; call MoveTogether(Handles) with an array of handles
; to set up a bundle of AHK Gui's that move together
;---------------------------------------------------------------------------
; https://autohotkey.com/boards/viewtopic.php?p=199402#p199402
; version 2018.02.08
static init := OnMessage(0xA1, "MoveTogether") ; WM_NCLBUTTONDOWN
static Handles
If IsObject(wParam) ; detect a set up call
Return, Handles := wParam ; store the array of handles
If (wParam != 2) ; HTCAPTION
Return
; changing AHK settings here will have no side effects
CoordMode, Mouse, Screen ; for MouseGetPos
SetBatchLines, -1 ; for onMessage
SetWinDelay, -1 ; for WinActivate, WinMove
M_old_X := lParam & 0xFFFF, M_old_Y := lParam >> 16 & 0xFFFF
WinActivate, ahk_id %hWnd%
Win := {}
For each, Handle in Handles {
WinGetPos, X, Y, W, H, ahk_id %Handle%
Win[Handle] := {X: X, Y: Y, W: W, H: H}
}
While GetKeyState("LButton", "P") {
MouseGetPos, M_new_X, M_new_Y
dX := M_new_X - M_old_X, M_old_X := M_new_X
, dY := M_new_Y - M_old_Y, M_old_Y := M_new_Y
If GetKeyState("Shift", "P")
WinMove, ahk_id %hWnd%,, Win[hWnd].X += dX, Win[hWnd].Y += dY
Else { ; DeferWindowPos cycle
hDWP := DllCall("BeginDeferWindowPos", "Int", Handles.Length(), "Ptr")
For each, Handle in Handles
hDWP := DllCall("DeferWindowPos", "Ptr", hDWP
, "Ptr", Handle, "Ptr", 0
, "Int", Win[Handle].X += dX
, "Int", Win[Handle].Y += dY
, "Int", Win[Handle].W
, "Int", Win[Handle].H
, "UInt", 0x214, "Ptr")
DllCall("EndDeferWindowPos", "Ptr", hDWP)
}
}
}
;=================================== END script ====================================