Where to Go from Here
Chapter 2 AppClose (statement) 59 Platform
Notes:
Macintosh
On the Macintosh, the name$ parameter specifies the title of the desired application. The MacID function can be used to specify the application signature of the application to be activated:
AppActivate MacID(text$) | task
The text$ parameter is a four-character string containing an application signature. A runtime error occurs if the MacID function is used on platforms other than the Macintosh.
AppClose (statement)
Syntax AppClose [name$]
Description Closes the named application.
Comments The name$ parameter is a String containing the name of the application. If the name$ parameter is absent, then the AppClose statement closes the active application.
Example 'This example activates Excel, then closes it.
Sub Main()
If AppFind$("Microsoft Excel") = "" Then 'Make sure Excel is there.
MsgBox "Excel is not running."
Exit Sub End If
AppActivate "Microsoft Excel" 'Activate it (unnecessary).
AppClose "Microsoft Excel" 'Close it.
End Sub
See Also AppMaximize (statement); AppMinimize (statement); AppRestore (statement);
AppMove (statement); AppSize (statement).
Platform(s) Windows.
Platform Notes:
Windows
A runtime error results if the application being closed is not enabled, as is the case if that application is currently displaying a modal dialog box.
The name$ parameter is the exact string appearing in the title bar of the named application's main window. If no application is found whose title exactly matches name$, then a second search is performed for applications whose title string begins with name$. If more than one application is found that matches name$, then the first application encountered is used.
AppFilename$ (function)
Syntax AppFilename$([name$])
Description Returns the filename of the named application.
Comments The name$ parameter is a String containing the name of the desired application. If the name$ parameter is omitted, then the AppFilename$
function returns the filename of the active application.
Example 'This example switches the focus to Excel, then changes the current directory
'to be the same as that of Excel.
Sub Main()
If AppFind$("Microsoft Excel") = "" Then 'Make sure Excel is there.
MsgBox "Excel is not running."
Exit Sub End If
AppActivate "Microsoft Excel" 'Activate Excel.
s$ = AppFilename$ 'Find where the Excel executable is.
d$ = FileParse$(s$,2) 'Get the path portion of the filename.
MsgBox d$ 'Display directory name.
End Sub
See Also AppFind$ (function).
Platform(s) Windows.
Platform Notes:
Windows
For DOS applications launched from Windows, the AppFilename function returns the name of the DOS program, not winoldap.exe.
The name$ parameter is the exact string appearing in the title bar of the named application's main window. If no application is found whose title exactly matches name$, then a second search is performed for applications whose title string begins with name$. If more than one application is found that matches name$, then the first application encountered is used.
AppFind$ (function)
Syntax AppFind$(partial_name$)
Description Returns a String containing the full name of the application matching the partial_name$.
Chapter 2 AppGetActive$ (function) 61 Comments The partial_name$ parameter specifies the title of the application to find. If
there is no exact match, WM Basic will find an application whose title begins with partial_name$.
AppFind$ returns a zero-length string if the specified application cannot be found.
AppFind$ is generally used to determine whether a given application is running. The following expression returns True if Microsoft Word is running:
AppFind$("Microsoft Word")
Example 'This example checks to see whether Excel is running before activating it.
Sub Main()
If AppFind$("Microsoft Excel") <> "" Then AppActivate "Microsoft Excel"
Else
MsgBox "Excel is not running."
End If End Sub
See Also AppFileName$ (function).
Platform(s) Windows.
Platform Notes:
Windows
Under Windows, this function returns a String containing the exact text appearing in the title bar of the active application's main window.
AppGetActive$ (function)
Syntax AppGetActive$()
Description Returns a String containing the name of the application.
Comments If no application is active, the AppGetActive$ function returns a zero-length string.
You can use AppGetActive$ to retrieve the name of the active application.
You can then use this name in calls to routines that require an application name.
Example Sub Main()
n$ = AppGetActive$() AppMinimize n$
End Sub
See Also AppActivate (statement); WinFind (function).
Platform(s) Windows.
Platform Notes:
Windows
Under Windows, this function returns a String containing the exact text appearing in the title bar of the active application's main window.
AppGetPosition (statement)
Syntax AppGetPosition X,Y,width,height [,name$]
Description Retrieves the position of the named application.
Comments The AppGetPosition statement takes the following parameters:
Parameter Description
X, Y Names of Integer variables to receive the position of the application's window.
width, height Names of Integer variables to receive the size of the application's window.
name$ String containing the name of the application. If the name$ parameter is omitted, then the active application is used.
The x, y, width, and height variables are filled with the position and size of the application's window. If an argument is not a variable, then the argument is ignored, as in the following example, which only retrieves the x and y parameters and ignores the width and height parameters:
Dim x as integer, y as integer
AppGetPosition x,y,0,0,"Program Manager"
Example Sub Main()
Dim x As Integer, y As Integer Dim cx As Integer, cy As Integer
AppGetPosition x,y,cx,cy,"Program Manager"
End Sub
See Also AppMove (statement); AppSize (statement).
Platform(s) Windows.
Platform Notes:
Windows
The position and size of the window are returned in twips.
The name$ parameter is the exact string appearing in the title bar of the named application's main window. If no application is found whose title exactly matches name$, then a second search is performed for applications whose title string begins with name$. If more than one application is found that matches name$, then the first application encountered is used.
Chapter 2 AppGetState (function) 63
AppGetState (function)
Syntax AppGetState[([name$])]
Description Returns an Integer specifying the state of the top-level window.
Comments The AppGetState function returns any of the following values:
If the window is then AppGetState returns
Maximized ebMaximized
Minimized ebMinimized
Restored ebRestored
The name$ parameter is a String containing the name of the desired
application. If it is omitted, then the AppGetState function returns the name of the active application.
Examples 'This example saves the state of Program Manager, changes it, then restores
'it to its original setting.
Sub Main()
If AppFind$("Program Manager") = "" Then MsgBox "Can't find Program Manager."
Exit Sub End If
AppActivate "Program Manager" 'Activate Program Manager.
state = AppGetState 'Save its state.
AppMinimize 'Minimize it.
MsgBox "Program Manager is now minimized. Select OK to restore it."
AppActivate "Program Manager"
AppSetState state 'Restore it.
End Sub
See Also AppMaximize (statement); AppMinimize (statement); AppRestore (statement).
Platform(s) Windows.
Platform Notes:
Windows
Under Windows, the name$ parameter is the exact string appearing in the title bar of the named application's main window. If no application is found whose title exactly matches name$, then a second search is performed for applications whose title string begins with name$. If more than one application is found that matches name$, then the first application encountered is used.
AppHide (statement)
Syntax AppHide [name$]
Description Hides the named application.
Comments If the named application is already hidden, the AppHide statement will have no effect.
The name$ parameter is a String containing the name of the desired application. If it is omitted, then the AppHide statement hides the active application.
AppHide generates a runtime error if the named application is not enabled, as is the case if that application is displaying a modal dialog box.
Example 'This example hides Program Manager.
Sub Main()
'See whether Program Manager is running.
If AppFind$("Program Manager") = "" Then Exit Sub AppHide "Program Manager"
MsgBox "Program Manager is now hidden. Press OK to show it once again."
AppShow "Program Manager"
End Sub
See Also AppShow (statement).
Platform(s) Windows.
Platform Notes:
Windows
Under Windows, the name$ parameter is the exact string appearing in the title bar of the named application's main window. If no application is found whose title exactly matches name$, then a second search is performed for applications whose title string begins with name$. If more than one application is found that matches name$, then the first application encountered is used.
AppList (statement)
Syntax AppList AppNames$()
Description Fills an array with the names of all open applications.
Comments The AppNames$ parameter must specify either a zero- or one-dimensioned dynamic String array or a one-dimensional fixed String array. If the array is dynamic, then it will be redimensioned to match the number of open
applications. For fixed arrays, AppList first erases each array element, then begins assigning application names to the elements in the array. If there are fewer elements than will fit in the array, then the remaining elements are unused. WM Basic returns a runtime error if the array is too small to hold the new elements.
After calling this function, you can use LBound and UBound to determine the new size of the array.
Chapter 2 AppMaximize (statement) 65