2

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.

SpyrosKo
  • 167
  • 1
  • 11
  • What kind of program, console, windows forms, wpf? – Ian Jun 25 '16 at 19:08
  • I don't completely understand your question. The program is called SharpDevelop and it is an IDE am using for C#. SharpDevelop is a code editor (Visual Studio/Xamarin alternative). – SpyrosKo Jun 25 '16 at 19:12
  • I thought you meant the program you're trying to develop. – Ian Jun 25 '16 at 19:12

1 Answers1

2

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.

lexx9999
  • 736
  • 3
  • 9