设置窗口在最前

[DllImport("User32.dll")]
private static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow);

[DllImport("User32.dll")]
[return: MarshalAs(UnmanagedType.Bool)
private static extern bool SetForegroundWindow(IntPtr hWnd);

private const int SW_SHOWNORMAL = 1;//正常大小窗口

void FixedTop()
{
    IntPtr hwnd = Process.GetCurrentProcess().MainWindowHandle;//获取应用程序句柄
    ShowWindowAsync(hwnd, SW_SHOWNORMAL);//确保窗口没有被最小化或最大化
    SetForegroundWindow(hwnd);//设置应用程序为前台,返回bool值。
}

posted on 2018-08-06 22:28  springsnow  阅读(294)  评论(0编辑  收藏  举报

导航