Jump to content

How to handle two different possible windows after MouseClick()?


Mbee
 Share

Recommended Posts

So I'm making progress controlling the non-standard GUIs of  Comodo Firewall (See thread: Updating question about manipulating non-standard GUIs) . It was tedious and annoying to get as far as I have, but now I'm at an impasse: After I MouseClick() a pseudo-button, I could get two different windows depending on an internal-to-Comodo state. How do I code my script to handle either?  I'm guessing using AdLib functions, but I want to get a check from you folks on how to do it.

Here's my plan: After clicking the button, I register two AdLib functions, one for each possible result. Each sets a global variable (must it be static, too?) to match which condition was met. Meanwhile, the main script waits for that global to have a non-zero value, whereupon it unregisters both AdLibs and continues the script.  Does that seem right?

I'm completely open to suggestions...

 

As a side-note, because these GUIs are non-standard, I can't distinguish between the possible outcomes by the usual techniques, such as the existence of a specific class or control or different texts in the windows.  The only thing that I've been able to find that's different is their window sizes, but that's enough -- unless I run into a case where both windows have exactly the same size, in which case I'm pretty sure I'm screwed.  But I'll worry about that if it happens.

Link to comment
Share on other sites

I actually need more help: I want to wait until there's a window change, i.e., that a new window comes up on top of the others.  Since I can't get the text or title or anything else, I can't use WinWait() or any of its variants!  Is there something  like "Wait till a new window opens on top" function or UDF that anyone knows of?

Thanks!

Link to comment
Share on other sites

4 hours ago, Nine said:

Use the known handles of the windows, to compare to the current "[ACTIVE]" window...

Hey, thank you, @Nine! 😀  Just to be sure I understand, I would call WinGetHandle("[ACTIVE]", "") for the current window, then in my AdLib functions I keep calling that same function until it returns a different value, correct?

Or would you recommend some other approach?

 

Link to comment
Share on other sites

12 minutes ago, Mbee said:

Hey, thank you, @Nine! 😀  Just to be sure I understand, I would call WinGetHandle("[ACTIVE]", "") for the current window, then in my AdLib functions I keep calling that same function until it returns a different value, correct?

Or would you recommend some other approach?

 

Hard to say without your code.  But I suppose using AdLib is one solution.  Depends if you are waiting for that window to appears, or is it appearing randomly...

Link to comment
Share on other sites

Well, what I have appears to work.  Here's the relevant code snippet,,,

 

 

How would you suggest I improve this?  I'm completely open to advice/suggestions...

ETA: Do those global static variables actually need to be static?

NO! THAT'S NONSENSE!  Give me a moment, please, to ix it...

Edited by Mbee
Completely WROMG
Link to comment
Share on other sites

Here how I would do it (untested)

Local $GS_InitWinHdl = WinGetHandle("[ACTIVE]")     ; Get the current ("Application Rules") Handle
MouseClick( $MOUSE_CLICK_MAIN, 638, 168 )           ; Application Rules -> "Purge"

Local $hTime = TimerInit ()
While WinGetHandle("[ACTIVE]") = $GS_InitWinHdl
    if TimerDiff($hTime) > 15 * 1000 then
        _MyUpdStatusMsg("Application Purge Timed Out")
        MsgBox($MB_OK, $GC_OurTitle, "FATAL: Application Purge Timed Out - Aborting")
        Exit -32
    EndIf
    Sleep(200)
Wend 
    
_MyUpdStatusMsg("Application Purge Button Wait Complete")
Sleep( 1000 )
_MyUpdStatusMsg("Success - Exiting")
MsgBox($MB_OK, $GC_OurTitle, "Success - Exiting")
Exit 0

FYI : Global static are same as Global.  It is usually used as Local Static.  Use local (instead of global) as much as possible unless it is absolutely necessary.

Link to comment
Share on other sites

