Notifications

Post Reply
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Notifications

Post by Natter »

Hi,

My application is placed in Systray at startup. Sometimes I activate system notifications from my application (via PS). Each notification contains a text and an icon. Everything works well. However, if you look into SysTray, there will be as many icons as there were messages. When you hover the mouse cursor over these icons, they disappear. What could it be ?
User avatar
karinha
Posts: 7948
Joined: Tue Dec 20, 2005 7:36 pm
Location: São Paulo - Brasil
Been thanked: 3 times
Contact:

Re: Notifications

Post by karinha »

Muestre un ejemplo simple, por favor.

Show a simple example, please.

Regards, saludos.
João Santos - São Paulo - Brasil - Phone: +55(11)95150-7341
User avatar
Antonio Linares
Site Admin
Posts: 42595
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 39 times
Been thanked: 86 times
Contact:

Re: Notifications

Post by Antonio Linares »

Dear Yuri,

You may try a SysRefresh() call after each message
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Notifications

Post by Natter »

SysRefresh() does not help.

hdn.bat - to call the PS script

Code: Select all | Expand

%comspec% /c powershell -executionpolicy RemoteSigned -file C:\ZVK\TMP\my.ps1


my.ps1 - PS script

Code: Select all | Expand

Add-Type -AssemblyName  System.Windows.Forms
$global:balmsg = New-Object System.Windows.Forms.NotifyIcon
$balmsg.Icon = '\\192.168.4.11\zvk\zvk.ico'
$balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
$balmsg.BalloonTipText ='ABCDEF'
$balmsg.BalloonTipTitle = 'My text'
$balmsg.Visible = $true
$balmsg.ShowBalloonTip(500000)


