Recent

Author Topic: Shell_NotifyIconW  (Read 9056 times)

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Shell_NotifyIconW
« Reply #15 on: October 12, 2021, 01:00:15 pm »
Show me the code how to get the notification without the balloon using trayicon
« Last Edit: October 12, 2021, 01:05:43 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

dbannon

  • Hero Member
  • *****
  • Posts: 2791
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Shell_NotifyIconW
« Reply #16 on: October 12, 2021, 01:39:06 pm »
maybe -

Code: Pascal  [Select][+][-]
  1. procedure TForm1.Button1Click(Sender: TObject);
  2. begin
  3.     TrayIcon1.ShowBalloonHint := 'Hello, I am a balloon hint');
  4.     TrayIcon1.BalloonTimeout := 50;                    // thats mS
  5.     TrayIcon1.ShowBalloonHint;
  6. end;    

Tested on Linux were it produces a very ugly and obtrusive oversized yellow box (and I use libnotifier instead), 50mS is just noticable, 10mS is not but I assume the event is still fired.  I allow myself only one boot into windows each day and I did that earlier to see if it works through the windows notifier system (yes, it does). 

I suggest you try it yourself.

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Shell_NotifyIconW
« Reply #17 on: October 12, 2021, 02:34:46 pm »
I have, and it doesn't work
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

balazsszekely

  • Guest
Re: Shell_NotifyIconW
« Reply #18 on: October 12, 2021, 09:25:14 pm »
@pcurtis
On Win10 you have to enable balloon hints firts. You can do it with the Group Policy Editor.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Shell_NotifyIconW
« Reply #19 on: October 12, 2021, 09:34:10 pm »
they are enabled. i want to stop them programmatically

attached is a screenshot of a balloon
« Last Edit: October 12, 2021, 09:49:54 pm by pcurtis »
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

dbannon

  • Hero Member
  • *****
  • Posts: 2791
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Shell_NotifyIconW
« Reply #20 on: October 13, 2021, 02:31:37 am »
I have, and it doesn't work

Well, its not clear at all to me just what 'it' is. 
As I understand it, you are talking about W10's ability to alert the user of some minor event. First we see a slide out box from the right side of screen, it goes away in a few seconds, then the user can go looking for that notification and see it in a larger, ad filled slide out ?

I understand you want the notification available if the user goes looking but do not want the slide out to appear ?

So, when you say "it doesn't work", just what does not work ?  Do you see the initial slideout for the full 3 seconds and cannot reduce that ?  Is the notification not recorded at all ? Does smoke come out of your computer ?

Your average word count is about ten words per post in this thread, can you be  little more expansive ?

Davo


Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Shell_NotifyIconW
« Reply #21 on: October 13, 2021, 05:00:25 am »
Yes I want to stop the slide out from appearing (hide the balloon).
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

balazsszekely

  • Guest
Re: Shell_NotifyIconW
« Reply #22 on: October 13, 2021, 08:44:54 am »
@pcurtis

You seem to confuse Balloon notifications with Toast notifications.

1. Balloon notifications
If you wish to enable Balloon notifications on Win10, press "Windows Key + R", then type "gpedit.msc" + enter. After the "Group Policy Editor" appears, follow the instructions from the first screenshot. Please note that in order for the changes to take effect a restart is needed. Balloon notification is a well documented and tested feature. You can find a detailed Delphi implementation here:
   https://github.com/coolshou/CoolTrayIcon/blob/master/Source/CoolTrayIcon.pas
Search for ShowBalloonHint and HideBalloonHint functions. It shouldn't take to much time to convert it to Lazarus. Actually I tested the code on Win10 and it works fine:
   https://youtu.be/MRdoWBYSDcI

2. Toast notification
This is the default notification in Win10, but you must also enable it in "Notifications & actions", by switching "Get notifications from apps and other senders" to "On". The same code(see above) will show a toast notification in the right panel, however it does not hide it(see second screenshot). You should do a google search: "hide toast notification" or "hide toast notification with delphi", maybe the API has changed.

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Shell_NotifyIconW
« Reply #23 on: October 13, 2021, 11:18:24 am »
OK I wan't to stop the slide out dialog.

Quote
You can find a detailed Delphi implementation here:
   https://github.com/coolshou/CoolTrayIcon/blob/master/Source/CoolTrayIcon.pas
Search for ShowBalloonHint and HideBalloonHint functions. It shouldn't take to much time to convert it to Lazarus. Actually I tested the code on Win10 and it works fine:
   https://youtu.be/MRdoWBYSDcI
 
Thats above my level. Thats why I asked here for help
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

balazsszekely

  • Guest
Re: Shell_NotifyIconW
« Reply #24 on: October 13, 2021, 01:37:03 pm »
@pcurtis

I ran a few tests with Delphi 11 Alexandria, which supports the Win10 notification center via TNotificationCenter/TNotification classes. Showing a toast message is quite simple:
Code: Pascal  [Select][+][-]
  1. var
  2.   Notification: TNotification;
  3. begin
  4.   Notification := NotificationCenter.CreateNotification;
  5.   try
  6.     Notification.Name := 'myNotification';
  7.     Notification.Title := 'Notification';
  8.     Notification.AlertBody := 'Test test test';
  9.     NotificationCenter.PresentNotification(Notification);
  10.   finally
  11.     MyNotification.Free;
  12.   end;
  13. end;
