Jump to content

WinGetState & WinActivate problems..


Guest @ds
 Share

Recommended Posts

Hi All,

I'm brand new to this AutoIt thing (I love it though!) and am having some trouble with a simple thing I'm trying to do.

Here's my code (that I got from BillMercer through ExpertsExchange):

;;; Set the window titlebar matching mode to do a substring match

Opt("WinTitleMatchMode", 2) 

;;; Start Agent Board

run("C:\Program Files\QMCProg_Ads\ABCLIENT.exe")

;;; Endless loop - Exit program from the tray icon...

while 1

 if bitand(WinGetState("Agent Board"),16) = 16 then WinActivate("Agent Board") 
 Sleep(2000); Wait two seconds before checking again

wend

The code works perfectly - except for this particular application (ABCLIENT.exe). If I was, for example, to substitute Agent Board with Notepad like so:

;;; Set the window titlebar matching mode to do a substring match

Opt("WinTitleMatchMode", 2) 

;;; Start Agent Board

run("c:\winnt\notepad.exe")

;;; Endless loop - Exit program from the tray icon...

while 1
 if bitand(WinGetState("Notepad"),16) = 16 then WinActivate("Notepad") 
 Sleep(2000); Wait two seconds before checking again
wend

then it works without a hitch.. just not for this ABCLICNET.exe application.

I'm not really sure what info to give you that may help, but I suspect it to be an issue with AutoIt recognising the Title bar of the app.

Any thoughts and help would be greatly appreciated.

Thanks very much.

Adam - @ds

Link to comment
Share on other sites

;;; Set the window titlebar matching mode to do a substring match

Opt("WinTitleMatchMode", 2) 

;;; Start Agent Board

run("C:\Program Files\QMCProg_Ads\ABCLIENT.exe")

;;; Endless loop - Exit program from the tray icon...

while 1

 if bitand(WinGetState("Agent Board"),16) = 16 then WinActivate("Agent Board") 
 Sleep(2000); Wait two seconds before checking again

wend

this is looking for "Agent Board" as part of the title of the program.

if ABCLIENT.exe does not containt the string "Agent Board" in the title

it will not work.

WinGetState is checking for a minimized window so if it isn't it wont work.

search for SCITE (in this board) which is an editor that will make learning easier!

(sorry don't have the link)

Link to comment
Share on other sites

Thanks for your reply normeus.

As it turns out, after some more playing around, I noticed that the script actually was working, just not as I thought it would. It seems the WinActivate function didn't actually restore the window the the ABCLIENT app. If the window was already restored, then it would set the focus to it, but if it was minimised, it wouldn't maximise it (like it DID for notepad..).

I ended up using the WinSetState function instead and it worked a charm.

Additionally, the Window state of ABCLIENT wasn't one of the standard ones (16 = minimised etc). I had to find out what state it thought it was, and use that.. as it turns out it was 5 - god knows that that is meant to be though!? :idiot:

here's the code if anyone's interested:

;;; Set the window titlebar matching mode to do a substring match
Opt("WinTitleMatchMode", 2) 

;;; Start Agent Board +

run("C:\Program Files\..\..\ABCLIENT.exe")           

;;; Endless loop - Exit program from the tray icon...

while 1

  IF BitAND(WinGetState("Agent Board +"),5) THEN 
    WinSetState("Agent Board +", "", @SW_SHOW)
  ENDIF

  Sleep(5000); Wait five seconds before checking again

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