Manipulating Windows

 

Next Topic

 

The WIL Tutorial

§         Topic by Topic

§         The Tutorial Course

§         The Complete WIL Tutorial

 

Getting started

Using WIL

Reference

Notes

 

There are a large number of functions which allow you to manage the windows on your desktop. Here are some of them:

 

WinZoom (partial-windowname)

Maximizes an application window to full-screen.

 

WinIconize (partial-windowname)

Turns an application window into an icon.

 

WinShow (partial-windowname)

Shows a window in its "normal" state.

 

These three functions are used to modify the size of an already-running window. WinZoom is the equivalent of selecting Maximize from a window's control menu, WinIconize is like selecting Minimize, and WinShow is like selecting Restore.

The window on which you are performing any of these functions does not have to be the active window. If the specified window is in the background, and a WinZoom or WinShow function causes the size of the window to change, then the window will be brought to the foreground. The WinZoom function has no effect on a window which is already maximized; likewise, WinShow has no effect on a window which is already "normal."

Each of these functions accepts a partial windowname as a parameter. The windowname is the name which appears in the title bar at the top of the window. You can specify the full name if you wish, but it may often be advantageous not to have to do so. For example, if you are editing the file SOLITARE.WBT in a Notepad window, the windowname will be SOLITARE.WBT - Notepad.

tutbut9_shg.gif

 

You probably don't want to have to hard-code this entire name into your WIL program as:

WinZoom("SOLITARE.WBT - Notepad")

 

Instead, you can specify the partial windowname "~Notepad":

WinZoom("~Notepad")

 

If you have more than one Notepad window open, WIL will use the one which was most recently used or started.

Note that WIL matches the partial windowname beginning with the first character, so that while

WinZoom("SOLITARE")

 

would be correct,

WinZoom("Notepad")

 

would not result in a match.

Also, the case (upper or lower) of the title is significant, so

WinZoom("~notepad")

 

would not work either.

 

WinActivate (partial-windowname)

Makes an application window the active window.

This function makes a currently-open window the active window. If the specified window is an icon, it will be restored to normal size; otherwise, its size will not be changed.

 

WinClose (partial-windowname)

Closes an application window.

This is like selecting Close from an application's control menu. You will still receive any closing message(s) that the application would normally give you, such as an "unsaved-file" dialog box.

 

WinExist (partial-windowname)

Tells if a window exists.

This function returns @TRUE or @FALSE, depending on whether a matching window can be found. This provides a way of insuring that only one copy of a given window will be open at a time.

If you've been following this tutorial faithfully from the beginning, you probably have several copies of Solitaire running at the moment. (You can check by pressing Alt-Tab and seeing how many instances are open. You say you've got five Solitaire windows open? Okay, close them all.) Now, let's modify our WIL program. First, trim out the excess lines so that it looks like this:

Run("C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe", "")

 

Now, let's use the WinExist function to make sure that the WIL program only starts Solitaire if it isn't already running:

If WinExist("Solitaire") == @FALSE Then Run("C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe", "")

 

And this should work fine. Run the WIL program twice now, and see what happens. The first time you run it, it should start Solitaire; the second (and subsequent) time, it should not do anything.

However, it's quite likely that you want the WIL program to do something if Solitaire is already running - namely, bring the Solitaire window to the foreground. This can be accomplished by using the WinActivate function as follows:

If WinExist("Solitaire") == @TRUE
 WinActivate("Solitaire")
Else
 Run("C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe", "")
Endif

 

Note that we can change this to have WinExist check for a False value instead, by modifying the structure of the WIL program:

If WinExist("Solitaire") == @FALSE
 Run("C:\Program Files\Microsoft Games\Solitaire\Solitaire.exe", "")
Else
 WinActivate("Solitaire")
Endif

 

Either format is perfectly correct, and the choice of which to use is merely a matter of personal style. The result is exactly the same.

EndSession ( )

Ends the current Windows session.

This does exactly what it says. It will not ask any questions (although you will receive any closing messages that your currently-open windows would normally display), so you may want to build in a little safety net:

sure = AskYesNo("End Session", "Really quit Windows?")
If sure == @YES Then EndSession( )

 

EndSession is an example of a WIL function which does not take any parameters, as indicated by the empty parentheses which follow it. The parentheses are still required, though.

See Also: IntControl 66, 67, or 68.