New UserLib : NotifyIcon library

Windows specific forum
Pantcho!!
Enthusiast
Enthusiast
Posts: 538
Joined: Tue Feb 24, 2004 3:43 am
Location: Israel
Contact:

Post by Pantcho!! »

great lib.

add features suggestions:

1. ballon background and foreground color.
2. ballon time to wait for user to click or to refuse ( for example shows for 1 second and auto disappear)
3. display images in the ballon (will be great!, and i know this is possible)

thank you!!!
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

Is it possible to check if the systray icon is "on" / "active" without using a Callback?

A ni_Status() would be nice... :)

Cheers!
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

One more thing, what I understand you must have a WindowID for the built in SysTrayIcon functions and for the NotifyIcon lib you don't?!?

Is this right?

I remember some years ago, I was coding someting in C and read at msdn that there was a bug / feature - so you had to have a window open to use a systray icon. Microsofts solution was that you should hide the window and make it 1 x 1 pixel.

:lol:
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
Micko
Enthusiast
Enthusiast
Posts: 244
Joined: Thu May 24, 2007 7:36 pm
Location: Senegal
Contact:

Post by Micko »

I guy ! Can somebaody update this lib to PB 4.30 i just try but have an error
PS: The source is in the 1rst post
thanks you

[Edit]
can Somebody convert this Flype source to make it work with PB 4.30 please ?
this is the ressource code

Code: Select all

;-           
;- Object:   NotifyIcon UserLibrary / SHELL_NOTIFYICON
;-           
;- Descr.    Set of functions for the Systray Icon
;-           From the 'shellapi.h' Microsoft include file
;-           
;- Version:  1.0 Beta
;- Date:     Mars 2005
;-           
;- Author:   Philippe 'Flype' Carpentier
;- Email:    flype@altern.org
;- 


;/
;/ USER DEFINED : NotifyIcon UserLibrary
;/

;#WM_USER              = $400
#WM_NOTIFYICON        = $400 + $7258

;/
;/ NIM_xxx
;/

;#NIM_ADD              = 0 ; 95+
;#NIM_MODIFY           = 1 ; 95+
;#NIM_DELETE           = 2 ; 95+
#NIM_SETFOCUS         = 3 ; 2000+
#NIM_SETVERSION       = 4 ; 2000+
  
;/
;/ NIF_xxx
;/
  
;#NIF_MESSAGE          = $01 ; 95+
;#NIF_ICON             = $02 ; 95+
;#NIF_TIP              = $04 ; 95+
;#NIF_STATE            = $08 ; 95+
#NIF_INFO             = $10 ; 2000+
#NIF_GUID             = $20 ; XP+ Reserved
  
;/
;/ NIS_xxx
;/
  
#NIS_HIDDEN           = 1 ; 2000+
#NIS_SHAREDICON       = 2 ; 2000+
  
;/
;/ NIIF_xxx
;/
  
#NIIF_NONE            = $00 ; 2000+
#NIIF_INFO            = $01 ; 2000+
#NIIF_WARNING         = $02 ; 2000+
#NIIF_ERROR           = $03 ; 2000+
#NIIF_USER            = $04 ; XPSP2+
#NIIF_ICON_MASK       = $0F ; XP+ Reserved
#NIIF_NOSOUND         = $10 ; XP+ Reserved

;/
;/ NIN_xxx
;/
  
#NINF_KEY             = 1
#NIN_SELECT           = $400
#NIN_KEYSELECT        = #NIN_SELECT | #NINF_KEY
  
#NIN_BALLOONSHOW      = $400 + 2 ; XP+
#NIN_BALLOONHIDE      = $400 + 3 ; XP+
#NIN_BALLOONTIMEOUT   = $400 + 4 ; XP+
#NIN_BALLOONUSERCLICK = $400 + 5 ; XP+
  
;/
;/ NOTIFY_xxx
;/

