WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

Window Manipulation

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

WinExist and WinWaitClose Problems


Question:

I have a problem I simply cannot resolve.

Basically, I have a script that does some processing, opens Microsoft Outlook, creates a new mail, populates it, sends it and continues on. Due to the slowness of my PC, the mail takes some time to close, so I do a winexist and winwaitclose before continuing on. This is where my problem manifests itself. winexist always seems to return true and winwaitclose simply waits for ever, even though the window has closed.

I have created a short script to duplicate and demonstrate the problem. The script simply opens up a new mail, waits a few seconds, closes the mail then checks to make sure the mail is closed before continuing. I have tried a number of variations to check for the existence of the mail closure, and none of them ever detect the window closing.

allwins = WinItemize( )
OutlookInbox = AskItemList("Windows", allwins, @TAB, @unsorted, @single)
winactivate(OutlookInbox)
sendkeysto(OutlookInbox, "^n")
timedelay(1)
allwins = WinItemize( )
NewMail = AskItemList("Windows", allwins, @TAB, @unsorted, @single)
; do some other stuff and usually sent the mail here
; for this example I will simply shut the new mail windows
timedelay(2)
winactivate(NewMail)
sendkeysto(Newmail, "!{F4}")

; I have tried tried this
if winexist(Newmail) == @true then winwaitclose(NewMail)

; I have also tried this
while winexist(NewMail) == @true
yield()
end while
I have a problem Iied this before giving up
while @true
yield()
if winexist(NewMail) == @true then
timedelay(1)
else
break
endif
end while

; this message simply never appears
message("Done","You may proceed")

Any suggestions would be much appreciated.

Answer:

After you do the WinExist to see if the window exists, you may also wish to do a WinState on it to check its state. WinExist will check whether or not the window exists in any form. However, if a program has a window that might be used repeatedly, it can, instead of creating a window each time it is needed and destroying it afterwards (what WinExist checks) The program can make a single window and hide it when it is not needed, and make it visible when it is wanted.

The WinState function can tell you the current state of the window. It may be flopping between Normal and Hidden.

User Reply:

I tried it and the NewMail Window still exists, even though it is not visible. I did a winitemize, and the Window is still there, but the suggestion of doing a winstate on it indicates that it is indeed in a hidden state.

I have changed my code now to open the NewMail, do a winidget, then close it. If winexist(NewMailID) returns true and winstate(NewmailID) returns @hidden, then I simply assume it's in the hidden state and continue on.

Works great now.


Article ID:   W16267
File Created: 2004:03:30:15:43:42
Last Updated: 2004:03:30:15:43:42