Reputation: 223
My App in WPF is a kind of system monitor, so I want to have it always visible, even in each Virtual Desktop of Windows 10. Is it possible using only C#?
Upvotes: 2
Views: 1680
Reputation: 223
I found wrapper .Net 4.6 compatible: VirtualDesktop
Nice solution! TY all ;-)
Upvotes: 1
Reputation: 8706
Looks like all you have to do is set WS_EX_TOOLWINDOW on your main window. Per https://superuser.com/questions/950960/pin-applications-to-multiple-desktops-in-windows-10
Example code:
[DllImport( "user32.dll", EntryPoint = "GetWindowLongPtr" )]
public static extern IntPtr GetWindowLongPtr( IntPtr hWnd, GWL nIndex );
[DllImport( "user32.dll", EntryPoint = "SetWindowLongPtr" )]
public static extern IntPtr SetWindowLongPtr( IntPtr hWnd, GWL nIndex, IntPtr dwNewLong );
const long WS_EX_TOPMOST = 0x00000008L;
public enum GWL : int
{
GWL_WNDPROC = (-4),
GWL_HINSTANCE = (-6),
GWL_HWNDPARENT = (-8),
GWL_STYLE = (-16),
GWL_EXSTYLE = (-20),
GWL_USERDATA = (-21),
GWL_ID = (-12)
}
public static void SetToolWindow( Window window )
{
var wih = new WindowInteropHelper( window );
var style = GetWindowLongPtr( wih.Handle, GWL.GWL_EXSTYLE );
style = new IntPtr( style.ToInt64() | WS_EX_TOPMOST );
SetWindowLongPtr( wih.Handle, GWL.GWL_EXSTYLE, style );
}
Upvotes: 3