#NOTIFYICON_VERSION     = 3   ; 2000+
#NOTIFYICONDATA_V1_SIZE = 88  ; 95+
#NOTIFYICONDATA_V2_SIZE = 488 ; 2000+
#NOTIFYICONDATA_V3_SIZE = 504 ; XP+
and here the Lib code:

Code: Select all

;-           
;- Object:   NotifyIcon UserLibrary / SHELL_NOTIFYICON
;-           
;- Descr.    Set of functions for the Systray Icon
;-           From the 'shellapi.h' Microsoft include file
;-           
;- Version:  1.0 Beta
;- Date:     Mars 2005
;-           
;- Author:   Philippe 'Flype' Carpentier
;- Email:    flype@altern.org
;- 

;-
;- Structures
;-

Structure NOTIFYICONDATA_95
  
  cbSize.l
  hwnd.l 
  uID.l 
  uFlags.l 
  uCallbackMessage.l 
  hIcon.l 
  szTip.b[64] 
  
EndStructure 
Structure NOTIFYICONDATA_2K Extends NOTIFYICONDATA_95
  
  szTipEx.b[64] 
  dwState.l
  dwStateMask.l 
  szInfo.b[256] 
  StructureUnion 
  uTimeout.l 
  uVersion.l 
  EndStructureUnion 
  szInfoTitle.b[64]
  
EndStructure 
Structure NOTIFYICONDATA_XP Extends NOTIFYICONDATA_2K
  
  dwInfoFlags.l
  guid.GUID
  
EndStructure 

;-
;- Constantes
;-

Enumeration ; #NIM
  
  #NIM_ADD        = 0 ; 95+
  #NIM_MODIFY     = 1 ; 95+
  #NIM_DELETE     = 2 ; 95+
  #NIM_SETFOCUS   = 3 ; 2000+
  #NIM_SETVERSION = 4 ; 2000+
  
EndEnumeration
Enumeration ; #NIF
  
  #NIF_MESSAGE = $01 ; 95+
  #NIF_ICON    = $02 ; 95+
  #NIF_TIP     = $04 ; 95+
  #NIF_STATE   = $08 ; 95+
  #NIF_INFO    = $10 ; 2000+
  #NIF_GUID    = $20 ; XP+ Reserved
  
EndEnumeration
Enumeration ; #NIS
  
  #NIS_HIDDEN     = 1 ; 2000+
  #NIS_SHAREDICON = 2 ; 2000+
  
EndEnumeration
Enumeration ; #NIIF
  
  #NIIF_NONE      = $00 ; 2000+
  #NIIF_INFO      = $01 ; 2000+
  #NIIF_WARNING   = $02 ; 2000+
  #NIIF_ERROR     = $03 ; 2000+
  #NIIF_USER      = $04 ; XPSP2+
  #NIIF_ICON_MASK = $0F ; XP+ Reserved
  #NIIF_NOSOUND   = $10 ; XP+ Reserved
  
EndEnumeration
Enumeration ; #NIN
  
  #NINF_KEY             = 1
  #NIN_SELECT           = #WM_USER
  #NIN_KEYSELECT        = #NIN_SELECT | #NINF_KEY
  
  #NIN_BALLOONSHOW      = #WM_USER + 2 ; XP+
  #NIN_BALLOONHIDE      = #WM_USER + 3 ; XP+
  #NIN_BALLOONTIMEOUT   = #WM_USER + 4 ; XP+
  #NIN_BALLOONUSERCLICK = #WM_USER + 5 ; XP+
  
  #WM_NOTIFYICON        = #WM_USER + $7258
  
EndEnumeration
Enumeration ; #NOTIFY
  
  #NOTIFYICON_VERSION = 3       ; 2000+
  
  #NOTIFYICONDATA_V1_SIZE = 88  ; 95+
  #NOTIFYICONDATA_V2_SIZE = 488 ; 2000+
  #NOTIFYICONDATA_V3_SIZE = 504 ; XP+
  
EndEnumeration

;-
;- Private functions
;-

Procedure.b ni_0500()
  
  If OSVersion() >= #PB_OS_Windows_2000
    
    ProcedureReturn #True
    
  EndIf
  