For some reason, with such a call, the icon appears in the Systray window :(
User avatar
Antonio Linares
Site Admin
Posts: 42595
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 39 times
Been thanked: 86 times
Contact:

Re: Notifications

Post by Antonio Linares »

Please move this line to the end:
$balmsg.Visible = $true

https://stackoverflow.com/questions/20615151/how-can-i-close-a-notifyicon-ballontooltip-from-code

He uses an extra this.Hide(); that I don't know which control applies. You may try this:
$balmsg.Hide()

or
$balmsg.Visible = $false
regards, saludos

Antonio Linares
www.fivetechsoft.com
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Notifications

Post by Natter »

I already specified in the script - $balms.Visible = $true. :o
In addition, true without $ gives an error
Natter
Posts: 1244
Joined: Mon May 14, 2007 9:49 am

Re: Notifications

Post by Natter »

Removed the line from the script:

Code: Select all | Expand

$balmsg.BalloonTipIcon = [System.Windows.Forms.ToolTipIcon]::Warning
 


Everything worked :D
User avatar
Antonio Linares
Site Admin
Posts: 42595
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 39 times
Been thanked: 86 times
Contact:

Re: Notifications

Post by Antonio Linares »

cool! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
User avatar
Jimmy
Posts: 1740
Joined: Thu Sep 05, 2019 5:32 am
Location: Hamburg, Germany
Has thanked: 2 times

Re: Notifications

Post by Jimmy »

hi,

try this CODE from HMG Forum (will run under FiveWin)

Code: Select all | Expand

#include "FIVEWIN.CH"
#define WIN_NIIF_USER                      0x00000004

/*------------------------------------------------------
MsgBalloon( cMessage, [ cTitle ], [ xIcon ], [ nFlags ] ) -> nil

Copyright 2007-2013 Grigory Filatov <gfil...@inbox.ru>

Parameters:
cMessage        -> info text
cTitle          -> info title
xIcon           -> resource id / resource name / filename
                   of the icon displayed to the left of the title
nFlags          -> bit masked icon flags (default = WIN_NIIF_INFO)
                   for the icon displayed to the left of the message
                  set from ShellNotifyIcon() dwInfoFlags values:
                  #define WIN_NIIF_NONE                      0x00000000
                  #define WIN_NIIF_INFO                      0x00000001
                  #define WIN_NIIF_WARNING                   0x00000002
                  #define WIN_NIIF_ERROR                     0x00000003
                  #define WIN_NIIF_USER                      0x00000004
                  #define WIN_NIIF_NOSOUND                   0x00000010
                  #define WIN_NIIF_LARGE_ICON                0x00000020
                  #define WIN_NIIF_RESPECT_QUIET_TIME        0x00000080
                  #define WIN_NIIF_ICON_MASK                 0x0000000F
                  if nFlags is used via symbolic names it's needed to include "hbwin.ch" in source

Samples:
MsgBallon( "Some text" )
MsgBallon( "Some text", "A title" )
MsgBallon( "Some text", "A title", 123 )  123 is the id of the icon set in resource file
MsgBallon( "Some text", "A title", "PRGICON" ) "PRGICON" is the icon name set in resource file
MsgBallon( "Some text", "A title", "c:\path\icon.ico" )
MsgBallon( "Some text", "A title", "c:\path\icon.ico", NIIF_ERROR ) same as previous, but with an error icon
MsgBallon( "Some text", "A title", "c:\path\icon.ico", NIIF_USER + NIIF_NOSOUND ) no sound, same icon as title icon

--------------------------------------------------------*/


Procedure Main
*  MsgBalloon( "Any text", "Any title", "A2MAIN", WIN_NIIF_USER )
*  MsgBalloon( "Some text", "A title", "A2MAIN" )
   MsgBalloon( "Some text", "A title", 10002 )
RETURN

function MsgBalloon( cMessage, cTitle, xIcon, nFlags )

   ShowNotifyInfo( 0, .F. , xIcon, NIL, NIL, NIL, NIL )
   ShowNotifyInfo( 0, .T. , xIcon, NIL, cMessage, cTitle, hb_defaultValue( nFlags, 1 ) )

Return Nil

#pragma BEGINDUMP

      #include <windows.h>
      #include "hbapi.h"

      static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szText, LPSTR szInfo, LPSTR szInfoTitle, int nFlags );

      HB_FUNC ( SHOWNOTIFYINFO )
      {

         HICON hIcon;
         if ( HB_ISNUM( 3 ) )
         {
            hIcon = LoadIcon( ( HINSTANCE ) GetModuleHandle( NULL ), MAKEINTRESOURCE( hb_parni( 3 ) ) );
         }
         else
         {
            hIcon = LoadIcon( ( HINSTANCE ) GetModuleHandle( NULL ), hb_parc( 3 ) );
            if ( hIcon == NULL )
               hIcon = ( HICON ) LoadImage( ( HINSTANCE ) NULL, hb_parc( 3 ), IMAGE_ICON, 0, 0, LR_LOADFROMFILE );
         }

         ShowNotifyInfo( (HWND) hb_parnl(1), (BOOL) hb_parl(2), hIcon , (LPSTR) hb_parc(4), (LPSTR) hb_parc(5), (LPSTR) hb_parc(6), hb_parni( 7 ) );

      }

      static void ShowNotifyInfo(HWND hWnd, BOOL bAdd, HICON hIcon, LPSTR szText, LPSTR szInfo, LPSTR szInfoTitle, INT nFlags )
      {
          NOTIFYICONDATA nid;

          ZeroMemory( &nid, sizeof(nid) );

          nid.cbSize        = sizeof(NOTIFYICONDATA);
          nid.hIcon         = hIcon;
          nid.hWnd          = hWnd;
          nid.uID           = 0;
          nid.uFlags        = NIF_INFO | NIF_ICON;
          nid.dwInfoFlags   = nFlags;

          lstrcpy( nid.szTip, TEXT(szText) );
          lstrcpy( nid.szInfo, TEXT(szInfo) );
          lstrcpy( nid.szInfoTitle, TEXT(szInfoTitle) );

          if(bAdd)
              Shell_NotifyIcon( NIM_ADD, &nid );
          else
              Shell_NotifyIcon( NIM_DELETE, &nid );

          if(hIcon)
              DestroyIcon( hIcon );
      }

#pragma ENDDUMP
greeting,
Jimmy
User avatar
Antonio Linares
Site Admin
Posts: 42595
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Has thanked: 39 times
Been thanked: 86 times
Contact:

Re: Notifications

Post by Antonio Linares »

Thank you Jimmy :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Post Reply