2

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. Desktop 1 However, when I change the desktop, the application remains in the foreground. Desktop 2

Márcio Eric
  • 205
  • 2
  • 10
  • Possible duplicate of https://stackoverflow.com/questions/33548454/perisistant-window-across-multiple-windows-10-virtual-desktops – jlynch630 Jun 24 '17 at 00:22
  • No, it's using WPF with other conditions, it was one of the POST's I've seen, however, if you read my POST I'm using Windows Forms which is different and what's more, I quoted the same repository. – Márcio Eric Jun 24 '17 at 19:35
  • I don't suppose there's any chance you ever figured this out and would be willing to post it as an answer? – Sidney Aug 13 '20 at 19:04
  • In fact I ended up finding out after all ... But it was a long time after this post, I will look here for the repository and post it here. – Márcio Eric Aug 28 '20 at 01:21

1 Answers1

1

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));
Sidney
  • 624
  • 7
  • 20