Size of .ico for a tray notification

Windows specific forum
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Size of .ico for a tray notification

Post by forumuser »

Hi,

I'm trying to use this:

Code: Select all

  ; For systray notifications
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
    Structure _NotifyIconData
      cbSize.l
      PB_Alignment1.b[4]
      hWnd.i
      uId.l
      uFlags.l
      uCallbackMessage.l
      PB_Alignment2.b[4]
      hIcon.i
      szTip.s{128}
      dwState.l
      dwStateMask.l
      szInfo.s{256}
      StructureUnion
        uTimeout.l
        uVersion.l
      EndStructureUnion
      szInfoTitle.s{64}
      dwInfoFlags.l
      guidItem.GUID
      hBalloonIcon.i
    EndStructure

  CompilerElseIf #PB_Compiler_Processor = #PB_Processor_x86
    Structure _NotifyIconData
      cbSize.l
      hwnd.i
      uId.l
      uFlags.l
      uCallbackMessage.l
      hIcon.i
      szTip.s{128}
      dwState.l
      dwStateMask.l
      szInfo.s{256}
      StructureUnion
        uTimeout.l
        uVersion.l
      EndStructureUnion
      szInfoTitle.s{64}
      dwInfoFlags.l
      guidItem.GUID
      hBalloonIcon.i
    EndStructure
  CompilerEndIf



; *************************************************************************************************

; This was taken from the !WinAPI library tool

; Possible flags, e.g.: #NIIF_ERROR, #NIIF_INFO, #NIIF_USER, #NIIF_WARNING
; For a user defined icon, #NIIF_USER and the belonging hIcon must be passed!
; timeOut in milliseconds
Procedure ShowTrayNotification(trayIconID, windowID, title.s, message.s, timeOut, flags, hIcon=0)
  Protected nId._NotifyIconData

  If OSVersion() >= #PB_OS_Windows_Vista
    nId\cbSize = SizeOf(_NotifyIconData)
  ElseIf OSVersion() >= #PB_OS_Windows_XP
    nId\cbSize = 504
  ElseIf OSVersion() >= #PB_OS_Windows_2000
    nId\cbSize = 488
  Else
    nId\cbSize = 88
  EndIf
  If nId\cbSize
    nId\uVersion       = 4
    Shell_NotifyIcon_(#NIM_SETVERSION, @nId)
    nId\uId            = trayIconID
    nId\hWnd           = windowID
    If OSVersion() >= #PB_OS_Windows_Vista
      nId\hBalloonIcon = hIcon
    Else
      nId\hIcon        = hIcon
    EndIf
    nId\dwInfoFlags    = flags
    nId\uFlags         = #NIF_INFO
    nId\uTimeout       = timeOut
    nId\szInfo         = message
    PokeS(@nId\szInfo, message)
    PokeS(@nId\szInfoTitle, title)
    ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY, @nId)
  EndIf

  ProcedureReturn #False
EndProcedure
and inside an If OpenWindow() ... EndIf:

Code: Select all

    If FileSize(iconFile) > 0
      If LoadImage(#IconID, iconFile)
        hIcon = ImageID(#IconID)
      EndIf
    EndIf
    ShowTrayNotification(#TrayIcons_Main, WindowID(#Win_Main), title, message, timeout, #NIIF_USER, hIcon)
This will display a tray notification, as long as the .ico file contains only a single icon with a 16x16 px size.
If the .ico file contains more than one icon (with different sizes): No tray notification gets displayed and the same is true if the .ico contains a (single) different sized icon (anything else than 16x16 px)...

Is there a way to get this working even if the .ico file contains more than one icon and for .ico files with
only one but a different size (e.g. by automatically rescaling them)?
Last edited by forumuser on Fri Aug 17, 2018 1:21 pm, edited 1 time in total.
fryquez
Enthusiast
Enthusiast
Posts: 367
Joined: Mon Dec 21, 2015 8:12 pm

Re: Size of .ico for a tray notification

Post by fryquez »

There is an working example for systray icons: #PB_Compiler_Home + "examples/sources/SysTray.pb"

Anyway, if you need to load a specific size of an icon use the LoadImage_() API.
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Size of .ico for a tray notification

Post by forumuser »

There is an working example for systray icons: #PB_Compiler_Home + "examples/sources/SysTray.pb"
I know but that isn't really related to tray icon notifications (only to tray icons and when the mouse is hovering over them)
Anyway, if you need to load a specific size of an icon use the LoadImage_() API.
Yeah, thanks! It is now as easy as this:

Code: Select all

hIcon = LoadImage_(0, imageFile, #IMAGE_ICON, 16, 16, #LR_LOADFROMFILE)
Post Reply