How to set the “always on top” flag / parameter in a window that is external to my application?

Is there a way to always set the top-level flag / in a window external to my application, or will I need P / Invoke for my own function?

And if P / Invoke is the only way that is required to call a function, and from which dll?

+3
source share
1 answer

Asking the question, I studied this and came across what seems like a good example of how to achieve this using p / invoke SetWindowPos in 'user32.dll'. I will come back and accept this answer if it 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);
    }
+8
source

Source: https://habr.com/ru/post/1730457/


All Articles