Jump to content

move multiple windows through dllcall


Recommended Posts

i know i can use

DllCall("user32.dll","int","ReleaseCapture")
   DllCall("user32.dll","int","SendMessage","hWnd", "window here","int",0xA1,"int", 2,"int", 0)

to move a window, but is there a way i can move multiple windows?

i have a script where if u click on a label in the window, hold the mouse down and move you can drag the window to the desired position as i have the style and ex style set to

BitOR($WS_BORDER, $WS_POPUP), BitOR($WS_EX_TOOLWINDOW, $WS_EX_TOPMOST)

this is the only way i can do this, the script contains more then one window and are all set to the above styles

is there a way i can move more than one or all of the windows?

something like

DllCall("user32.dll","int","ReleaseCapture")
   DllCall("user32.dll","int","SendMessage","hWnd", "window one","int",0xA1,"int", 2,"int", 0)  
   DllCall("user32.dll","int","ReleaseCapture")
   DllCall("user32.dll","int","SendMessage","hWnd", "window two","int",0xA1,"int", 2,"int", 0)

but it didnt work

im not good with dll calling =)

thanks

Edited by burrup

qq

Link to comment
Share on other sites

Maybe you should take a look at SlimShady's nice example on moving windows by clicking on a label...

#include <GUIConstants.au3>
AutoItSetOption("TrayIconDebug", 1)

;Initialize variables
Global $style1
Global $IniFile
Global $GUIWidth
Global $GUIHeight

$GUIWidth = 250
$GUIHeight = 250
$IniFile = StringTrimRight(@ScriptFullPath, 3) & "ini"

$GUI_hwnd_1 = GUICreate("New GUI", $GUIWidth, $GUIHeight)

$Drag_btn = GUICtrlCreateLabel("Drag window", 100, 100, 75, -1, $SS_SIMPLE)
    GUICtrlSetBkColor(-1, 0xCCCCCC)

GUISetState(@SW_SHOW)

$GUI_hwnd_2 = GUICreate("New GUI", $GUIWidth, $GUIHeight)

While 1
   Sleep(25)
   $CursorInfo = GUIGetCursorInfo($GUI_hwnd_1)
   $msg = GUIGetMsg()
   Select
          
      Case $msg = $GUI_EVENT_CLOSE
         GUIDelete($GUI_hwnd_1)
         Exit

      Case $CursorInfo[2] AND $CursorInfo[4] = $Drag_btn
         DragWin($GUI_hwnd_1)
        
   EndSelect

WEnd

Func DragWin($hwnd)
   $OldPos = 0
   $OldMousePos = MouseGetPos()
   Local $MousePos
   Local $WinPos
   Local $offset_x, $offset_y
   Local $OldOpt
   $OldOpt = Opt ("WinWaitDelay", 1)
   GUISetCursor(9, 1, $hwnd)
   Do
      Sleep(20)
      $CursorInfo = GUIGetCursorInfo($hwnd)
      If NOT ($OldPos = $CursorInfo[0] + $CursorInfo[1]) Then
         $MousePos = MouseGetPos()
         $WinPos = WinGetPos($hwnd)
         $NewPos = $WinPos
         If $MousePos[0] > $OldMousePos[0] Then
            $NewPos[0] = $WinPos[0] + ($MousePos[0] - $OldMousePos[0])
         Else
            $NewPos[0] = $WinPos[0] - ($OldMousePos[0] - $MousePos[0])
         EndIf
         If $MousePos[1] > $OldMousePos[1] Then
            $NewPos[1] = $WinPos[1] + ($MousePos[1] - $OldMousePos[1])
         Else
            $NewPos[1] = $WinPos[1] - ($OldMousePos[1] - $MousePos[1])
         EndIf
         $OldMousePos = $MousePos
         $OldPos = $CursorInfo[0] + $CursorInfo[1]
         WinMove($hwnd, "", $NewPos[0], $NewPos[1])
      EndIf
   Until NOT $CursorInfo[2]
   GUISetCursor(2, 1, $hwnd)
   Opt ("WinWaitDelay", $OldOpt)
EndFunc

Or... Josbe's AxWindow:

;// AXWindow - AutoIt eXperimental Window (7/08/2004)
;// By: 'Josbe' (mrjosbe AT yahoo DOT com)
;// Based in Ideas: CyberSlug, Rednhead (http://www.hiddensoft.com/forum)
;// Requirement: AutoIt v3.0.102+ (GUI version)

_AXWindow()
Exit

Func _AXWindow()
;// AutoIt Options
Opt("WinWaitDelay",20); If the value is less, it's more easy to move the window.
Opt("GuiResizeMode",800);

;// Window's settings
$wTITLE="AXWindow-My flat window"
$wHEIGHT=365
$wWIDTH=365
$wTITHEIGHT=16
$wColorFont_Title=0xFFFFFF
$wColorBack_Title=0x0BAFEE
$wFont_Title="Arial"
Local $MOVE_MODE=0,$OFFSET

;// Default states
$wStateTop=1;// State by default for window. :: 0 = remove on top flag, 1=set on top flag
$mAnimate=1;// Default state mode for animate 'resizing' the window. :: 0= remove this mode, 1=set this mode on

;// GUI Vars
$WS_EX_STATICEDGE=0x00020000
$WS_EX_CLIENTEDGE=0x00000200
$WS_POPUP=0x80000000
$WS_EX_DLGMODALFRAME=0x00000001
$WS_BORDER=0x00800000
$WS_THICKFRAME=0x00040000
$BS_FLAT=32768
$BS_CENTER  =768
$BS_PUSHLIKE=0x1000

;// Finding default Window's color. Function ::RGB 2 HEX
$rgbComp=StringSplit(StringStripWS(RegRead("HKCU\Control Panel\Colors","ButtonFace"),3),"")
$_hexWinColor=Hex(BitAND($rgbComp[1],255),2)&Hex(BitAND($rgbComp[2],255),2)&Hex(BitAND($rgbComp[3],255),2)

;// >>>==[ WINDOW DEFINITION ]===>>>
If 1 Then; This "IF" only for collapse [+] in the editor (Scite).
GUICreate($wTITLE,$wWIDTH,$wHEIGHT,-1,-1,$WS_POPUP+$WS_BORDER)
GuiSetIcon('')
GuiSetBkColor(Dec($_hexWinColor))

;// TITLE DEFINITION
GuiSetFont(10,700,0,$wFont_Title)
$wTITLEBorder=GUICtrlCreateLabel(''&$wTITLE,0,0,$wWIDTH-80,$wTITHEIGHT)
GuiCtrlSetResizing($wTITLEBorder,'')
GuiCtrlSetTip($wTITLEBorder,'')
GuiCtrlSetLimit($wTITLEBorder,$wColorFont_Title)
GuiCtrlSetBkColor($wTITLEBorder,$wColorBack_Title)

;// ==> BUTTONS DEFINITION - START
GuiSetFont(9,300,0,'Wingdings')
; ASCII Characters for icons
$charM="y"
$charX="x"

If $wStateTop=0 Then
$chrSTop='m'
Else
$chrSTop='l'
EndIf
$btnTop=GUICtrlCreateButton($chrSTop,$wWIDTH-80,0,20,16,$BS_FLAT)
GuiCtrlSetResizing(-1,'')
GuiCtrlSetTip(-1,'Always on top')


Global $btnMin=GUICtrlCreateButton('Ú',$wWIDTH-60,0,20,16,$BS_FLAT)
GuiCtrlSetResizing(-1,'')
GuiCtrlSetTip(-1,'Minimize')


Global $btnCut=GUICtrlCreateButton($charM,$wWIDTH-40,0,20,16,$BS_FLAT)
GuiCtrlSetResizing(-1,'')
GuiCtrlSetTip(-1,'Cut window')


Global $btnClose=GUICtrlCreateButton($charX,$wWIDTH-20,0,20,16,$BS_FLAT)
GuiCtrlSetResizing(-1,'')
GuiCtrlSetTip(-1,'Close')


GuiSetFont(9); Font by default

Global $btnHello=GUICtrlCreateButton('Hello World',$wWIDTH/2-50,$wHEIGHT/2-10,100,20)

;// <== BUTTONS DEFINITION - END

EndIf
;// <<<==[ WINDOW DEFINITION ]===<<<

GuiSetState(@SW_SHOW)

;// Setting value
WinSetOnTop($wTITLE,"",$wStateTop)

While WinExists($wTITLE)
Sleep(10)

;// MOVE MODE - Title
If $MOVE_MODE Then
$mouse=MouseGetPos()
WinMove($wTITLE,"",$mouse[0]+$x_offset,$mouse[1]+$y_offset)
EndIf

$msg=GuiGetMsg()
Select

Case $msg=$btnClose
Exit

Case $msg=$btnCut
$oWWD=Opt("WinWaitDelay",1)
$wPos=WinGetPos($wTITLE)
If $wPos[3]<>$wTITHEIGHT Then
If $mAnimate=1 Then
For $t=$wHEIGHT to $wTITHEIGHT step-6
WinMove($wTITLE,'',$wPos[0],$wPos[1],$wWIDTH,$t-1)
Next
WinMove($wTITLE,'',$wPos[0],$wPos[1],$wWIDTH,$wTITHEIGHT)
Else
WinMove($wTITLE,'',$wPos[0],$wPos[1],$wWIDTH,$wTITHEIGHT)
EndIf
ControlSetText($wTITLE,'','Button3','p')
ControlFocus($wTITLE,"","Static1"); remove the focus
Else
If $mAnimate=1 Then
For $t=$wTITHEIGHT to $wHEIGHT Step 6
WinMove($wTITLE,'',$wPos[0],$wPos[1],$wWIDTH,$t)
Next
Else
WinMove($wTITLE,'',$wPos[0],$wPos[1],$wWIDTH,$wHEIGHT)
EndIf
ControlSetText($wTITLE,'','Button3',$charM)
ControlFocus($wTITLE,"","Static1")
EndIf
Opt("WinWaitDelay",$oWWD)
ContinueLoop

