Page 1 of 2

send systray icon notification in W7

Posted: Tue Nov 23, 2010 9:21 am
by wichtel
Hello,
W7 hides away inactive icons in the notification area. I know that I can change that setting, but actually I like it.
I would like to know how I can "send" a notification to a systray icon of a PB program so that it appears again when hidden.

I tried to use ChangeSysTrayIcon() but that does not help.

I guess I'd need some new W7 API call to do that. I have searched but found nothing so far.

Any ideas?

Re: send systray icon notification in W7

Posted: Tue Nov 23, 2010 5:24 pm
by RASHAD
Hide or Show PB program systemtray icon in win 7
Tested PB x86,x64 Win 7 x64

Code: Select all

  hnd = FindWindow_("Shell_TrayWnd", #Null)
  hnd = FindWindowEx_(hnd, #Null, "TrayNotifyWnd", #Null)
  hnd = FindWindowEx_(hnd,#Null, "SysPager", #Null)
  hnd = FindWindowEx_(hnd, #Null, "ToolbarWindow32", #Null)
If OpenWindow(0, 100, 150, 300, 100, "PureBasic - SysTray Example", #PB_Window_SystemMenu) 

  AddSysTrayIcon(1, WindowID(0), LoadImage(0,"CdPlayer.ico"))
  SysTrayIconToolTip(1, "Icon 1")
  Delay(2000)  
  SendMessage_(hnd, #TB_HIDEBUTTON,1, 1)                 ;Hide
  Delay(2000)
  SendMessage_(hnd, #TB_HIDEBUTTON,1, 0)                 ;Show
  Repeat
    Event = WaitWindowEvent()
    
  Until Event = #PB_Event_CloseWindow
  
EndIf

Re: send systray icon notification in W7

Posted: Tue Nov 23, 2010 6:45 pm
by rsts
Hi Mr Rashad.

On my windows 7 64 bit system running PB 32bit compiler, the hide and show effect my "network" icon, which is always showing in the notification area and does not effect the actual program icon.

cheers

Re: send systray icon notification in W7

Posted: Tue Nov 23, 2010 6:54 pm
by RASHAD
Sorry rsts
Try it this way and please tell me the result

Code: Select all

  hnd = FindWindow_("Shell_TrayWnd", #Null)
  hnd = FindWindowEx_(hnd, #Null, "TrayNotifyWnd", #Null)
  hnd = FindWindowEx_(hnd,#Null, "SysPager", #Null)
  hnd = FindWindowEx_(hnd, #Null, "ToolbarWindow32", #Null)
If OpenWindow(0, 100, 150, 300, 100, "PureBasic - SysTray Example", #PB_Window_SystemMenu) 

 index = SendMessage_(hnd, #TB_BUTTONCOUNT,0, 0)  
  AddSysTrayIcon(0, WindowID(0), LoadImage(0,"CdPlayer.ico"))
  SysTrayIconToolTip(0, "Icon 1")
  Delay(2000)  
  SendMessage_(hnd, #TB_HIDEBUTTON,index, 1)                 ;Hide
  Delay(2000)
  SendMessage_(hnd, #TB_HIDEBUTTON,index, 0)                 ;Show
  Repeat
    Event = WaitWindowEvent()
    
  Until Event = #PB_Event_CloseWindow
  
EndIf


Re: send systray icon notification in W7

Posted: Tue Nov 23, 2010 8:02 pm
by rsts
Nothing.

Since the icon immediately goes to the overflow area, the commands appear to have no effect.

It works if you change the default windows notification from "only show notifications" to "show icon and notifications", but I doubt most average folks are aware of that capability.

The icon overflow area seems to cause all kinds of problems. I was wanting to determine a list of programs in the notification area and have not been able to get an acceptable solution due to knowing of no good way to obtain information about those in the overflow area, which is most of them.

cheers

Re: send systray icon notification in W7

Posted: Tue Nov 23, 2010 8:14 pm
by wichtel
Thanks everybody.
Now we get to my problem :)

I want to send "something" to an icon so it gets out of the overflow area and gets visible again.
The setting is "show only notification".
And some Windows programs can do that.
Their icon remains "unseen" in the overflow area and only shows up when something happens that needs user attention.
How is that done?

Re: send systray icon notification in W7

Posted: Tue Nov 23, 2010 8:19 pm
by PureLust
Maybe THIS or THIS could be helpful to you.

Re: send systray icon notification in W7

Posted: Wed Nov 24, 2010 2:40 pm
by wichtel
Thanks.
It looks like there is no simple way to have a program that was designed for XP force the appearance of an icon that has been hidden.

I used the PB command to set the tray icon.
If I understand right, the only way to make a hidden icon visible is to send a too ballon tip with NIF_INFO.
The structure NOTIFYICONDATA is not completely defined, and if it would be empty...

So I would need to create my tray icons manually...
Mmh...looking into this.

Re: send systray icon notification in W7

Posted: Wed Nov 24, 2010 2:58 pm
by RASHAD
@wichtel Hi
With windows XP it is no problem
The big problem is with windows 7 (The guys in MS make it very difficult)
When you create a system tray icon with PB and then remove it
It stays in the imagelist in the notification area and make a lot of problems after that
I am in the middle of the road right now
I managed to remove the icon (and all the abused) from the imagelist and refresh the system without rebooting or logon\logoff (It works fine I just looked for how to do that long time ago)
Right now I am trying to figure out how to to change the status of the icon from 'only show notifications' to 'show icon and notifications' then we can manage the hide and show
I hope success soon
Be tuned

Re: send systray icon notification in W7

Posted: Wed Nov 24, 2010 3:44 pm
by wichtel
@RASHAD:
Thanks a lot.
I played with shell_notifyicon_ and got to the point where I had the same behavior like with the build in commands...
I was not able to unhide the icon.
Sorry, I need to focus on the real purpose of the program again, will look into the icon stuff later.

Re: send systray icon notification in W7

Posted: Tue Oct 25, 2011 6:55 am
by aaaaaaaargh
Hi,
has anybody managed to solve the Windows 7 systray / notification area issue?

Cheers

Re: send systray icon notification in W7

Posted: Tue Oct 25, 2011 8:56 am
by MachineCode
It's probably not possible. You've set Windows 7 to hide all icons, but then want to force it to be seen?

Re: send systray icon notification in W7

Posted: Tue Oct 25, 2011 10:12 am
by wichtel
My original question was a different one.

- I create a taskbar icon under W7
- it appears and then disappears after some time (default behavior)
- but then my program has something to "say" and I want the icon to reappear
- other applications are able to do that
- so how is this done in PB?

Re: send systray icon notification in W7

Posted: Tue Oct 25, 2011 5:46 pm
by aaaaaaaargh
MachineCode wrote:It's probably not possible. You've set Windows 7 to hide all icons, but then want to force it to be seen?
Well, if you set a program to "Only show notifications" there must be a way for that program to show the notification icon at some point, other proggies do it all the time...

Re: send systray icon notification in W7

Posted: Mon Oct 31, 2011 12:56 am
by em_uk
Why not send some notification text to your icon, Windows 7 then show the icon and we hide again once the notification has timed out.

Code: Select all


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

Enumeration
   #NOTIFYICONDATA_V1_SIZE = 88
   #NOTIFYICONDATA_V2_SIZE = 488
   #NOTIFYICONDATA_V3_SIZE = 504
   #NOTIFYICONDATA_V4_SIZE = 508
EndEnumeration


Procedure SysTrayIconBalloon_(uId, hWindow, Title$, Message$, timeOut, flags)
   Protected nId.NOTIFYICONDATA_
   If OSVersion() >= #PB_OS_Windows_Vista
      nId\cbSize = #NOTIFYICONDATA_V4_SIZE
   ElseIf OSVersion() >= #PB_OS_Windows_XP
      nId\cbSize = #NOTIFYICONDATA_V3_SIZE
   ElseIf OSVersion() >= #PB_OS_Windows_2000
      nId\cbSize = #NOTIFYICONDATA_V2_SIZE
   Else
      nId\cbSize = #NOTIFYICONDATA_V1_SIZE
   EndIf
   If nId\cbSize
      nId\uVersion    = 4
      Shell_NotifyIcon_(#NIM_SETVERSION, @nId)
      nId\uId         = uId
      nId\hwnd        = hWindow
      nId\dwInfoFlags = flags
      nId\uFlags      = #NIF_INFO
      nId\uTimeout    = timeOut
      PokeS(@nId\szInfo, Message$, SizeOf(nId\szInfo))
      PokeS(@nId\szInfoTitle, Title$, SizeOf(nId\szInfoTitle))
      ProcedureReturn Shell_NotifyIcon_(#NIM_MODIFY, @nId)
   EndIf
   ProcedureReturn #False
EndProcedure


If OpenWindow(0, 100, 150, 300, 100, "PureBasic - SysTray Example", #PB_Window_SystemMenu)

  AddSysTrayIcon(0, WindowID(0), LoadImage(0,"C:\Program Files (x86)\PureBasic\Examples\Sources\Data\CdPlayer.ico"))
 
  SysTrayIconBalloon_(0, WindowID(0),"Icon Appears!","When you add this notification, your tray icon will appear.",50,#NIIF_INFO)
  
  Repeat
    Event = WaitWindowEvent()
   
  Until Event = #PB_Event_CloseWindow
 
EndIf

You can also change the #NIIF_INFO and the end for different types of notifications eg : #NIIF_USER, #NIIF_WARNING, #NIIF_ERROR