Search code examples
c#windows-media-playersharpdevelop

Is there a way to get SharpDevelop program to always stay on top other windows?


I am working in SharpDevelop C#, and I am wondering if there is a way to always keep the program to stay on top of every other window. I am following a tutorial to learn C# but it is getting annoying switching between Media Player and SharpDevelop program. It's not that big of a deal, I know, but just wondering if there is a way to achieve this.


Solution

  • Yes, there are tools to have media player (and 99% of any app) staying on top. Because I won't recommend one please search "Always On Top" or "Window on top"

    If you want to write your own, you need to find get window handle of the top-level window of that application, then do something like (w is the HWND). Sample code in c++:

      HWND w=GetForegroundWindow(); // or  w=WindowFromPoint(cursorpos);
    
      DWORD isTop=GetWindowLong(w, GWL_EXSTYLE)&WS_EX_TOPMOST;
    
      SetWindowPos(w, isTop ? HWND_NOTOPMOST : HWND_TOPMOST, 0,0,0,0, SWP_NOMOVE|SWP_NOACTIVATE|SWP_NOSIZE);
    

    In C# you need P/Invoke.