The above code works fine.

According to de documentation, the following code should remove the notification:
Code: Pascal  [Select][+][-]
  1. NotificationCenter.CancelAll;
  2.  
  3. {Use CancelAll to cancels all notifications:
  4. - The notifications that are scheduled will not be fired.
  5. - The notifications, that belong to this application, and are available in the notification center or notification drawer are also cancelled and removed.}
Unfortunately it does not work, something fishy is happening here.

Quote
Thats above my level. Thats why I asked here for help
I don't have time to translate that code to Lazarus, but as you can see it won't work with toast notification. Even the dedicated components from Delphi does not work and I have no idea why.
« Last Edit: October 13, 2021, 01:48:23 pm by GetMem »

dbannon

  • Hero Member
  • *****
  • Posts: 2791
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Shell_NotifyIconW
« Reply #25 on: October 13, 2021, 02:06:51 pm »
> Unfortunately it does not work, something fishy is happening here.

Well, I had a poke around the Lazarus TrayIcon code, its identical to the block of code circulating on this thread ending with Shell_NotifyIconW(NIM_MODIFY, @NotifyData);

pcurtis's "does not work" could be translated to "if you set the NotifyData.szInfo[0] := 0 it does not compile (obviously) and if you set it to WideChar(0); it compiles and runs fine but no notification is recorded by Windows.".

Clearly, some time in the past, setting NotifyData.szInfo must have "worked" and setting the timeout (which is ignored) must have done what we'd expect. That says to me that MS have redefined the API, probably in a effort to make the notifier experience more uniform. They don't want different applications doing different things, if you send a notification expect a "banner" (thats the small slider) to be visible for 3-4 seconds (as long as the user has not turned the banner off).

Incidentally, on my Windows install I have changed almost none of the settings, by default, that banner or Toaster as Getmem calls it, is enabled for all apps.

pcurtis, what I suggest you do is accept the banner is going to appear. You can however determine what it says, so, how about settings it's title to the name of some Windows Service ?  The users who find it really annoying will blame that service and not your app !

Davo
Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

balazsszekely

  • Guest
Re: Shell_NotifyIconW
« Reply #26 on: October 13, 2021, 02:22:22 pm »
« Last Edit: October 13, 2021, 02:40:48 pm by GetMem »

pcurtis

  • Hero Member
  • *****
  • Posts: 951
Re: Shell_NotifyIconW
« Reply #27 on: October 13, 2021, 02:48:49 pm »
https://docs.microsoft.com/en-us/windows/win32/api/shellapi/ns-shellapi-notifyicondataa

NIF_INFO (0x00000010)

0x00000010. Display a balloon notification. The szInfo, szInfoTitle, dwInfoFlags, and uTimeout members are valid. Note that uTimeout is valid only in Windows 2000 and Windows XP.

    To display the balloon notification, specify NIF_INFO and provide text in szInfo.
    To remove a balloon notification, specify NIF_INFO and provide an empty string through szInfo.
    To add a notification area icon without displaying a notification, do not set the NIF_INFO flag.

Does this mean in W10 no can do?
Windows 10 20H2
Laz 2.2.0
FPC 3.2.2

balazsszekely

  • Guest
Re: Shell_NotifyIconW
« Reply #28 on: October 13, 2021, 03:05:51 pm »
Quote
To display the balloon notification, specify NIF_INFO and provide text in szInfo.
To add a notification area icon without displaying a notification, do not set the NIF_INFO flag.
Works with xp, win7(balloon) and win8, win10(balloon + toast).

Quote
To remove a balloon notification, specify NIF_INFO and provide an empty string through szInfo.
That's exactly what cooltrayicon does:
Code: Pascal  [Select][+][-]
  1. function TCoolTrayIcon.HideBalloonHint: Boolean;
  2. // Hide balloon hint. Return false if error.
  3. begin
  4.   with IconData do
  5.   begin
  6.     uFlags := uFlags or NIF_INFO;
  7.     StrPCopy(szInfo, '');
  8.   end;
  9.   Result := ModifyIcon;
  10. end;
Works with xp, win7, win8, win10(balloon),  does not work with win10 toast notifications. I have nothing more to say, Picard out.

dbannon

  • Hero Member
  • *****
  • Posts: 2791
    • tomboy-ng, a rewrite of the classic Tomboy
Re: Shell_NotifyIconW
« Reply #29 on: October 14, 2021, 12:39:11 am »
Quote
that banner or Toaster as Getmem calls it, is enabled for all apps.
I'm afraid this is the official name :):

I respectfully suggest that Windows users (as opposed to developers) are more likely to know it as the Notification Banner. But I do like your reasoning for the name "Toast"   :D

Lazarus 3, Linux (and reluctantly Win10/11, OSX Monterey)
My Project - https://github.com/tomboy-notes/tomboy-ng and my github - https://github.com/davidbannon

 

TinyPortal © 2005-2018