send systray icon notification in W7

Just starting out? Need help? Post your questions and find answers here.
User avatar
wichtel
User
User
Posts: 71
Joined: Fri May 02, 2003 11:14 am
Location: Germany
Contact:

send systray icon notification in W7

Post 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?
PB 5.40 LTS, W7,8,10 64bit and Mint x64
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: send systray icon notification in W7

Post 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
Egypt my love
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: send systray icon notification in W7

Post 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
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: send systray icon notification in W7

Post 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

Egypt my love
rsts
Addict
Addict
Posts: 2736
Joined: Wed Aug 24, 2005 8:39 am
Location: Southwest OH - USA

Re: send systray icon notification in W7

Post 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
User avatar
wichtel
User
User
Posts: 71
Joined: Fri May 02, 2003 11:14 am
Location: Germany
Contact:

Re: send systray icon notification in W7

Post 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?
PB 5.40 LTS, W7,8,10 64bit and Mint x64
PureLust
Enthusiast
Enthusiast
Posts: 477
Joined: Mon Apr 16, 2007 3:57 am
Location: Germany, NRW

Re: send systray icon notification in W7

Post by PureLust »

Maybe THIS or THIS could be helpful to you.
[Dynamic-Dialogs] - create complex GUIs the easy way
[DeFlicker] - easily deflicker your resizeable Windows
[WinFX] - Window Effects (incl. 'click-through' Window)
User avatar
wichtel
User
User
Posts: 71
Joined: Fri May 02, 2003 11:14 am
Location: Germany
Contact:

Re: send systray icon notification in W7

Post 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.
PB 5.40 LTS, W7,8,10 64bit and Mint x64
RASHAD
PureBasic Expert
PureBasic Expert
Posts: 4946
Joined: Sun Apr 12, 2009 6:27 am

Re: send systray icon notification in W7

Post 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
Egypt my love
User avatar
wichtel
User
User
Posts: 71
Joined: Fri May 02, 2003 11:14 am
Location: Germany
Contact:

Re: send systray icon notification in W7

Post 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.
PB 5.40 LTS, W7,8,10 64bit and Mint x64
User avatar
aaaaaaaargh
User
User
Posts: 55
Joined: Thu Jul 27, 2006 1:24 pm

Re: send systray icon notification in W7

Post by aaaaaaaargh »

Hi,
has anybody managed to solve the Windows 7 systray / notification area issue?

Cheers
MachineCode
Addict
Addict
Posts: 1482
Joined: Tue Feb 22, 2011 1:16 pm

Re: send systray icon notification in W7

Post 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?
Microsoft Visual Basic only lasted 7 short years: 1991 to 1998.
PureBasic: Born in 1998 and still going strong to this very day!
User avatar
wichtel
User
User
Posts: 71
Joined: Fri May 02, 2003 11:14 am
Location: Germany
Contact:

Re: send systray icon notification in W7

Post 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?
PB 5.40 LTS, W7,8,10 64bit and Mint x64
User avatar
aaaaaaaargh
User
User
Posts: 55
Joined: Thu Jul 27, 2006 1:24 pm

Re: send systray icon notification in W7

Post 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...
User avatar
em_uk
Enthusiast
Enthusiast
Posts: 366
Joined: Sun Aug 08, 2010 3:32 pm
Location: Manchester UK

Re: send systray icon notification in W7

Post 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
----

R Tape loading error, 0:1
Post Reply