Jump to content

Recommended Posts

Posted (edited)

hello, Please help me to short my code.

Dim $Win_Names = "Win1"
Opt("WinTitleMatchMode", 2)
If WinExists($Win_Names, "") Then
    WinSetState($Win_Names, "", @SW_HIDE)
    MsgBox(64, "Title", "Press ok to show window.", 10)
    WinSetState($Win_Names, "", @SW_SHOW)
    MsgBox(64, "Title", "Press ok to Close the window.", 10)
    WinClose($Win_Names, "")
EndIf
Dim $Win_Names = "2nd"
If WinExists($Win_Names, "") Then
    WinSetState($Win_Names, "", @SW_HIDE)
    MsgBox(64, "Title", "Press ok to show window.", 10)
    WinSetState($Win_Names, "", @SW_SHOW)
    MsgBox(64, "Title", "Press ok to Close the window.", 10)
    WinClose($Win_Names, "")
EndIf
Dim $Win_Names = "Third"
If WinExists($Win_Names, "") Then
    WinSetState($Win_Names, "", @SW_HIDE)
    MsgBox(64, "Title", "Press ok to show window.", 10)
    WinSetState($Win_Names, "", @SW_SHOW)
    MsgBox(64, "Title", "Press ok to Close the window.", 10)
    WinClose($Win_Names, "")
EndIf

there maybe some more window names. any trick to short my code and add new window names without writing the whole If...to...EndIf Script?

Edited by SinghIsKing
Posted

@Singhisking

Hi, perhaps this is shorter:

Opt("WinTitleMatchMode", 2)

Global $Win_Names="First"
_Showhide()
Global $Win_Names="Second"
_Showhide()
Global $Win_Names="Third"
_Showhide()

Func _Showhide()
If WinExists($Win_Names, "") Then
    WinSetState($Win_Names, "", @SW_HIDE)
    MsgBox(64, "Title", "Press ok to show window.", 10)
    WinSetState($Win_Names, "", @SW_SHOW)
    MsgBox(64, "Title", "Press ok to Close the window.", 10)
    WinClose($Win_Names, "")
EndIf
EndFunc
Posted

@Singhisking

Hi, perhaps this is shorter:

Opt("WinTitleMatchMode", 2)

Global $Win_Names="First"
_Showhide()
Global $Win_Names="Second"
_Showhide()
Global $Win_Names="Third"
_Showhide()

Func _Showhide()
If WinExists($Win_Names, "") Then
    WinSetState($Win_Names, "", @SW_HIDE)
    MsgBox(64, "Title", "Press ok to show window.", 10)
    WinSetState($Win_Names, "", @SW_SHOW)
    MsgBox(64, "Title", "Press ok to Close the window.", 10)
    WinClose($Win_Names, "")
EndIf
EndFunc
oh! Yes, i can short my code using functions. thanksss

can i also do it using RegExpTitle? reading the help file did not help.

Posted

little bit shorter.

Opt("WinTitleMatchMode", 2)

_Showhide("First")
_Showhide("Second")
_Showhide("Third")

Func _Showhide($Title)
    If WinExists($Title, "") Then
        WinSetState($Title, "", @SW_HIDE)
        MsgBox(64, "Title", "Press ok to show window.", 10)
        WinSetState($Title, "", @SW_SHOW)
        MsgBox(64, "Title", "Press ok to Close the window.", 10)
        WinClose($Title, "")
    EndIf
EndFunc  ;==>_Showhide

I don't think that RegExpTitle will help in this script. Or do you want to detect a window which has "First" in the title?

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.

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
×
×
  • Create New...