0

I'm trying to trigger a notification which has no expiry but must be closed by pressing the top-right X close button. Is this possible?

enter image description here

I've been able to trigger a timed notification which also closes when anywhere else is clicked. With this answer.

[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
[reflection.assembly]::loadwithpartialname("System.Drawing")
$notify = new-object system.windows.forms.notifyicon
$notify.icon = [System.Drawing.SystemIcons]::Information
$notify.visible = $true
$notify.showballoontip(10,"New Chat!","You have received New Chat!",[system.windows.forms.tooltipicon]::None) 
Ben Racicot
  • 5,332
  • 12
  • 66
  • 130
  • Do you mean a popup message that does not have any buttons to close it and can be closed only with `X`? If that's the case, I believe you'll have to create a custom form since the default pop-up methods such as https://learn.microsoft.com/en-us/previous-versions/windows/internet-explorer/ie-developer/windows-scripting/x83z1d9f(v=vs.84)?redirectedfrom=MSDN have at least an `OK` button. – Santiago Squarzon Apr 29 '21 at 23:25
  • Hey @SantiagoSquarzon not as you describe. A standard notification popup. The only thing it needs that is unique is to not expire on its own or close on its own. It must be closed by clicking the usual close button. – Ben Racicot Apr 30 '21 at 12:16
  • Can't you set an async timer to regularly re-display the ballon tip until you get the `BalloonTipClosed` event ? – Zilog80 May 02 '21 at 13:08

1 Answers1

1

Per Microsofts NotifyIcon.ShowBalloonTip Method documentation, the actual timeout property is set by the current system settings.

Minimum and maximum timeout values are enforced by the operating system and are typically 10 and 30 seconds, respectively, however this can vary depending on the operating system. Timeout values that are too large or too small are adjusted to the appropriate minimum or maximum value. In addition, if the user does not appear to be using the computer (no keyboard or mouse events are occurring) then the system does not count this time towards the timeout.

According to a couple of more google searches, you can set the time for your profile through the Registry ( Regedit - HKEY_CURRENT_USER\Control Panel\Accessibility: MessageDuration - didn't work for me).

Through group policy, or using theSystemParametersInfo API which is out of my league to explain any further. Only reference I can find was configuring the Accessibility/System Parameter: SPI_SETMESSAGEDURATION. Its C++ though and only other article I could find was this one:SystemParametersInfoA function.

Seems possible but, it will definitely be a hassle to get it working.

Abraham Zinala
  • 4,267
  • 3
  • 9
  • 24
  • Hey @Abraham Zinala, thank you for your time on this. I have gotten this far with system timeout set to 30 seconds. However, real notifications persist despite clicking elsewhere. Test ones triggered by the script above exit when any mouse click occurs anywhere. So even with 30 seconds set I cannot work with notifs that disappear. – Ben Racicot May 03 '21 at 13:29