Edun

If Then multiple conditions

10 posts in this topic

#1 ·  Posted (edited)

Hello. It's me asking stupid questions once again : )

Now I'm kinda stuck with some really basic things. My script just loops and wait for existing windows and if the conditions are met, run function. Mainly it is as simple as this:

While 1

If WinExists("Title","") AND WinExists("[CLASS:Notepad]") Then function()

WEnd

If I'm not mistaken, right now it checks separately if there is a window named Title and if there is a window of notepad class. How can I check if those conditions met for the same spesific window?

I feel kinda stupid asking questions like these :facepalm:

-Edun

 

Edited by Edun

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

Just remove the 'AND' and the second 'WinExists'

and then have a look at the page in the help file that this link sends you to:   :D

 

Okay - I see, you want both conditions met for the same window...

disregard.

 

Clipboard01.jpg

Edited by l3ill

Share this post


Link to post
Share on other sites
18 minutes ago, l3ill said:

Just remove the 'AND' and the second 'WinExists'

and then have a look at the page in the help file that this link sends you to:   :D

Clipboard01.jpg

Oh dear... Thank you. I've actually got pretty decent and well working script here and then I can't figure problem like this by myself. Shame on me.

-Edun

Share this post


Link to post
Share on other sites
15 minutes ago, l3ill said:
$sVar = "Test_Window - Notepad"
$hWnd = WinGetHandle($sVar)


If WinExists("[CLASS:Notepad]") And WinGetTitle($hWnd) = $sVar Then
    MsgBox(64, "", "it's there")
EndIf

 

This was the first idea that came to my idea and I was actually able to figure it out by myself (Hurray!). Unfortunately this didn't fit too well for my script since it's repeatingly detecting multiply Windows so I had to find alternative method. Still thank you for the reply.

-Edun

Share this post


Link to post
Share on other sites

Edun,

When you reply, please use the "Reply to this topic" button at the top of the thread or the "Reply to this topic" editor at the bottom rather than the "Quote" button - responders know what they wrote and it just pads the thread unnecessarily.

M23

 


Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind._______My UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Share this post


Link to post
Share on other sites

You could try this.

HotKeySet("{ESC}", "Terminate")

Run("NOTEPAD.EXE")
Local $hWnd = WinWaitActive("[CLASS:Notepad]")
WinSetTitle($hWnd, "", "My Window") ; <<< Change title to "My Window1" to not detect the NOTEPAD window.


While 1
    Sleep(100)
    If WinExists("[REGEXPTITLE:^My Window$;CLASS:Notepad]") Then MsgBox(0, "", "Window Exists")
    ; The regular expression pattern above (to match the title) is "^My Window$".  Where "^" specifices the start of the title matching,
    ;      and, "$" specifices the end of the title matching.
WEnd


Func Terminate()
    Exit
EndFunc   ;==>Terminate

 

Share this post


Link to post
Share on other sites

Seems simple enough and you guys have been really helpful, but for some weird reason I'm still doing this wrong.

So notepad isn't actually the program I'm using here. This is more like the information I use:

Title:    Window something here
Class:    WindowsForms10.Window.208.app.0.f7e717_r12_ad2

For the Class it can be exact match but I'd like to use it WindowsForms10* because after that it might changes at some point. But for name it should be a match only for the first word and random text after that.

I've tried to make this work using TITLE, REGEXPTITLE and REGEXPCLASS and a lot of different variations of these.

Shouldn't it be working with something as simple as this:

Opt("WinTitleMatchMode", 1)

If WinExists("[TITLE:Window;CLASS:WindowsForms10.Window.208.app.0.f7e717_r12_ad2]")

 

Share this post


Link to post
Share on other sites

Okay I think I got it fixed, not sure how though since I've been struggling with this so much. Maybe it has something to do with WinTitleMatchmode and using REGEXPCLASS?

Well I got a lot of helpful information here, thank you all.

-Edun

 

 

Share this post


Link to post
Share on other sites
1 hour ago, Edun said:

....

For the Class it can be exact match but I'd like to use it WindowsForms10* because after that it might changes at some point.

....

It appears you are familiar with the wildcard character "*". in "WindowsForms10*" above. The Regular Expression (RE) equivalent is "WindowsForms10.*". Where "." represents any one character, and the "*" is a quantifiers that specifies the preceding character is matched zero to many times.

Try

If WinExists("[REGEXPTITLE:^Window.*;REGEXPCLASS:^WindowsForms10.*]")
; Title RE pattern, "^Window.*" means match the window title that starts with "Window" and is followed by either no characters or many characters.
; Class RE pattern, "^WindowsForms10.*" means match the window class that starts with "WindowsForms10" and is followed by either no characters or many characters.

 

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