Make a window topmost using a window handle

后端 未结 1 1937
逝去的感伤
逝去的感伤 2020-11-30 06:05

After launching an application using the Process class I\'d like to make that window topmost. Currently, my app is the topmost window so when i launch the other app it does

相关标签:
1条回答
  • 2020-11-30 06:41

    You need to use P/Invoke with SetWindowPos to accopmlish this:

    [DllImport("user32.dll")]
    static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    
    static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
    const UInt32 SWP_NOSIZE = 0x0001;
    const UInt32 SWP_NOMOVE = 0x0002;
    const UInt32 SWP_SHOWWINDOW = 0x0040;
    
    // Call this way:
    SetWindowPos(theWindowHandle, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_SHOWWINDOW);
    
    0 讨论(0)
提交回复
热议问题