Sign in to follow this  
Followers 0
SinghIsKing

Please help me to short my code.

4 posts in this topic

#1 ·  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

Share this post


Link to post
Share on other sites



@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

 

OS : Win XP SP2 (32 bits) / Win 7 SP1 (64 bits) / Win 8 (64 bits) | Autoit version: latest stable / beta.
Hardware : Intel(R) Core(TM) i5-2400 CPU @ 3.10Ghz / 8 GiB RAM DDR3.

My UDFs : Skype UDF | TrayIconEx UDF | GUI Panel UDF | Excel XML UDF | Is_Pressed_UDF

My Projects : YouTube Multi-downloader | FTP Easy-UP | Lock'n | WinKill | AVICapture | Skype TM | Tap Maker | ShellNew | Scriptner | Const Replacer | FT_Pocket | Chrome theme maker

My Examples : Capture toolIP Camera | Crosshair | Draw Captured Region | Picture Screensaver | Jscreenfix | Drivetemp | Picture viewer

My Snippets : Basic TCP | Systray_GetIconIndex | Intercept End task | Winpcap various | Advanced HotKeySet | Transparent Edit control

 

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

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