Activate another example and focus on the front-end

Source: Internet
Author: User
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 );
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.