0

I mean this feature:

enter image description here

So you can open other stuff, folder, files, etc. and that window is on top always. I managed to archive pretty much that with:

SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);

but there are cases like pressing windows+D or open brave browser, where it's no longer on top. The first case is very important. How do I fix that? I thought making global hotkey to prevent window+D to work would be a hacky and not only that I need to make it so only in my application not make windows+D to stop overall. It just need to keep that window on top even so. Here's my current code so far:

using System.Runtime.InteropServices;

namespace fixedWindow
{
    public partial class Form1 : Form
    {
        private static readonly IntPtr HWND_TOPMOST = new IntPtr(-1);
        private const UInt32 SWP_NOSIZE = 0x0001;
        private const UInt32 SWP_NOMOVE = 0x0002;
        private const UInt32 TOPMOST_FLAGS = SWP_NOMOVE | SWP_NOSIZE;

        [DllImport("user32.dll")]
        [return: MarshalAs(UnmanagedType.Bool)]
        public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);

        public Form1()
        {
            InitializeComponent();
 
        }

        private void Form1_Load(object sender, EventArgs e)
        {
           SetWindowPos(Handle, HWND_TOPMOST, 0, 0, 0, 0, TOPMOST_FLAGS);
        }

    }
}
Coder
  • 43
  • 5
  • 3
    You may want to read @raymondchen's take on this issue (Raymond is a guy at Microsoft who is contacted by other Microsoft folks when they need an answer): https://devblogs.microsoft.com/oldnewthing/20110310-00/?p=11253 – Flydog57 May 03 '23 at 21:27
  • @Flydog57 I see... alright, I'd like something like it's on top often like firefox's picture-in-picture. How is that firefox's feature done? – Coder May 03 '23 at 21:34
  • 3
    tldr; it is not possible to have an always always on top window because there are too many apps that think that they need to be always on top -- it's an arms race where nobody wins. – Paul Dempsey May 03 '23 at 21:35
  • See https://www.w3.org/TR/picture-in-picture/ for the PiP Web API in a browser. It's only for video, not applications. – Paul Dempsey May 03 '23 at 21:42
  • PiP is typically a low-level display driver thing where video codec writes directly in the video memory, which is obviously not something available for general app programming., – Paul Dempsey May 03 '23 at 22:15
  • @PaulDempsey If I manage to do something similar to Windows11's focus app would be enough. How can I do something like that? – Coder May 04 '23 at 01:36
  • @PaulDempsey I see, I didn't it was a WEB thing and such low level API. Interesting to know. But what does apps like Windows11's focus app use to keep that windows fixed, on top and don't minimize on windows+D? – Coder May 04 '23 at 01:39
  • @PaulDempsey managed to do that with this https://stackoverflow.com/a/1052921/4497062 work pretty much the way I want. Just doing nothing when handling WM_SYSCOMMAND preventing the default action, does what I want. – Coder May 04 '23 at 01:58

0 Answers0