Sign in to follow this  
Followers 0
Champak

"Enhanced" Windows Management UDF

3 posts in this topic

#1 ·  Posted (edited)

Nothing really special; I had a need in my app to change the window detect mode from time to time, and also needed to get a new title for the control commands based on certain states of a communicating application, so I made a few simple functions to take care of that. Then it dawned on me that I may need this stuff down the line so I decided to make the entire collection....then I decided to share it, so here.

With this you don't have to worry about the different versions of titles an app your communicating with spits out because you can adjust to winsettitlemode on the fly within each win and control function call and it will return the winsettitlemode to its original state at the end of the function. All the parameters are the same as the win and control functions except one more is added on as the last parameter of all of them where you set the title mode.

I recommend setting a the default winsettitlemode to 2 when using this.

Func _Enhanced_Helper($ETitleHelper, $ETextHelper, $EOptionMatchHelper)

    ;ConsoleWrite("Current match mode " & Opt("WinTitleMatchMode") & @CRLF)


    $EOptionMatchReturn = Opt("WinTitleMatchMode");Get original match mode
    Opt("WinTitleMatchMode", $EOptionMatchHelper);Set new match mode from control/win function
    $ENewTitle = WinGetTitle ( $ETitleHelper, $ETextHelper );Get the full title of the window based on the new match mode
    Opt("WinTitleMatchMode", $EOptionMatchReturn);Return the match mode to the original match mode

;   ConsoleWrite("+ Original Title Match: " & $ETitleHelper & @CRLF & _
;   "! Window Title Match: " & $ENewTitle & @CRLF & _
;   "! Match: " & $EOptionMatchHelper & @CRLF & _
;   "+ Return: " & $EOptionMatchReturn & @CRLF & _
;   "-///////////////////////////////////////" & @CRLF)
    
    Return $ENewTitle

EndFunc

Func _Enhanced_ControlClick ( $ETitle, $EText, $EID, $EButton = 'Left', $EClicks = 1, $EX = "", $EY = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlClick ( $EReturnTitle, $EText, $EID, $EButton, $EClicks )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlCommand ( $ETitle, $EText, $EID, $ECommand, $EOption = "", $EOptionMatch = 1 )
    
    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlCommand ( $EReturnTitle, $EText, $EID, $ECommand, $EOption )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlDisable ( $ETitle, $EText, $EID, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlDisable ( $EReturnTitle, $EText, $EID )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlEnable ( $ETitle, $EText, $EID, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlEnable ( $EReturnTitle, $EText, $EID )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlFocus ( $ETitle, $EText, $EID, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlFocus ( $EReturnTitle, $EText, $EID )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlGetFocus ( $ETitle, $EText, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlGetFocus ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlGetHandle ( $ETitle, $EText, $EID, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlGetHandle ( $EReturnTitle, $EText, $EID )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlGetPos ( $ETitle, $EText, $EID, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlGetPos ( $EReturnTitle, $EText, $EID )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlGetText ( $ETitle, $EText, $EID, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlGetText ( $EReturnTitle, $EText, $EID )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlHide ( $ETitle, $EText, $EID, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlHide ( $EReturnTitle, $EText, $EID )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlListView ( $ETitle, $EText, $EID, $ECommand, $EOption1 = "", $EOption2 = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlListView ( $EReturnTitle, $EText, $EID, $ECommand, $EOption1, $EOption2 )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlMove ( $ETitle, $EText, $EID, $EX, $EY, $EWidth = "", $EHeight = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlMove ( $EReturnTitle, $EText, $EID, $EX, $EY, $EWidth, $EHeight )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlSend ( $ETitle, $EText, $EID, $EString, $EFlag = 0, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlSend ( $EReturnTitle, $EText, $EID, $EString, $EFlag )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlSetText ( $ETitle, $EText, $EID, $ENewText, $EFlag = 0, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlSetText ( $EReturnTitle, $EText, $EID, $ENewText, $EFlag )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlShow ( $ETitle, $EText, $EID, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlShow ( $EReturnTitle, $EText, $EID )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_ControlTreeView ( $ETitle, $EText, $EID, $ECommand, $EOption1 = "", $EOption2 = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlTreeView ( $EReturnTitle, $EText, $EID, $ECommand, $EOption1, $EOption2 )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_StatusbarGetText ( $ETitle, $EText = "", $EPart = 1, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = ControlGetText ( $EReturnTitle, $EText, $EPart )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinActivate ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinActivate ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinActive ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinActive ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinClose ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinClose ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinExists ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinExists ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinFlash ( $ETitle, $EText = "", $EFlashes = 4, $EDelay = 500, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinFlash ( $EReturnTitle, $EText, $EFlashes, $EDelay )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinGetClassList ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinGetClassList ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinGetClientSize ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinActivate ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinGetHandle ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinGetHandle ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinGetPos( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinGetPos ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinGetProcess ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinGetProcess ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinGetState ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinGetState ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinGetText ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinGetText ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinGetTitle ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinGetTitle ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinKill ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinKill ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinList ( $ETitle, $EText = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinList ( $EReturnTitle, $EText )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinMenuSelectItem ( $ETitle, $EText, $EItem, $EItem1 = "", $EItem2 = "", $EItem3 = "", $EItem4 = "", $EItem5 = "", $EItem6 = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinMenuSelectItem ( $EReturnTitle, $EText, $EItem, $EItem1, $EItem2, $EItem3, $EItem4, $EItem5, $EItem6 )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinMove ( $ETitle, $EText, $EX, $EY, $EWidth = "", $EHeight = "", $ESpeed = 1, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinMove ( $EReturnTitle, $EText, $EX, $EY, $EWidth, $EHeight, $ESpeed )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinSetOnTop ( $ETitle, $EText, $EFlag, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinSetOnTop ( $EReturnTitle, $EText, $EFlag )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinSetState ( $ETitle, $EText, $EFlag, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinSetState ( $EReturnTitle, $EText, $EFlag )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinSetTitle ( $ETitle, $EText, $NewTitle, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinSetTitle ( $EReturnTitle, $EText, $NewTitle )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinSetTrans ( $ETitle, $EText, $ETransparency, $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinSetTrans ( $EReturnTitle, $EText, $ETransparency )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinWait ( $ETitle, $EText = "", $ETimeout = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinWait ( $EReturnTitle, $EText, $ETimeout )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinWaitActive ( $ETitle, $EText = "", $ETimeout = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinWaitActive ( $EReturnTitle, $EText, $ETimeout )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinWaitClose ( $ETitle, $EText = "", $ETimeout = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinWaitClose ( $EReturnTitle, $EText, $ETimeout )
    Return $EEnhancedValue

EndFunc

Func _Enhanced_WinWaitNotActive ( $ETitle, $EText = "", $ETimeout = "", $EOptionMatch = 1 )

    $EReturnTitle = _Enhanced_Helper($ETitle, $EText, $EOptionMatch)
    $EEnhancedValue = WinWaitNotActive ( $EReturnTitle, $EText, $ETimeout )
    Return $EEnhancedValue

EndFunc

EDIT: Made a couple of corrections. Also, not all of the functions have been tested, I just copied the basic formula for each function. Ex. _Enhanced_WinWaitActive doesn't seem very reliable if the window does not already EXIST.

Edited by Champak

Share this post


Link to post
Share on other sites



Fixing my other app I realized that this wasn't working properly and overcomplicated. Now fixed (OP code)...as far as I see.

Share this post


Link to post
Share on other sites

can you post an example please?

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