EndProcedure
Procedure.b ni_0600()
  
  If OSVersion() >= #PB_OS_Windows_XP
    
    ProcedureReturn #True
    
  EndIf
  
EndProcedure

Procedure.l ni_Info95(uID.l, szTip.s) 
  
  Protected uID.l
  Protected szTip.s
  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd   = WindowID()
  ni\uID    = uID
  ni\uFlags = #NIF_TIP
  
  PokeS(@ni\szTip,szTip,64)
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
  
EndProcedure
Procedure.l ni_Info2K(uID.l, szInfoTitle.s, szInfo.s) 
  
  Protected uID.l
  Protected szInfo.s
  Protected szInfoTitle.s
  Protected ni.NOTIFYICONDATA_2K
  
  ni\cbSize = #NOTIFYICONDATA_V2_SIZE
  ni\hwnd   = WindowID()
  ni\uID    = uID
  ni\uFlags = #NIF_INFO
  
  PokeS(@ni\szInfo,szInfo,256) 
  PokeS(@ni\szInfoTitle,szInfoTitle,64) 
  
  ni\uVersion = #NOTIFYICON_VERSION 
  Shell_NotifyIcon_(#NIM_SETVERSION,@ni)
  
  ni\uTimeout = 5000
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
  
EndProcedure
Procedure.l ni_InfoXP(uID.l, szInfoTitle.s, szInfo.s, dwInfoFlags.l) 
  
  Protected uID.l
  Protected szInfo.s
  Protected szInfoTitle.s
  Protected dwInfoFlags.l
  Protected ni.NOTIFYICONDATA_XP
  
  ni\cbSize      = #NOTIFYICONDATA_V3_SIZE
  ni\hwnd        = WindowID()
  ni\uID         = uID
  ni\uFlags      = #NIF_INFO
  ni\dwInfoFlags = dwInfoFlags
  
  PokeS(@ni\szInfo,szInfo,256) 
  PokeS(@ni\szInfoTitle,szInfoTitle,64)
  
  ni\uVersion = #NOTIFYICON_VERSION 
  Shell_NotifyIcon_(#NIM_SETVERSION,@ni)
  
  ni\uTimeout = 5000
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
  
EndProcedure

;-
;- Public functions
;-

ProcedureDLL.l ni_DefaultIcon()
  
  If CatchImage(#PB_Any,?DefaultNotifyIcon)
    ProcedureReturn ImageID()
  EndIf
  
EndProcedure
ProcedureDLL.l ni_ExtractIcon()
  
  Protected lpFileName.s
  
  lpFileName = Space(#MAX_PATH)
  
  If GetModuleFileName_(#Null,lpFileName,#MAX_PATH)
    ProcedureReturn ExtractIcon_(GetModuleHandle_(#Null),lpFileName,#Null)
  EndIf
  
EndProcedure
ProcedureDLL.l ni_LoadIcon(IconName.s)
  
  Protected IconName.s
  
  ProcedureReturn LoadImage_(GetModuleHandle_(#Null),IconName,#IMAGE_ICON,0,0,#LR_LOADFROMFILE)
  
EndProcedure

ProcedureDLL.l ni_IconApplication()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_APPLICATION)
  
EndProcedure
ProcedureDLL.l ni_IconAsterix()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_ASTERISK)
  
EndProcedure
ProcedureDLL.l ni_IconExclamation()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_EXCLAMATION)
  
EndProcedure
ProcedureDLL.l ni_IconHand()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_HAND)
  
EndProcedure
ProcedureDLL.l ni_IconQuestion()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_QUESTION)
  
EndProcedure
ProcedureDLL.l ni_IconWinLogo()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_WINLOGO)
  
EndProcedure

ProcedureDLL.l ni_Add(uID.l, tip.s, hIcon.l)
  
  Protected uID.l
  Protected hIcon.l
  Protected szTip.s
  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize           = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd             = WindowID()
  ni\uID              = uID
  ni\uFlags           = #NIF_MESSAGE | #NIF_ICON | #NIF_TIP
  ni\uCallbackMessage = #WM_NOTIFYICON
  ni\hIcon            = hIcon
  
  If ni_0500()
    PokeS(@ni\szTip,tip,128)
    ProcedureReturn Shell_NotifyIcon_(#NIM_ADD,@ni)
  EndIf
  
  PokeS(@ni\szTip,tip,64)
  ProcedureReturn Shell_NotifyIcon_(#NIM_ADD,@ni)
  
EndProcedure
ProcedureDLL.l ni_Remove(uID.l)
  
  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd   = WindowID()
  ni\uID    = uID
  
  ProcedureReturn Shell_NotifyIcon_(#NIM_DELETE,@ni)
  
EndProcedure

ProcedureDLL.l ni_Icon(uID.l, hIcon.l)
  
  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd   = WindowID()
  ni\uID    = uID
  ni\hIcon  = hIcon
  ni\uFlags = #NIF_ICON
  
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni)
  
EndProcedure
ProcedureDLL.l ni_Tip(uID.l, tip.s)
  
  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd   = WindowID()
  ni\uID    = uID
  ni\uFlags = #NIF_TIP
  
  If ni_0500()
    PokeS(@ni\szTip,tip,128)
    ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni)
  EndIf
  
  PokeS(@ni\szTip,tip,64)
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni)
  
EndProcedure
ProcedureDLL.l ni_Focus(uID.l)
  
  Protected uID.l
  Protected ni.NOTIFYICONDATA_2K
  
  If ni_0500()
    
    ni\cbSize = #NOTIFYICONDATA_V2_SIZE
    ni\hwnd   = WindowID()
    ni\uID    = uID
    
    ProcedureReturn Shell_NotifyIcon_(#NIM_SETFOCUS,@ni) 
    
  EndIf
  
EndProcedure
ProcedureDLL.l ni_Show(uID.l)
  
  Protected uID.l
  Protected ni.NOTIFYICONDATA_2K
  
  If ni_0500()
    
    ni\cbSize = #NOTIFYICONDATA_V2_SIZE
    ni\hwnd   = WindowID()
    ni\uID    = uID
    ni\uFlags = #NIF_STATE
    
    ni\dwState     = #Null
    ni\dwStateMask = #NIS_HIDDEN
    
    ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
    
  EndIf
  
EndProcedure
ProcedureDLL.l ni_Hide(uID.l)
  
  Protected uID.l
  Protected ni.NOTIFYICONDATA_2K
  
  If ni_0500()
    
    ni\cbSize = #NOTIFYICONDATA_V2_SIZE
    ni\hwnd   = WindowID()
    ni\uID    = uID
    ni\uFlags = #NIF_STATE
    
    ni\dwState     = #NIS_HIDDEN
    ni\dwStateMask = #NIS_HIDDEN
    
    ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
    
  EndIf
  
EndProcedure

ProcedureDLL.l ni_Info(uID.l, title.s, info.s, Flags.l) 
  
  Protected uID.l
  Protected info.s
  Protected title.s
  Protected Flags.l
  
  If ni_0600()
    ProcedureReturn ni_InfoXP(uID,title,info,Flags)
  EndIf
  
  If ni_0500()
    ProcedureReturn ni_Info2K(uID,title,info)
  EndIf
  
  ProcedureReturn ni_Info95(uID,info)
  
EndProcedure

;-
;- DATA SECTION
;-

DataSection
  DefaultNotifyIcon: IncludeBinary "purebasic.ico"
EndDataSection
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: New UserLib : NotifyIcon library

Post by Derren »

Here is a code that "runs" (doesn't produce any syntax errors that come from the code being old).
But it doesn't do anything.

I have an VBA example that uses Shell_NotifyIcon() to display a notification popup, so this function still works in Windows 10.
I just cant get it to run in PB (can't even get it to add a systray icon at all (sometimes the function returns 1, sometimes 0, in either case, no icon is visible), which seems to be a pre-requisite for creating a popup).

And apparently this code DID work 17 years ago.

Idk, any takers?

Code: Select all

;-           
;- Object:   NotifyIcon UserLibrary / SHELL_NOTIFYICON
;-           
;- Descr.    Set of functions for the Systray Icon
;-           From the 'shellapi.h' Microsoft include file
;-           
;- Version:  1.0 Beta
;- Date:     Mars 2005
;-           
;- Author:   Philippe 'Flype' Carpentier
;- Email:    flype@altern.org
;- 

;-
;- Structures
;-

Structure NOTIFYICONDATA_95
  
  cbSize.l
  hwnd.l 
  uID.l 
  uFlags.l 
  uCallbackMessage.l 
  hIcon.l 
  szTip.b[64] 
  
EndStructure 
Structure NOTIFYICONDATA_2K Extends NOTIFYICONDATA_95
  
  szTipEx.b[64] 
  dwState.l
  dwStateMask.l 
  szInfo.b[256] 
  StructureUnion 
  uTimeout.l 
  uVersion.l 
  EndStructureUnion 
  szInfoTitle.b[64]
  
EndStructure 
Structure NOTIFYICONDATA_XP Extends NOTIFYICONDATA_2K
  
  dwInfoFlags.l
  guid.GUID
  
EndStructure 

;-
;- Constantes
;-

Enumeration ; #NIM
  
  #NIM_ADD        = 0 ; 95+
  #NIM_MODIFY     = 1 ; 95+
  #NIM_DELETE     = 2 ; 95+
  #NIM_SETFOCUS   = 3 ; 2000+
  #NIM_SETVERSION = 4 ; 2000+
  
EndEnumeration
Enumeration ; #NIF
  
  #NIF_MESSAGE = $01 ; 95+
  #NIF_ICON    = $02 ; 95+
  #NIF_TIP     = $04 ; 95+
  #NIF_STATE   = $08 ; 95+
  #NIF_INFO    = $10 ; 2000+
  #NIF_GUID    = $20 ; XP+ Reserved
  
EndEnumeration
Enumeration ; #NIS
  
  #NIS_HIDDEN     = 1 ; 2000+
  #NIS_SHAREDICON = 2 ; 2000+
  
EndEnumeration
Enumeration ; #NIIF
  
  #NIIF_NONE      = $00 ; 2000+
  #NIIF_INFO      = $01 ; 2000+
  #NIIF_WARNING   = $02 ; 2000+
  #NIIF_ERROR     = $03 ; 2000+
  #NIIF_USER      = $04 ; XPSP2+
  #NIIF_ICON_MASK = $0F ; XP+ Reserved
  #NIIF_NOSOUND   = $10 ; XP+ Reserved
  
EndEnumeration
Enumeration ; #NIN
  
  #NINF_KEY             = 1
  #NIN_SELECT           = #WM_USER
  #NIN_KEYSELECT        = #NIN_SELECT | #NINF_KEY
  
  #NIN_BALLOONSHOW      = #WM_USER + 2 ; XP+
  #NIN_BALLOONHIDE      = #WM_USER + 3 ; XP+
  #NIN_BALLOONTIMEOUT   = #WM_USER + 4 ; XP+
  #NIN_BALLOONUSERCLICK = #WM_USER + 5 ; XP+
  
  #WM_NOTIFYICON        = #WM_USER + $7258
  
EndEnumeration
Enumeration ; #NOTIFY
  
  #NOTIFYICON_VERSION = 3       ; 2000+
  
  #NOTIFYICONDATA_V1_SIZE = 88  ; 95+
  #NOTIFYICONDATA_V2_SIZE = 488 ; 2000+
  #NOTIFYICONDATA_V3_SIZE = 504 ; XP+
  
EndEnumeration

;-
;- Private functions
;-

Procedure.b ni_0500()
  
  If OSVersion() >= #PB_OS_Windows_2000
    
    ProcedureReturn #True
    
  EndIf
  
EndProcedure
Procedure.b ni_0600()
  
  If OSVersion() >= #PB_OS_Windows_XP
    
    ProcedureReturn #True
    
  EndIf
  
EndProcedure

Procedure.l ni_Info95(uID.l, hWnd,szTip.s) 
  

  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd   = WhWnd
  ni\uID    = uID
  ni\uFlags = #NIF_TIP
  
  PokeS(@ni\szTip,szTip,64)
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
  
EndProcedure
Procedure.l ni_Info2K(uID.l, hWnd, szInfoTitle.s, szInfo.s) 
  

  Protected ni.NOTIFYICONDATA_2K
  
  ni\cbSize = #NOTIFYICONDATA_V2_SIZE
  ni\hwnd   = hWnd
  ni\uID    = uID
  ni\uFlags = #NIF_INFO
  
  PokeS(@ni\szInfo,szInfo,256) 
  PokeS(@ni\szInfoTitle,szInfoTitle,64) 
  
  ni\uVersion = #NOTIFYICON_VERSION 
  Shell_NotifyIcon_(#NIM_SETVERSION,@ni)
  
  ni\uTimeout = 5000
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
  
EndProcedure
Procedure.l ni_InfoXP(uID.l, hWnd, szInfoTitle.s, szInfo.s, dwInfoFlags.l) 
  

  Protected ni.NOTIFYICONDATA_XP
  
  
  
  ni\cbSize      = #NOTIFYICONDATA_V3_SIZE
  ni\hwnd        = hWnd
  ni\uID         = uID
  ni\uFlags      = #NIF_INFO
  ni\dwInfoFlags = dwInfoFlags
  
  PokeS(@ni\szInfo,szInfo,256) 
  PokeS(@ni\szInfoTitle,szInfoTitle,64)
  
  ni\uVersion = #NOTIFYICON_VERSION 
  Shell_NotifyIcon_(#NIM_SETVERSION,@ni)
  
  ni\uTimeout = 5000
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
  
EndProcedure

;-
;- Public functions
;-

ProcedureDLL.l ni_DefaultIcon()
  
  If CatchImage(#PB_Any,?DefaultNotifyIcon)
    ProcedureReturn ImageID(CatchImage(#PB_Any,?DefaultNotifyIcon))
  EndIf
  
EndProcedure
ProcedureDLL.l ni_ExtractIcon()
  
  Protected lpFileName.s
  
  lpFileName = Space(#MAX_PATH)
  
  If GetModuleFileName_(#Null,lpFileName,#MAX_PATH)
    ProcedureReturn ExtractIcon_(GetModuleHandle_(#Null),lpFileName,#Null)
  EndIf
  
EndProcedure
ProcedureDLL.l ni_LoadIcon(IconName.s)
  

  
  ProcedureReturn LoadImage_(GetModuleHandle_(#Null),IconName,#IMAGE_ICON,0,0,#LR_LOADFROMFILE)
  
EndProcedure

ProcedureDLL.l ni_IconApplication()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_APPLICATION)
  
EndProcedure
ProcedureDLL.l ni_IconAsterix()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_ASTERISK)
  
EndProcedure
ProcedureDLL.l ni_IconExclamation()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_EXCLAMATION)
  
EndProcedure
ProcedureDLL.l ni_IconHand()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_HAND)
  
EndProcedure
ProcedureDLL.l ni_IconQuestion()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_QUESTION)
  
EndProcedure
ProcedureDLL.l ni_IconWinLogo()
  
  ProcedureReturn LoadIcon_(#Null,#IDI_WINLOGO)
  
EndProcedure

ProcedureDLL.l ni_Add(uID.l, hWnd, tip.s, hIcon.l)
  

  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize           = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd             = hWnd
  ni\uID              = uID
  ni\uFlags           = #NIF_MESSAGE | #NIF_ICON | #NIF_TIP
  ni\uCallbackMessage = #WM_NOTIFYICON
  ni\hIcon            = hIcon
  
  If ni_0500()
    PokeS(@ni\szTip,tip,128)
    ProcedureReturn Shell_NotifyIcon_(#NIM_ADD,@ni)
  EndIf
  
  PokeS(@ni\szTip,tip,64)
  ProcedureReturn Shell_NotifyIcon_(#NIM_ADD,@ni)
  
EndProcedure
ProcedureDLL.l ni_Remove(uID.l, hWnd)
  
  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd   = hWnd
  ni\uID    = uID
  
  ProcedureReturn Shell_NotifyIcon_(#NIM_DELETE,@ni)
  
EndProcedure

ProcedureDLL.l ni_Icon(uID.l, hIcon.l, hWnd)
  
  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd   = hWnd
  ni\uID    = uID
  ni\hIcon  = hIcon
  ni\uFlags = #NIF_ICON
  
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni)
  
EndProcedure
ProcedureDLL.l ni_Tip(uID.l, tip.s, hWnd)
  
  Protected ni.NOTIFYICONDATA_95
  
  ni\cbSize = #NOTIFYICONDATA_V1_SIZE
  ni\hwnd   = hWnd
  ni\uID    = uID
  ni\uFlags = #NIF_TIP
  
  If ni_0500()
    PokeS(@ni\szTip,tip,128)
    ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni)
  EndIf
  
  PokeS(@ni\szTip,tip,64)
  ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni)
  
EndProcedure
ProcedureDLL.l ni_Focus(uID.l, hWnd)
  

  Protected ni.NOTIFYICONDATA_2K
  
  If ni_0500()
    
    ni\cbSize = #NOTIFYICONDATA_V2_SIZE
    ni\hwnd   = hWnd
    ni\uID    = uID
    
    ProcedureReturn Shell_NotifyIcon_(#NIM_SETFOCUS,@ni) 
    
  EndIf
  
EndProcedure
ProcedureDLL.l ni_Show(uID.l, hWnd)
  
  Protected ni.NOTIFYICONDATA_2K
  
  If ni_0500()
    
    ni\cbSize = #NOTIFYICONDATA_V2_SIZE
    ni\hwnd   = hWnd
    ni\uID    = uID
    ni\uFlags = #NIF_STATE
    
    ni\dwState     = #Null
    ni\dwStateMask = #NIS_HIDDEN
    
    ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
    
  EndIf
  
EndProcedure
ProcedureDLL.l ni_Hide(uID.l, hWnd)
  

  Protected ni.NOTIFYICONDATA_2K
  
  If ni_0500()
    
    ni\cbSize = #NOTIFYICONDATA_V2_SIZE
    ni\hwnd   = hWnd
    ni\uID    = uID
    ni\uFlags = #NIF_STATE
    
    ni\dwState     = #NIS_HIDDEN
    ni\dwStateMask = #NIS_HIDDEN
    
    ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@ni) 
    
  EndIf
  
EndProcedure

ProcedureDLL.l ni_Info(uID.l, hWnd, title.s, info.s, Flags.l) 
  

  
  If ni_0600()
    ProcedureReturn ni_InfoXP(uID,hWnd,title,info,Flags)
  EndIf
  
  If ni_0500()
    ProcedureReturn ni_Info2K(uID,hWnd,title,info)
  EndIf
  
  ProcedureReturn ni_Info95(uID,hWnd,info)
  
EndProcedure





;-
;-Example Code 
;-

Define hWnd = OpenWindow(#PB_Any, 0, 0, 300, 300, "systray Test", #PB_Window_SystemMenu | #PB_Window_ScreenCentered )
Define uID = 99001

ButtonGadget(0, 10, 10, 200, 40, "Test")


Repeat 
	Select WaitWindowEvent()
		Case #PB_Event_CloseWindow
			End 
		Case #PB_Event_Gadget
			Debug ni_add(uID, hWnd, "Tip", ni_IconQuestion())
			Debug ni_info(uID, hWnd, "Hello", "Bla Blub", #NIF_INFO)
		EndSelect 	
ForEver 

DataSection
	DefaultNotifyIcon: 
	;IncludeBinary "myIcon.ico" ;use ni_DefaultIcon() to get a handle to this icon
EndDataSection
Post Reply