簡體   English   中英

如何在應用程序外部的窗口上設置“始終在頂部”標志/設置?

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

是否有一種托管方法可以在我的應用程序外部的窗口上設置始終在頂部標志/設置,或者我是否需要 P/Invoke 本機函數?

如果 P/Invoke 是唯一的方法,需要什么函數調用以及從哪個 dll 調用?

自從提出這個問題以來,我一直在研究這個問題,並遇到了一個很好的例子,說明如何通過 p/invoking SetWindowPos in 'user32.dll' 來實現這一點。 如果可行,我會回來接受這個答案。

    [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);
    }

簡單回答:

        TopMost = true;

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM