4
votes

I'm trying to make my toast window to act exactly same as tray balloon tip. It must stay in front of every window and not steal focus. But when i press show desktop button in right bottom corner of Windows 7 and show this toast window 5 seconds later then it not show up in my screen. But when i select another window in taskbar it show up afterwards.

When i use top most for toast form it shows always properly but then it steals focus from directx games etc. and returning to desktop therefore i can't use top most.

This is what i'm doing:

NotificationForm form = new NotificationForm(5000, new Size(400, 300), img, url);
NativeMethods.ShowWindow(form.Handle, (int)WindowShowStyle.ShowNoActivate);
NativeMethods.SetWindowPos(form.Handle, (IntPtr)SpecialWindowHandles.HWND_TOP, 0, 0, 0, 0,
    SetWindowPosFlags.SWP_NOMOVE | SetWindowPosFlags.SWP_NOSIZE | SetWindowPosFlags.SWP_NOACTIVATE);

Full source code here:

https://github.com/ShareX/ShareX/blob/master/ShareX/Forms/NotificationForm.cs

I think Windows balloon tip is using top most and still manages to not steal focus when playing fullscreen directx games. Not sure how it works.

1

1 Answers

0
votes

If I'm not mistaken, I don't think the Windows balloon tips actually are windows. I think they use the desktop "window" and draw directly to the screen. Maybe look at trying to find the active window and draw your "toast" directly on it if its fullscreen rather than creating another window? I did something similar to this for a CRM suite one time where we had a fullscreen view and we wanted to have an accessibility overlay for CSRs who had vision impairment. Here's what I did to accomplish that:

  • GetActiveWindow() to retrieve the handle of the current focused window
  • GetWindowRect() and compared it to the screen size to figure out if it was fullscreen (because maximized programs are still shorter than the full screen because of the task bar)
  • If it was fullscreen, GetDC() to retrieve the device context for drawing (I believe this is the Graphics object in .NET)
  • Then I drew object straight on that window, covering what was on the screen in that place. Transparency is a little more difficult to do, but not impossible. Look up alpha-blending and the math involved with that.

It wasn't particularly pretty but it worked well enough for me.