Bewerken

Delen via


Interaction.AppActivate Method

Definition

Activates an application that is already running.

Overloads

AppActivate(Int32)

Activates an application that is already running.

AppActivate(String)

Activates an application that is already running.

AppActivate(Int32)

Source:
Interaction.vb
Source:
Interaction.vb
Source:
Interaction.vb

Activates an application that is already running.

public:
 static void AppActivate(int ProcessId);
public static void AppActivate (int ProcessId);
static member AppActivate : int -> unit
Public Sub AppActivate (ProcessId As Integer)

Parameters

ProcessId
Int32

Integer specifying the Win32 process ID number assigned to this process. You can use the ID returned by the Shell(String, AppWinStyle, Boolean, Int32), provided it is not zero.

Examples

This example illustrates various uses of the AppActivate function to activate an application window. If a Notepad process is not running, the example throws an ArgumentException. The Shell procedure assumes 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.NormalFocus)
' Activate the new instance of Notepad.  
AppActivate(notepadID)

Remarks

You use AppActivate to bring an application's active window into focus. You might not have a handle or a reference to the active window, or even know which window is active at a given moment. In such a case, you cannot use the Focus method.

The AppActivate function changes the focus to the named application or window but does not affect whether it is maximized or minimized. Focus moves away from the activated application window when the user takes some action to change the focus or close the window. You can use the Shell function to start an application and set the window style.

If you use the Title parameter, AppActivate uses a case-insensitive comparison but otherwise requires an exact match with the contents of the title bar. It first looks through the top-level windows and then through the child windows. If it cannot find a match, it throws an ArgumentException.

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 you request the current process ID, you get the process ID of this separate process, rather than the console application's process ID.

At run time, the AppActivate function activates any running application with a title that matches Title or with a process ID that matches ProcessId. If there is no exact match, it activates any application whose title string ends with Title. If there is more than one application named Title, the AppActivate function arbitrarily chooses one to activate.

Note

The AppActivate function requires UIPermission at the SafeTopLevelWindows level, which may affect its execution in partial-trust situations. For more information, see UIPermission .

See also

Applies to

AppActivate(String)

Source:
Interaction.vb
Source:
Interaction.vb
Source:
Interaction.vb

Activates an application that is already running.

public:
 static void AppActivate(System::String ^ Title);
public static void AppActivate (string Title);
static member AppActivate : string -> unit
Public Sub AppActivate (Title As String)

Parameters

Title
String

String expression specifying the title in the title bar of the application you want to activate. You can use the title assigned to the application when it was launched.

Examples

This example illustrates various uses of the AppActivate function to activate an application window. If a Notepad process is not running, the example throws an ArgumentException. The Shell procedure assumes 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.NormalFocus)
' Activate the new instance of Notepad.  
AppActivate(notepadID)

Remarks

You use AppActivate to bring an application's active window into focus. You might not have a handle or a reference to the active window, or even know which window is active at a given moment. In such a case, you cannot use the Focus method.

The AppActivate function changes the focus to the named application or window but does not affect whether it is maximized or minimized. Focus moves away from the activated application window when the user takes some action to change the focus or close the window. You can use the Shell function to start an application and set the window style.

If you use the Title parameter, AppActivate uses a case-insensitive comparison but otherwise requires an exact match with the contents of the title bar. It first looks through the top-level windows and then through the child windows. If it cannot find a match, it throws an ArgumentException.

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 you request the current process ID, you get the process ID of this separate process, rather than the console application's process ID.

At run time, the AppActivate function activates any running application with a title that matches Title or with a process ID that matches ProcessId. If there is no exact match, it activates any application whose title string ends with Title. If there is more than one application named Title, the AppActivate function arbitrarily chooses one to activate.

Note

The AppActivate function requires UIPermission at the SafeTopLevelWindows level, which may affect its execution in partial-trust situations. For more information, see UIPermission .

See also

Applies to