开发者

How do I set the 'always on top' flag/setting on a window that is external to my application?

开发者 https://www.devze.com 2022-12-18 22:56 出处:网络
Is there a managed way to set the always on top flag/setting on a window that is external to my application or will I ne开发者_运维技巧ed to P/Invoke a native function?

Is there a managed way to set the always on top flag/setting on a window that is external to my application or will I ne开发者_运维技巧ed to P/Invoke a native function?

And if P/Invoke is the only way what is the function call required and from which dll?


Since asking the question I have been researching this and came across what looks like a good example of how to achieve this via p/invoking SetWindowPos in 'user32.dll'. I will come back and accept this answer if this works.

    [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 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;

    public static void MakeTopMost (IntPtr hWnd)
    {
        SetWindowPos(hWnd, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);
    }


Simple answer:

        TopMost = true;
0

精彩评论

暂无评论...
验证码 换一张
取 消