Thanks again.  When I deleted my code and added "NO! THAT'S NONSENSE!", I had understood why using AdLib was pointless, as you indicated. What I coded and verified working is quite similar to what you posted above, all without AdLibs.

I was always skeptical about defining those vars as Static (the code I saw using AdLibs declared them as Local Static), but even if Static was unnecessary, I thought some of them needed to be Global because of the AdLibs. Once I threw that flawed notion out, I could see that not even the Globals were needed.

I very much appreciate your kind help!

 

Link to comment
Share on other sites

1 minute ago, Mbee said:

Thanks again.  When I deleted my code and added "NO! THAT'S NONSENSE!", I had understood why using AdLib was pointless, as you indicated. What I coded and verified working is quite similar to what you posted above, all without AdLibs.

I was always skeptical about defining those vars as Static (the code I saw using AdLibs declared them as Local Static), but even if Static was unnecessary, I thought some of them needed to be Global because of the AdLibs. Once I threw that flawed notion out, I could see that not even the Globals were needed.

I very much appreciate your kind help!

 

:thumbsup:

Link to comment
Share on other sites

5 hours ago, Nine said:

Use local (instead of global) as much as possible unless it is absolutely necessary.

Except that in the code you posted, all of  your variables are global. 

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

37 minutes ago, BrewManNH said:

Except that in the code you posted, all of  your variables are global. 

Except you don't understand that it is a snippet not a true program...

Link to comment
Share on other sites

Yes, I understand that, but you declared Global variables using the Local keyword. I assumed you didn't realize that using Local in a global scope is wrong, they're all Global regardless of what keyword you used to declare them.

Hopefully by pointing it out to people that insist on misusing Local this way, it will eventually get through to the other people that visit the forum, that Local should only be used inside functions, anywhere else is a misuse of the declaration.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

39 minutes ago, BrewManNH said:

I assumed you didn't realize that using Local in a global scope is wrong, they're all Global regardless of what keyword you used to declare them.

You assume wrong.  But if it is the best contribution you have to do in this thread, I suggest you go throw your boredom elsewhere...

Link to comment
Share on other sites

Lets just drop this one here, you're obviously taking things the wrong way and aren't particularly interested in not being an ass about it.

Forgive my impudence in pointing out your ironic statement and misuse of the Local declaration. You're on your own from here on out, you're free to misuse the language in any way you'd like, I won't try and correct you.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
Share on other sites

21 hours ago, BrewManNH said:

Lets just drop this one here, you're obviously taking things the wrong way and aren't particularly interested in not being an ass about it.

Forgive my impudence in pointing out your ironic statement and misuse of the Local declaration. You're on your own from here on out, you're free to misuse the language in any way you'd like, I won't try and correct you.

Respectfully sir, you can hardly blame friend @Nine for my mistake!  In post 6, I had posted a snippet where all the same variables were declared Global -- in fact Global Static -- a very foolish mistake on MY part!  Once I had realized how stupid that was, I went back and deleted the code snippet -- but not before @nine had copied it on his own system to examine it.  So he did not declare those variables Global, I ignorantly did!

Please, kind sir, direct your genuinely valuable corrective advice to He Who Screwed Up -- me!

Thanks.

Link to comment
Share on other sites

14 minutes ago, Mbee said:

Once I had realized how stupid that was, I went back and deleted the code snippet -- but not before @nine had copied it on his own system to examine it.  So he did not declare those variables Global, I ignorantly did!

Please, kind sir, direct your genuinely valuable corrective advice to He Who Screwed Up -- me!

The only mistake you made was in the use of Global with Static, from what you're telling me. What he did was to change all of your correct Globals into incorrect Locals, which is what I pointed out to him. All of the variables in that snippet are global scoped, using Local with them is incorrect usage of the language. YOU didn't do anything other than use Static, you didn't screw up in declaring Global variables Global, you were correct.

If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Link to comment
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
 Share

  • Recently Browsing   0 members

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