Systray balloon message problems with 64 bit windows

Just starting out? Need help? Post your questions and find answers here.
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Systray balloon message problems with 64 bit windows

Post by Michael Vogel »

The following code shows a nice popup message in Windows 8 when using the 32 bit version of PB 5.46, but fails when compiled with 64 bit version. I fear there's something with integer and long types but haven't founf the error so far...

Code: Select all

; Define Icons

	#Icons=10

	Structure NOTIFYICONDATA_
		cbSize.l
		hwnd.i
		uId.l
		uFlags.l
		uCallbackMessage.l
		hIcon.i
		StructureUnion
			szTip.s{64}
			szTipEx.s{128}
		EndStructureUnion
		dwState.l
		dwStateMask.l
		szInfo.s{256}
		StructureUnion
			uTimeout.l
			uVersion.l
		EndStructureUnion
		szInfoTitle.s{64}
		dwInfoFlags.l
		guidItem.GUID
		hBalloonIcon.i
	EndStructure

	Global MyHandle
	Global SysTrayInfo.NOTIFYICONDATA_ ;	Handle für Balloon-Tooltip über dem SysTray-Icon

	Prototype.l ProtoAccessibleObjectFromPoint(x.l,y.l,*ia,*var)
	Global AccessibleObjectFromPoint.ProtoAccessibleObjectFromPoint

	Global Dim Icon(#Icons)

	For i=0 To #Icons
		Icon(i)=CreateImage(i,24,24,24,#Black)
		StartDrawing(ImageOutput(i))
		Box(1,1,22,i*2,$c0c0c0)
		Box(1,1+i*2,22,22-i*2,#Blue)
		StopDrawing()
	Next i

	#SysTray=0


	Global Icon_File.s=ProgramFilename()
	Global Icon_Lib.i
	Global Icon_Count.i
	Global *Icon_Group.GRPIconDIR
	Global *Icon_Image.IconIMAGE


; EndDefine

Procedure SystrayBalloon_(Title.s,Message.s,Flags)

	#NIIF_LARGE_ICON=			$20
	#NIIF_RESPECT_QUIET_TIME=	$80

	#TenSeconds=10000; kürzer gehts nicht

	If OSVersion() >=#PB_OS_Windows_Vista
		SysTrayInfo\cbSize=SizeOf(NOTIFYICONDATA_)
	ElseIf OSVersion() >=#PB_OS_Windows_XP
		SysTrayInfo\cbSize=OffsetOf(NOTIFYICONDATA_\hBalloonIcon)
	ElseIf OSVersion() >=#PB_OS_Windows_2000
		SysTrayInfo\cbSize=OffsetOf(NOTIFYICONDATA_\guidItem)
	Else
		SysTrayInfo\cbSize=OffsetOf(NOTIFYICONDATA_\szTip) + SizeOf(NOTIFYICONDATA_\szTip)
	EndIf

	If SysTrayInfo\cbSize
		SysTrayInfo\uVersion=#NOTIFYICON_VERSION
		SysTrayInfo\uCallbackMessage=#WM_NOTIFYICON
		SysTrayInfo\uId=#Null; SysTray
		SysTrayInfo\uFlags=#NIF_INFO|#NIF_TIP;|#TTS_NOPREFIX
		SysTrayInfo\uTimeout=#TenSeconds

		;Shell_NotifyIcon_(#NIM_SETVERSION,@SysTrayInfo)

		SysTrayInfo\hwnd=MyHandle
		SysTrayInfo\dwInfoFlags=Flags
		SysTrayInfo\dwState=#NIS_SHAREDICON
		SysTrayInfo\szInfoTitle=Left(Title,63)
		SysTrayInfo\szInfo=Left(Message,255)
		If Message
			Protected ToolTip.s=StringField(Message,CountString(Message,#CR$)+1,#CR$)
		EndIf
		SysTrayInfo\szTip=ToolTip.s
		ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY,@SysTrayInfo)
	EndIf

	ProcedureReturn #False

EndProcedure
Procedure ChangeIcon(n)
	If IconActive<>n
		IconActive=n
		ChangeSysTrayIcon(#SysTray,Icon(n))
	EndIf
EndProcedure

MyHandle=OpenWindow(0,0,0,0,0,"",#PB_Window_ScreenCentered|#PB_Window_SystemMenu|#PB_Window_Invisible)
AddWindowTimer(0,666,200)

AddSysTrayIcon(#SysTray,MyHandle,Icon(1))
SystrayBalloon_("'Hey'","Just click on the tray icon to quit...",#NIIF_USER|#NIIF_NOSOUND|#NIIF_LARGE_ICON|#NIIF_RESPECT_QUIET_TIME)

Repeat
	Select WaitWindowEvent(10)
			
		Case #PB_Event_SysTray;   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Mausklick im Systray ~~~~~~
		Select EventType()
		Case #PB_EventType_LeftClick
			End
		EndSelect

	Case #PB_Event_Timer
		If EventTimer()=666
			ChangeIcon(Random(#Icons))
		EndIf
		
	EndSelect
Until quit
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Systray balloon message problems with 64 bit windows

Post by forumuser »

The 64-bit structure needs alignments...

Code: Select all

    Structure NOTIFYICONDATA_
      cbSize.l
      CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
        PB_Alignment1.b[4]
      CompilerEndIf
      hWnd.i
      uId.l
      uFlags.l
      uCallbackMessage.l
      CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
        PB_Alignment2.b[4]
      CompilerEndIf
      hIcon.i
      StructureUnion
        szTip.s{64}
        szTipEx.s{128}
      EndStructureUnion
      dwState.l
      dwStateMark.l
      szInfo.s{256}
      StructureUnion
        uTimeout.l
        uVersion.l
      EndStructureUnion
      szInfoTitle.s{64}
      dwInfoFlags.l
      guidItem.GUID
      hBalloonIcon.i
    EndStructure
User avatar
Michael Vogel
Addict
Addict
Posts: 2666
Joined: Thu Feb 09, 2006 11:27 pm
Contact:

Re: Systray balloon message problems with 64 bit windows

Post by Michael Vogel »

Brilliant - thanks!
User avatar
Josh
Addict
Addict
Posts: 1183
Joined: Sat Feb 13, 2010 3:45 pm

Re: Systray balloon message problems with 64 bit windows

Post by Josh »

forumuser wrote:The 64-bit structure needs alignments...

Code: Select all

    Structure NOTIFYICONDATA_
      cbSize.l
      CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
        PB_Alignment1.b[4]
      CompilerEndIf
      hWnd.i
      uId.l
      uFlags.l
      uCallbackMessage.l
      CompilerIf #PB_Compiler_Processor = #PB_Processor_x64
        PB_Alignment2.b[4]
      CompilerEndIf
      hIcon.i
      StructureUnion
        szTip.s{64}
        szTipEx.s{128}
      EndStructureUnion
      dwState.l
      dwStateMark.l
      szInfo.s{256}
      StructureUnion
        uTimeout.l
        uVersion.l
      EndStructureUnion
      szInfoTitle.s{64}
      dwInfoFlags.l
      guidItem.GUID
      hBalloonIcon.i
    EndStructure
And Why not use #Pb_Structure_AlignC? :wink:

Code: Select all

   Structure NOTIFYICONDATA_ Align #PB_Structure_AlignC
      cbSize.l
      hwnd.i
      uId.l
      uFlags.l
      uCallbackMessage.l
      hIcon.i
      StructureUnion
         szTip.s{64}
         szTipEx.s{128}
      EndStructureUnion
      dwState.l
      dwStateMask.l
      szInfo.s{256}
      StructureUnion
         uTimeout.l
         uVersion.l
      EndStructureUnion
      szInfoTitle.s{64}
      dwInfoFlags.l
      guidItem.GUID
      hBalloonIcon.i
   EndStructure
sorry for my bad english
forumuser
User
User
Posts: 98
Joined: Wed Apr 18, 2018 8:24 am

Re: Systray balloon message problems with 64 bit windows

Post by forumuser »

And Why not use #Pb_Structure_AlignC?
I'd say: Even better :mrgreen:
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Systray balloon message problems with 64 bit windows

Post by BarryG »

I just worked out that you CAN'T use a constant for the systrayicon flag...? Check this out, which fails. A bug?

Also, calling this procedure in my production app does nothing (the Debug Output is 0 for failure). I can't work out why, when the procedure in this standalone snippet obviously works fine if you don't use a constant.

Code: Select all

Procedure ShowNotification(title$,text$,win=0,icon=0)
  Structure MyNotifyIconData
    cbSize.l
    CompilerIf #PB_Compiler_Processor=#PB_Processor_x64
      PB_Alignment1.b[4]
    CompilerEndIf
    hWnd.i
    uID.l
    uFlags.l
    uCallbackMessage.l
    CompilerIf #PB_Compiler_Processor=#PB_Processor_x64
      PB_Alignment2.b[4]
    CompilerEndIf
    hIcon.i
    StructureUnion
      szTip.s{64}
      szTipEx.s{128}
    EndStructureUnion
    dwState.l
    dwStateMark.l
    szInfo.s{256}
    StructureUnion
      uTimeout.l
      uVersion.l
    EndStructureUnion
    szInfoTitle.s{64}
    dwInfoFlags.l
    guidItem.GUID
    hBalloonIcon.i
  EndStructure
  balloon.MyNotifyIconData\hWnd=WindowID(win)
  balloon\uID=icon
  balloon\uFlags=#NIF_INFO
  balloon\dwState=#NIS_SHAREDICON
  balloon\szInfoTitle=title$
  balloon\szInfo=text$
  balloon\uTimeout=5000
  balloon\dwInfoFlags=#NIIF_NOSOUND
  balloon\cbSize=SizeOf(MyNotifyIconData)
  Debug Shell_NotifyIcon_(#NIM_MODIFY,balloon)
EndProcedure

OpenWindow(0,200,200,200,70,"test",#PB_Window_SystemMenu)
CreateImage(0,16,16,24,#Red)
#one=1
AddSysTrayIcon(#one,WindowID(0),ImageID(0)) ; Using a constant makes it fail!
ButtonGadget(0,20,20,150,25,"Show notification")

Repeat
  ev=WaitWindowEvent()
  If ev=#PB_Event_Gadget
    ShowNotification("Title","Message goes here")
  EndIf
Until ev=#PB_Event_CloseWindow
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: Systray balloon message problems with 64 bit windows

Post by mk-soft »

I found this from Rashad ...
Link: viewtopic.php?p=374614#p374614

Update AlignC

Code: Select all

Structure MY_NOTIFYICONDATA Align #PB_Structure_AlignC
  cbSize.l
  hWnd.i
  uID.l
  uFlags.l
  uCallbackMessage.l
  hIcon.i
  szTip.s{128}
  dwState.l
  dwStateMark.l
  szInfo.s{256}
  StructureUnion
    uTimeout.l
    uVersion.l
  EndStructureUnion
  szInfoTitle.s{64}
  dwInfoFlags.l
EndStructure

#WINDOW = 0
Enumeration
  #BUTTON_SHOW
  #BUTTON_HIDE
  #SYSTRAYICON
EndEnumeration

Procedure MyCallback(WindowID, Message, wParam, lParam)
  If WindowID = WindowID(0)   
    If Message = #WM_NOTIFYICON ; Does that make sense?
      If wParam = #SYSTRAYICON
        Select lParam
          Case #NIN_BALLOONTIMEOUT
            Debug "Balloon timed out or was closed by the user"
            
          Case #NIN_BALLOONUSERCLICK
            Debug "Balloon got clicked by the user"
            
          Case #NIN_BALLOONHIDE
            Debug "Balloon got hidden"
            
          Case #WM_LBUTTONUP
            MessageRequester("Message", "Systrayicon got clicked.")
        EndSelect
        
      EndIf
    EndIf   
  EndIf              
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure


OpenWindow(#WINDOW, 0, 0, 200, 75, "Icontest", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(#BUTTON_SHOW, 5, 5, 190, 30, "Show balloon message")
ButtonGadget(#BUTTON_HIDE, 5, 40, 190, 30, "Hide balloon message")


; You might wanna specify a path which corresponds to any valid .ico file on your system.
LoadImage(0, #PB_Compiler_Home + "\Examples\Sources - Advanced\Waponez II\Waponez.ico")

AddSysTrayIcon(#SYSTRAYICON, WindowID(0), ImageID(0))
SysTrayIconToolTip(#SYSTRAYICON, "Naah, I ain't no systray icon, I'm just cleanin' down 'ere.")

SetWindowCallback(@MyCallback(), 0)

NIData.MY_NOTIFYICONDATA
NIData\cbSize = SizeOf(MY_NOTIFYICONDATA)
NIData\hWnd = WindowID(0)
NIData\uID = #SYSTRAYICON
NIData\uFlags = #NIF_INFO | #NIF_MESSAGE
NIData\uCallbackMessage = #WM_NOTIFYICON
NIData\uTimeout = 2
NIData\uVersion = #NOTIFYICON_VERSION
NIData\szInfoTitle = "Hey there!"
NIData\dwInfoFlags = #NIIF_INFO

Repeat
  
  event = WaitWindowEvent()
  
  If event = #PB_Event_Gadget
    Select EventGadget()
      Case #BUTTON_SHOW:
        NIData\szInfo = "I'm just a small speech bubble."
        Shell_NotifyIcon_(#NIM_MODIFY, NIData)
      Case #BUTTON_HIDE:
        NIData\szInfo = ""
        Shell_NotifyIcon_(#NIM_MODIFY, NIData)
    EndSelect
  EndIf
  
  If event = #PB_Event_SysTray
    If EventGadget() = #SYSTRAYICON
      MessageRequester("Message", "Systrayicon got clicked.")
    EndIf
  EndIf
  
Until event = #PB_Event_CloseWindow

My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Systray balloon message problems with 64 bit windows

Post by BarryG »

None of these toast/app notification examples work with 6.10 anymore. :(

Does anyone know how to update them? Otherwise I have to go back to 6.04 again.
breeze4me
Enthusiast
Enthusiast
Posts: 511
Joined: Thu Mar 09, 2006 9:24 am
Location: S. Kor

Re: Systray balloon message problems with 64 bit windows

Post by breeze4me »

BarryG wrote: Sun Mar 03, 2024 2:29 am None of these toast/app notification examples work with 6.10 anymore. :(

Does anyone know how to update them? Otherwise I have to go back to 6.04 again.
It seems to work when the order in which the icons are added is used, not the user-defined icon number.
Tested with 6.10 b7 x64.

Code: Select all

Structure MY_NOTIFYICONDATA Align #PB_Structure_AlignC
  cbSize.l
  hWnd.i
  uID.l
  uFlags.l
  uCallbackMessage.l
  hIcon.i
  szTip.s{128}
  dwState.l
  dwStateMark.l
  szInfo.s{256}
  StructureUnion
    uTimeout.l
    uVersion.l
  EndStructureUnion
  szInfoTitle.s{64}
  dwInfoFlags.l
EndStructure

#WINDOW = 0
Enumeration
  #BUTTON_SHOW
  #BUTTON_HIDE
  #SYSTRAYICON
EndEnumeration



; Order in which icons are added.
#SysTrayIconCreatedOrder1 = 1



Procedure MyCallback(WindowID, Message, wParam, lParam)
  If WindowID = WindowID(0)   
    If Message = #WM_NOTIFYICON ; Does that make sense?
      If wParam = #SysTrayIconCreatedOrder1             ; <-- here
        Select lParam
          Case #NIN_BALLOONTIMEOUT
            Debug "Balloon timed out or was closed by the user"
            
          Case #NIN_BALLOONUSERCLICK
            Debug "Balloon got clicked by the user"
            
          Case #NIN_BALLOONHIDE
            Debug "Balloon got hidden"
            
          Case #WM_LBUTTONUP
            MessageRequester("Message", "Systrayicon got clicked.")
        EndSelect
        
      EndIf
    EndIf   
  EndIf              
  ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure


OpenWindow(#WINDOW, 0, 0, 200, 75, "Icontest", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
ButtonGadget(#BUTTON_SHOW, 5, 5, 190, 30, "Show balloon message")
ButtonGadget(#BUTTON_HIDE, 5, 40, 190, 30, "Hide balloon message")


; You might wanna specify a path which corresponds to any valid .ico file on your system.
LoadImage(0, #PB_Compiler_Home + "\Examples\Sources - Advanced\Waponez II\Waponez.ico")

AddSysTrayIcon(#SYSTRAYICON, WindowID(0), ImageID(0))
SysTrayIconToolTip(#SYSTRAYICON, "Naah, I ain't no systray icon, I'm just cleanin' down 'ere.")

SetWindowCallback(@MyCallback(), 0)

NIData.MY_NOTIFYICONDATA
NIData\cbSize = SizeOf(MY_NOTIFYICONDATA)
NIData\hWnd = WindowID(0)
NIData\uID = #SysTrayIconCreatedOrder1             ; <-- here
NIData\uFlags = #NIF_INFO | #NIF_MESSAGE
NIData\uCallbackMessage = #WM_NOTIFYICON
NIData\uTimeout = 2
NIData\uVersion = #NOTIFYICON_VERSION
NIData\szInfoTitle = "Hey there!"
NIData\dwInfoFlags = #NIIF_INFO

Repeat
  
  event = WaitWindowEvent()
  
  If event = #PB_Event_Gadget
    Select EventGadget()
      Case #BUTTON_SHOW:
        NIData\szInfo = "I'm just a small speech bubble."
        Shell_NotifyIcon_(#NIM_MODIFY, NIData)
      Case #BUTTON_HIDE:
        NIData\szInfo = ""
        Shell_NotifyIcon_(#NIM_MODIFY, NIData)
    EndSelect
  EndIf
  
  If event = #PB_Event_SysTray
    If EventGadget() = #SYSTRAYICON
      MessageRequester("Message", "Systrayicon got clicked.")
    EndIf
  EndIf
  
Until event = #PB_Event_CloseWindow
BarryG
Addict
Addict
Posts: 3292
Joined: Thu Apr 18, 2019 8:17 am

Re: Systray balloon message problems with 64 bit windows

Post by BarryG »

Thank you, breeze4me! You saved my life. It works again with 6.10 here as well. :D
Post Reply