Activates an application window.
Public Overloads Sub AppActivate( _ ByVal { Title As String | ProcessID As Integer } _ )
Exception type | Error number | Condition |
---|---|---|
5 | ProcessID is not found. |
The AppActivate function changes the focus to the named application or window, but does not affect whether it is maximized or minimized. Focus moves from the activated application window when the user takes some action to change the focus or close the window. Use the Shell function to start an application and set the window style.
You can use AppActivate only with processes that own windows. Most console applications do not own windows, which means that they do not appear in the list of processes that AppActivate searches. When running from a console application, the system creates a separate process to run the application and returns the output to the console process. Consequently, when the current Process ID is requested, you get the created process's Process ID rather than the console application's Process ID.
At run time the AppActivate function activates any running application whose title matches Title or whose Process ID matches ProcessID. If there is no exact match, it activates any application whose title string begins with Title. If there is more than one application named by Title, the AppActivate function activates one at random.
This example illustrates various uses of the AppActivate function to activate an application window. The Shell procedures assume the applications are in the paths specified.
Dim notepadID As Integer ' Activate a running notepad process. AppActivate("Untitled - Notepad") ' AppActivate can also use the return value of the Shell function. ' Shell runs a new instance of notepad. notepadID = Shell("C:\WINNT\NOTEPAD.EXE", AppWinStyle.MinimizedNoFocus) ' Activate the new instance of notepad.AppActivate(
notepadID)
Shell Function |