Windows 激活进程,让其窗口显示在最前面

2022年11月16日 1496点热度 0人点赞 0条评论
内容纲要

示例代码如下:

void Main()
{
    string pName = "程序的名称";
    Process[] temp = Process.GetProcessesByName(pName);
    if (temp.Length > 0)
    {
        IntPtr handle = temp[0].MainWindowHandle;
        SwitchToThisWindow(handle, true);
    }
}

[DllImport("user32.dll")]
public static extern void SwitchToThisWindow(IntPtr hWnd, bool fAltTab);

被选择的程序,其窗口会被激活,然后窗口将会展开,放到所有窗口之前。

痴者工良

高级程序员劝退师

文章评论