把自己的UI永远至于其他进程的UI之上

2019-07-12 19:37发布

无论如何切换,都让自己的UI始终处于其他进程的UI之上 需要的API [DllImport("user32.dll", SetLastError = true)] static extern int SetWindowLong(IntPtr hWnd, int nIndex, IntPtr dwNewLong); const int GWL_HWNDPARENT = -8; 使用的API设置自己的UI TestTopWin tmp = new TestTopWin(); tmp.Show(); TestTopWin tmp2 = new TestTopWin(); tmp2.Show(); var handle = new WindowInteropHelper(tmp).Handle; SetWindowLong(tmp, GWL_HWNDPARENT, tmp2); 关键的API是 SetWindowLong:     LONG WINAPI SetWindowLong(
     _In_ HWND hWnd,
     _In_ int nIndex,
     _In_ LONG dwNewLong
    ); 它有三个参数,第一个参数传入子窗口Handle, 第二个参数传入GWL_HWNDPARENT,第三个传入父窗口Handle