简体   繁体   中英

Window visible in all virtual desktop

WPF中的“我的应用”是一种系统监视器,因此,即使在Windows 10的每个虚拟桌面中,我都希望它始终可见。是否可以仅使用C#?

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

I found wrapper .Net 4.6 compatible: VirtualDesktop

Nice solution! TY all ;-)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM