Close "Main" Windows with Duplicate Names "Cl

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
lolkid
Newbie
Posts: 6
Joined: Mon Dec 21, 2009 2:57 pm

Close "Main" Windows with Duplicate Names "Cl

Post by lolkid » Mon May 03, 2010 1:15 pm

OK,

Not sure I can do much about this, but would seem to be a bit of a hole in MS's capabilities.

I have an application (Java) which fires up a number of "Main" Windows, ie just off the root level in the OpenWindows treeview from the View System Windows browser (actually SunAWTFrames). All the Windows have the same name.

When they appear (can be one to many ...), I (may) want to Close them. So, I'm doing something like ...

Code: Select all

GetWindowList>winlist
Separate>winlist,CRLF,windows
    Let>p=1
    Repeat>p
        Let>this=windows_%p%
        Length>this,iWinNameLength
        REM Handle The Windows with No Name!
        If>iWinNameLength>0
              Position>%strSuppressWinName%,this,1,iFoundWin
              If>iFoundWin=1
                    CloseWindow>this
              EndIf
        EndIf
        Let>p=p+1
    Until>p>windows_count
However, in the application I am testing, sending the WM_CLOSE does not truly *close* the Window. It ceases to be visible, but remains on the System Windows List.

So, when I iterate over the Window List, the "CloseWindow>this" keeps sending a WM_CLOSE to the first Window found (ie the first one that gets hidden), all the others remain visible and open.

What I really want to do is iterate over an array of Window *handles* and close by handle, but I don't think that there is any way to do this (ie "GetWindowList>winlist" can't be set-up to give me an array of handles/name pairs (or synchronised arrays)).

I appreciate the issue described in the Help manual to do with name mathcing, but this is killing me here. Are there any workarounds, or does anybody have any VBScript code that could help me?

Any help greatly appreciated.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Mon May 03, 2010 2:24 pm

Hi lolkid,

Try this setting WF_TYPE to 2 so GetWindowList and CloseWindow will only process visible windows.

The v12 beta version of Macro Scheduler will do as you wish, the GetWindowList command will return a list of window handles if WIN_USEHANDLE=1.


Gale

lolkid
Newbie
Posts: 6
Joined: Mon Dec 21, 2009 2:57 pm

Post by lolkid » Mon May 03, 2010 2:28 pm

OK, replying to my own problem, but I've spent another hour looking at this, and the only workaround I can come up with is to do some image recognition, click on the target (making the window active), getting the handle for the active window and then closing it.

A bit sucky, but if anybody is having the same problem, example code is below (might not be 100% correct, but you should get the idea).

Code: Select all

REM Filename For "Most Recent" ScreenCapture
Let>bmpMostRecentFullScreen=c:\Loltemp\bmpMostRecentFullScreen.bmp

REM Bitmaps to Find in Screen Comparisons
Let>bmpCheckOne=c:\Loltemp\bmpCheckOne.bmp
Let>bmpCheckTwo=c:\Loltemp\bmpCheckTwo.bmp

REM Constants
GetScreenRes>iScreenResX,iScreenResY

REM Code removed for post to discussion board
Let>iSuppressCheck=0

REM Set iSuppressCheck for debugging only.
REM Let>iSuppressCheck=2

Repeat>iImageToSuppress

    Wait>1
    DeleteFile>bmpMostRecentFullScreen
    ScreenCapture>0,0,iScreenResX,iScreenResY,bmpMostRecentFullScreen

    Let>iImageToSuppress=0

    REM Choose "Windows" to suppress. 
    If>iSuppressCheck=1
        FindImagePos>bmpCheckOne,bmpMostRecentFullScreen,10,1,XAlertPos,YAlertPos,iImageToSuppress
    EndIf

    If>iSuppressCheck=2
        FindImagePos>bmpCheckTwo,bmpMostRecentFullScreen,10,1,XAlertPos,YAlertPos,iImageToSuppress
    EndIf


    REM Would strictly be better to iterate over the arrays to handle multiple hits, but I *normally*
    REM only expect one of these to be around (if any).
    If>iImageToSuppress>0

        REM OK, there is a problem with looping on the Window List and then
        REM trying to close the window - If we have multiple windows with the same
        REM name, we just "close" the same one (windows stay in the system list even
        REM when closed). We need to try and do this by ActiveWindow/Handle.

        MouseMove>XAlertPos_0,YAlertPos_0
        LClick
        Let>WIN_USEHANDLE=1
        GetActiveWindow>handle,ignone,igntwo
        CloseWindow>handle
        Let>WIN_USEHANDLE=0

    EndIf

Until>iImageToSuppress=0

adroege
Automation Wizard
Posts: 438
Joined: Tue Dec 07, 2004 7:39 pm

Try WF_TYPE=2 to ignore invisible windows

Post by adroege » Mon May 03, 2010 2:29 pm

However, in the application I am testing, sending the WM_CLOSE does not truly *close* the Window. It ceases to be visible, but remains on the System Windows List
Have you tried setting the following variable at the beginning
of your code?

Let>WF_TYPE=2

This should make MS look at only visible windows.

I haven't tried it with the GetWindowList> command specifically, however it works great with the other window commands like WaitWindowOpen>

lolkid
Newbie
Posts: 6
Joined: Mon Dec 21, 2009 2:57 pm

Post by lolkid » Mon May 03, 2010 2:42 pm

Gaaah - Thanks Gale

The Solution:

"Try this setting WF_TYPE to 2 so GetWindowList and CloseWindow will only process visible windows. "

Seems to work just fine (and is obvioulsy much better than the image Recognition stuff)!

The only tweak I had to make was to wrap the code with :

Let>IGNOREERRORS=1 ... Let>IGNOREERRORS=0

To suppress the error re "Window not present, subsequent key sends in script may cause exceptions". Is this what yopu would expect. I'm never sending keys to the Window, only closing it, so I'm hoping I'll be alright.

gdyvig
Automation Wizard
Posts: 447
Joined: Fri Jun 27, 2008 7:57 pm
Location: Seattle, WA

Post by gdyvig » Mon May 03, 2010 3:31 pm

The WF_TYPE values let you distinguish between visible and not visible but not between visible parent and visible child. When you close a visible child window the visible child windows will also close. When you attempt to close the child you will get the error message.


Gale

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts