简体   繁体   中英

Make form visible on all virtual desktops

I am creating a small call application so when the user does not have a note a window appears and informs you that it is necessary to have an activity pointed to to do, but this window should be seen by all virtual desktops that the user owns.

I found two posts here in SO, but they only tell you how to change the default behaviors of workspaces like go left, right, create, remove, and transfer items between them.

These are the posts:

But as I said, I need the window to be visible in all work areas. I also saw that natively windows has an option when you press Alt + Tab and right click on the window you want, you have the option to keep it open in all workspaces. here

So how do I keep my application written in C # with windows forms open on all desktops?

Examples:

Here is the first desktop opening visual studio. 桌面 1 However, when I change the desktop, the application remains in the foreground. 桌面 2

This can be accomplished most easily by adding a value your to WS_EX_STYLES enum with the value of 0x00080080 . and using that style like I have below.I was able to get this enum with an Autohotkey script "checkstyles" available here and checking the style of the vs 2019 splash screen.

IntPtr hwnd = WinAPI.CreateWindowEx2(
    0,
    WinAPI.RegisterClassEx2(ref wndClass),
    null,
    Win32Enums.WindowStylesEx.WS_EX_OVERLAPPEDWINDOW
    ,
    -5, //x
    0 - WinAPI.GetSystemMetrics(Win32Enums.SystemMetric.SM_CYCAPTION) - 7, //y
    ScreenInfo.GetDisplays().MaxWidth  + 10, //width
    ScreenInfo.GetDisplays().MaxHeight + WinAPI.GetSystemMetrics(Win32Enums.SystemMetric.SM_CYCAPTION) + 15, //height
    IntPtr.Zero,
    IntPtr.Zero,
    wndClass.hInstance,
    IntPtr.Zero);


var ExStyle = WinAPI.GetWindowLongPtr(hwnd, (IntPtr)Win32Enums.GWL.GWL_EXSTYLE);
WinAPI.SetWindowLongPtr(hwnd, Win32Enums.GWL.GWL_EXSTYLE, (IntPtr)((int)ExStyle | (int)Win32Enums.WindowStylesEx.WS_EX_VisualStudioEmulation));

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