Jump to content

Recommended Posts

Posted (edited)

FYI: Wrong thread, my bad. I posted in the correct thread now.

Edited by SOLVE-SMART

==> AutoIt related: 🔗 GitHub, 🔗 Discord Server, 🔗 Cheat Sheet

Spoiler

🌍 Au3Forums

🎲 AutoIt (en) Cheat Sheet

📊 AutoIt limits/defaults

💎 Code Katas: [...] (comming soon)

🎭 Collection of GitHub users with AutoIt projects

🐞 False-Positives

🔮 Me on GitHub

💬 Opinion about new forum sub category

📑 UDF wiki list

✂ VSCode-AutoItSnippets

📑 WebDriver FAQs

👨‍🏫 WebDriver Tutorial (coming soon)

Posted

Had something lying around that does about the same thing, except the speed setting is missing. Instead it has a "soft landing" and is written in Plain AutoIt.

Saved it as WinMove.au3

; #FUNCTION# ====================================================================================================================
; Name ..........: _WinMove
; Description ...: same as native WinMove(), except that move and resize are simultaneous
; Syntax ........: _WinMove($_hWnd, $_txt, $_x, $_y, $_w, $_h)
; Parameters ....: $_hWnd   - the title/hWnd/class of the window to pose.
;                  $_txt    - the text of the window to move.
;                  $_x      - X coordinate to move to.
;                  $_y      - Y coordinate to move to.
;                  $_w      - [optional] new width of the window.
;                  $_h      - [optional] new height of the window.
; Author ........: DutchCoder
; Modified ......:
; Remarks .......: parameters and return values are practically identical to those of the native WinMove() function.
; Related .......:
; Link ..........:
; Example .......:
; ===============================================================================================================================

Global $_WinMove[10]

Func _WinMove($_hWnd, $_txt = '', $_x = Default, $_y = Default, $_w = Default, $_h = Default)
    If BitAND(WinGetState($_hWnd, $_txt), 0x20) Then WinSetState($_hWnd, '', @SW_RESTORE)
    Local $_go[4] = [$_x, $_y, $_w, $_h]
    $_WinMove = _MoveInit(WinGetPos($_hWnd, $_txt), $_go)
    $_WinMove[8] = $_hWnd
    AdlibRegister('_WinMoveCoord', 100)
EndFunc

Func _MoveInit($_1, $_2)
    For $_z = 0 To 3
        If $_2[$_z] = Default Then $_2[$_z] = $_1[$_z]
    Next
    Local $_ret[10] = [$_1[0], $_1[1], $_1[2], $_1[3], $_2[0], $_2[1], $_2[2], $_2[3]]
    Return $_ret
EndFunc

Func _WinMoveCoord()
    $_WinMove = _MoveCalc($_WinMove)
    If $_WinMove[9] Then AdlibUnRegister('_WinMoveCoord')
    WinMove($_WinMove[8], '', Round($_WinMove[0]), Round($_WinMove[1]), Round($_WinMove[2]), Round($_WinMove[3]))
EndFunc

Func _MoveCalc($_ret)
    Local $_end = True
    For $_m = 0 To 3
        Local $_dif = ($_ret[$_m + 4] - $_ret[$_m]) * .8
        If Int($_dif) Then
            $_end = False
            $_ret[$_m] += $_dif
        Else
            $_ret[$_m] = $_ret[$_m + 4]
        EndIf
    Next
    $_ret[9] = $_end
    Return $_ret
EndFunc

Example is according to orbs:

#AutoIt3Wrapper_Au3Check_Parameters=-q -d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7
#include <GUIConstantsEx.au3>
#include 'WinMove.au3'

Global Const $iMinW = 250, $iMinH = 100
Global $x, $y, $w, $h, $speed

Global $hGUI = GUICreate('_WinPose() Example', $iMinW, $iMinH)
Global $gButton = GUICtrlCreateButton('Click Me!', 25, 25, 200, 50)
GUICtrlSetResizing(-1, $GUI_DOCKBORDERS)
GUISetState(@SW_SHOW)

Global $msg
While True
    $msg = GUIGetMsg()
    Switch $msg
        Case -3
            ExitLoop
        Case $gButton
            $w = Random($iMinW, @DesktopWidth / 3, 1)
            $h = Random($iMinH, @DesktopHeight / 3, 1)
            $x = Random(0, @DesktopWidth - $w, 1)
            $y = Random(0, @DesktopHeight - $h, 1)
            _WinMove($hGUI, '', $x, $y, $w, $h)
    EndSwitch
WEnd

 

Posted

thank you, had you posted this earlier you would have saved me a lot of work 🙂

 

Signature - my forum contributions:

Spoiler

UDF:

LFN - support for long file names (over 260 characters)

InputImpose - impose valid characters in an input control

TimeConvert - convert UTC to/from local time and/or reformat the string representation

AMF - accept multiple files from Windows Explorer context menu

DateDuration -  literal description of the difference between given dates

WinPose - simultaneous fluent move and resize

Apps:

Touch - set the "modified" timestamp of a file to current time

Show For Files - tray menu to show/hide files extensions, hidden & system files, and selection checkboxes

SPDiff - Single-Pane Text Diff

Magic Math - a math puzzle

Demos:

Title Bar Menu - click the window title to pop-up a menu

 

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
  • Recently Browsing   0 members

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