Case $msg=$btnTop
If $wStateTop=0 Then
ControlSetText($wTITLE,'','Button1','l')
ControlFocus($wTITLE,"","Static1"); remove the focus
$wStateTop=1
Else
ControlSetText($wTITLE,'','Button1','m')
ControlFocus($wTITLE,"","Static1"); remove the focus
$wStateTop=0
EndIf
WinSetOnTop($wTITLE,"",$wStateTop)

Case $msg=$btnMin
WinSetState($wTITLE,"",@SW_MINIMIZE)

Case $msg=$btnHello
MsgBox(4096,"","Hello World!")

Case $msg=$wTITLEBorder
$MOVE_MODE=Not $MOVE_MODE;toggle mode
;// Calculate relative offset between window and mouse
If $MOVE_MODE Then
$mouse=MouseGetPos()
$window=WinGetPos($wTITLE)
$x_offset=$window[0]-$mouse[0]
$y_offset=$window[1]-$mouse[1]
GuiCtrlSetTip($wTITLEBorder,"Moving...")
GuiCtrlSetLimit($wTITLEBorder,0xFFFFFF)
GuiCtrlSetBkColor($wTITLEBorder,0x000000)
Else
GuiCtrlSetTip($wTITLEBorder,"Move")
GuiCtrlSetLimit($wTITLEBorder,$wColorFont_Title)
GuiCtrlSetBkColor($wTITLEBorder,$wColorBack_Title)
EndIf
EndSelect
Wend
EndFunc

Is that what your looking for?

FootbaG
Link to comment
Share on other sites

sorta lol, i can already move the window using a much simplier method, below i have recreated slimshadys exact example

#include <GUIConstants.au3>

$GUI_hwnd_1 = GUICreate("New GUI", 250, 250)

$Drag_btn = GUICtrlCreateLabel("Drag window", 100, 100, 75, -1, $SS_SIMPLE)

GUICtrlSetBkColor(-1, 0xCCCCCC)

GUISetState(@SW_SHOW)

While 1
   $Msg = GUIGetMsg()
   Select
      Case $Msg = $GUI_EVENT_CLOSE
         Exit
      Case $Msg = $Drag_btn
         _Drag()
   EndSelect
Wend

Func _Drag()
   DllCall("user32.dll","int","ReleaseCapture")
   DllCall("user32.dll","int","SendMessage","hWnd", $GUI_hwnd_1,"int",0xA1,"int", 2,"int", 0)
EndFunc

but i cant figure out how to move more than one window if i can at all, i want to move about 7 windows at once by clicking on a label in just one of them

qq

Link to comment
Share on other sites

Make an array of each window and use a For loop for each?

"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

Well lets see if I can whip up a little code:

Dim $Window[5]; makes an array with elements 0-4

; Not sure if the syntax is right for WinGetHandle, but this should make sense
$Window[0] = WinGetHandle("x","")
$Window[1] = WinGetHandle("x","")
$Window[2] = WinGetHandle("x","")
$Window[3] = WinGetHandle("x","")
$Window[4] = WinGetHandle("x","")

; Loop through the array and move each window
For $i = 0 to 4
    _Drag(  $Window[$i] )
Next

; It's that simple, that last bit, the 3 lines, loops through each element of the array
; Hope that makes sense, feel free to ask.


; Modified your function to accept an array, not tested, might work? :)
Func _Drag( $WindowHandle )
   DllCall("user32.dll","int","ReleaseCapture")
   DllCall("user32.dll","int","SendMessage","hWnd", $WindowHandle,"int",0xA1,"int", 2,"int", 0)
EndFunc
"I thoroughly disapprove of duels. If a man should challenge me, I would take him kindly and forgivingly by the hand and lead him to a quiet place and kill him." - Mark TwainPatient: "It hurts when I do $var_"Doctor: "Don't do $var_" - Lar.
Link to comment
Share on other sites

#include <GUIConstants.au3>

Dim $Window[2]

$GUI_hwnd0 = GUICreate("a", 500, 400)
GUISetState(@SW_SHOW)
$GUI_hwnd1 = GUICreate("b", 450, 350)

$Drag_btn = GUICtrlCreateLabel("Drag window", 100, 100, 75, -1, $SS_SIMPLE)

GUICtrlSetBkColor(-1, 0xCCCCCC)

GUISetState(@SW_SHOW)

$Window[0] = WinGetHandle("a","")
$Window[1] = WinGetHandle("b","")

While 1
   $Msg = GUIGetMsg()
   Select
      Case $Msg = $GUI_EVENT_CLOSE
         Exit
      Case $Msg = $Drag_btn
         For $i = 0 to 1
            _Drag(  $Window[$i] )
         Next
   EndSelect
Wend

Func _Drag( $WindowHandle )
   DllCall("user32.dll","int","ReleaseCapture")
   DllCall("user32.dll","int","SendMessage","hWnd", $WindowHandle,"int",0xA1,"int", 2,"int", 0)
EndFunc

i thought i would start simple for testing purposes and i used 2 windows, doesnt work =(, if u click drag in the window it will move the other one but not both, only moves the "a" window.

qq

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...