Two APIs are used:
- ShowWindowAsync (IntPtr hWnd, int cmdShow); this function is used to display the rows in the Windows generated by different programming languages.
- SetForegroundWindow (IntPtr hWnd); this function sets the parameter settings for the specified window to the front and updates the window. Please refer to this window and modify various types of recordable records for the user. The permission assigned by the system to the scheduler in the pre-built scheduler window is slightly higher than that of other schedulers.
HWndIs the handle of the window.
NCmdShowIt is the zookeeper shown in the window. The possible values are as follows:
SW_HIDE indicates that the window is hidden, and the constant number is 0.
SW_SHOWNORMAL indicates the current window, but the window is restored as the original size and position when the window is minimized or maximized. The constant number is 1.
SW_SHOWMINIMIZED refers to the activation window as the front window, and the indicator is minimized. Constant number: 2.
SW_SHOWMAXIMIZED refers to the activation window as the front window and maximizes the display. Constant number: 3.
SW_SHOWNOACTIVATE is a forward window, but is not activated as a forward window. The constant number is 4.
SW_SHOW is the size and position of the active window as the front window, And the cursor shows the front window. The constant number is 5.
SW_MINIMIZE indicates that the window is minimized, and the constant number is 6.
SW_SHOWMINNOACTIVE indicates that the window is minimized, but is not activated as the front window. Constant number: 7.
SW_SHOWNA indicates the size and position before the current window, but is not activated as the current window. Constant number: 8.
SW_RESTORE is displayed in the restore window from the task. Constant number: 9.
The token generation is as follows:
REFERENCE The following namespace:
Using System. Runtime. InteropServices;
Using System. Diagnostics;
Using System. Reflection;
Generation:
Public class ActiveOtherProcess
{
[DllImport ("User32.dll")]
Private static extern bool ShowWindowAsync (IntPtr hWnd, int cmdShow );
[DllImport ("User32.dll")]
Private static extern bool SetForegroundWindow (IntPtr hWnd );
Private const int WS_SHOWNORMAL = 1;
System. Diagnostics. Process [] processcoll = System. Diagnostics. Process. GetProcesses ();
Foreach (System. Diagnostics. Process process in processcoll)
{
If (process. ProcessName = "Instance name success ")
{
ShowWindowAsync (process. main1_whandle, WS_SHOWNORMAL );
SetForegroundWindow (process. main1_whandle );
}
}
}