Code archives/User Libs/ggTray system tray DLL

This code has been declared by its author to be Public Domain code.

Download source code

ggTray system tray DLL by gman2004
a ZIP download for the DLL, decls, and example code is here.

this is a DLL that puts an icon in they system tray and catches some mouse events performed over it. it is up to the application to "peek" for any generated events each time through a loop instead of responding to a generated event when one happens. this allows your application to keep chugging instead of waiting for an event. for a GUI app, WaitEvent will need a timeout. also, it does not do anything with popup menus. for that i would recommend Advance PopupMenu and Advance Popup Menu extras. there are 2 examples, one for B+ and one for B3D. ggTray.dll is provided for free... use it at your own risk.

the ggTray.decls file:
;Declarations file for ggTray.dll
;
; an individual event is in the following format:
;	EVENT_TYPE|MOUSEX|MOUSEY
;
; a list of events is a series of the individual event format seperated by newlines
;
; EVENT_TYPE can be the following:
;	1 - left click
;	2 - left double click
;	3 - right click
;	4 - right double click
;	5 - middle click
;	6 - middle double click
;
;

.lib "ggTray.dll"

; attaches the passed window handle to the tray icon and initializes the icon info
ggTrayCreate%(hWnd%):"_ggTrayCreate@4"

; shows the icon in the task tray
ggTrayShowIcon%():"_ggTrayShowIcon@0"

; hides the icon in the task tray
ggTrayHideIcon%():"_ggTrayHideIcon@0"

; sets the tooltip for the icon
ggTraySetToolTip%(cToolTip$):"_ggTraySetToolTip@4"

; gets the tooltip of the icon
ggTrayGetToolTip$():"_ggTrayGetToolTip@0"

; return 1 if visible, 0 if not
ggTrayIsVisible%():"_ggTrayIsvisible@0"

; sets the icon used based on the file passed.  1 if successful, 0 if not.
ggTraySetIconFromFile%(cIcoFile$):"_ggTraySetIconFromFile@4"

; sets the icon used based on an icon handle.  1 if successful, 0 if not.
ggTraySetIconFromHandle%(hIcon%):"_ggTraySetIconFromHandle@4"

; destroys everything setup with ggTrayCreate and removes the icon
ggTrayDestroy%():"_ggTrayDestroy@0"

; clears all events from the queue
ggTrayClearEvents():"_ggTrayClearEvents@0"

; clears the passed event from the queue (one-based)
ggTrayClearEvent(nEvent%):"_ggTrayClearEvent@4"

; returns a CRLF delimited list of events and clears the queue
ggTrayReadEvents$():"_ggTrayReadEvents@0"

; returns the passed event and removes it from the queue
ggTrayReadEvent$(nEvent%):"_ggTrayReadEvent@4"

; returns a CRLF delimited list of events but does not clear the queue
ggTrayPeekEvents$():"_ggTrayPeekEvents@0"

; returns the passed event but does not remove it from the queue
ggTrayPeekEvent$(nEvent%):"_ggTrayPeekEvent@4"

; returns the event # of the first left click encountered
ggTrayPeekLeftClick%():"_ggTrayPeekLeftClick@0"

; returns the event # of the first left double click encountered
ggTrayPeekLeftDblClick%():"_ggTrayPeekLeftDblClick@0"

; returns the event # of the first right click encountered
ggTrayPeekRightClick%():"_ggTrayPeekRightClick@0"

; returns the event # of the first right double click encountered
ggTrayPeekRightDblClick%():"_ggTrayPeekRightDblClick@0"

; returns the mouse X of the event passed
ggTrayEventMouseX%(nEvent%):"_ggTrayEventMouseX@4"

; returns the mouse Y of the event passed
ggTrayEventMouseY%(nEvent%):"_ggTrayEventMouseY@4"
; !*! this demo is for BlitzPlus only.  please use trayexamp_b3d.bb for Blitz3D

; TODO: you will need to place the ggTray.dll and ggTray.decls files in a folder called userlibs under your B+ directory
; TODO: ggTray.dll will need to be in the same directory that your EXE resides in if you compile
;

; TODO: either compile and run the EXE or change cAppDir$ to the hard location of the ICOs.  if you choose to compile, be
; sure to put the ggTray.dll in the same directory as your EXE
;Local cAppDir$=SystemProperty("appdir")
Local cAppDir$="c:\develop\trayexamp\"

Global cIconStop$=cAppDir$+"stop.ico"
Global cIconStart$=cAppDir$+"usergrp.ico"

; create a window that never shows... 
Global trayWnd=CreateWindow("Tray Example",-100,-100,1,17)
HideGadget trayWnd

If FileType(cIconStop$)<>1
	Notify("you must set the icon path",True)
Else
	
	; show the initial icon
	ggTrayCreate(QueryObject(trayWnd,1))
	
	; set the icon
	ggTraySetIconFromFile(cIconStop$)
	
	; set the tooltip
	ggTraySetToolTip("Tray Example Stopped")
	
	; show the icon with the updated text
	ggTrayShowIcon()
	
	; main loop to handle events 
	Repeat 
		WaitEvent(100)
	
		; check for a right click
		If ggTrayPeekRightClick()>0
			; check the tooltip to see what status we are currently at
			If Instr(ggTrayGetToolTip(),"Stopped")>0
				; set the icon and a new tip
				ggTraySetIconFromFile(cIconStart$)
				ggTraySetToolTip("Tray Example Started")
			Else
				; set the icon and a new tip
				ggTraySetIconFromFile(cIconStop$)
				ggTraySetToolTip("Tray Example Stopped")
			EndIf
			
			; TODO: show your menu here at the event mousex,mousey
			Notify("click occurred at: "+ggTrayEventMouseX(ggTrayPeekRightClick())+","+ggTrayEventMouseY(ggTrayPeekRightClick()))

			; clear out the events
			ggTrayClearEvents()
		EndIf
	
		; check for a left doubleclick
		If  ggTrayPeekLeftDblClick()>0
			Exit
		EndIf
	
	Forever
	
	; clean up the tray
	ggTrayDestroy()	
EndIf

; free the invisible tray window
FreeGadget trayWnd

Comments

Regular K2004
where can i find the dll?


gman2004
there is a link in the original post on the line:

"a ZIP download for the DLL, decls,..."

click on the word "here" for the download.


Jay Mattis2004
The link seems to be down. Does anybody have a copy of this library they could email me? My email address is jay(at)jaymattis.com. Thanks!


gman2004
sent... link should be up. think my web server was having some issues last nite. i had reports from a couple of other websites as well.


Jay Mattis2004
Thanks for the email!


Bad-Rat2004
what is a QueryObject??
When I start the bb,then direkt stop it because of an error
"Function QueryObject not Found"

Can somebody help me??


gman2004
the example was written for blitzplus and queryobject is a function that will return a platform handle to a window. my guess is that you are trying to run it in Blitz3d. i dont have blitz3d so i didnt do an example for it or know if it will work with it :( maybe someone out there has tried it in blitz3d?


Bad-Rat2004
ok.thx gman^^
thenI must look,how does it work!


gman2004
some searching found this bit of code from Peter Scheutz. i will see if i can install the demo of blitz3d and get a blitz3d sample going in the morning.


gman2004
here is the example (now included in the ZIP file) for B3D. please note that it does make use of the FindWindowUltimate() function by Peter Scheutz. it can be found here


; !*! this demo is for Blitz3D only.  please use trayexamp.bb for BlitzPlus

; TODO: you will need to place the ggTray.dll and ggTray.decls files in a folder called userlibs under your B3D directory
; TODO: ggTray.dll will need to be in the same directory that your EXE resides in if you compile
; TODO: you need to include the FindWindowUltimate() function or something similar.  it requires some entries in user32.decls and 
; is located at http://www.blitzbasic.com/Community/posts.php?topic=18287
;

; TODO: either compile and run the EXE or change cAppDir$ to the hard location of the ICOs.  if you choose to compile, be
; sure to put the ggTray.dll in the same directory as your EXE
;Local cAppDir$=SystemProperty("appdir")
Local cAppDir$="c:\develop\trayexamp\"

Global cIconStop$=cAppDir$+"stop.ico"
Global cIconStart$=cAppDir$+"usergrp.ico"

; set the graphics
Graphics 400,100,16,2

If FileType(cIconStop$)<>1
	Cls
	Text 110,10,"you must set the icon path",True
Else
	
	; TODO: you will need to include the FindWindowUltimate() function and its requirements 
	; or something similar To get the main window handle
	
	; show the initial icon
	ggTrayCreate(FindWindowUltimate())
	
	; set the icon
	ggTraySetIconFromFile(cIconStop$)
	
	; set the tooltip
	ggTraySetToolTip("Tray Example Stopped")
	
	; show the icon with the updated text
	ggTrayShowIcon()
	
	; main loop to handle events 
	Repeat 
	
		; check for a right click
		If ggTrayPeekRightClick()>0
			; check the tooltip to see what status we are currently at
			If Instr(ggTrayGetToolTip(),"Stopped")>0
				; set the icon and a new tip
				ggTraySetIconFromFile(cIconStart$)
				ggTraySetToolTip("Tray Example Started")
			Else
				; set the icon and a new tip
				ggTraySetIconFromFile(cIconStop$)
				ggTraySetToolTip("Tray Example Stopped")
			EndIf
			
			; TODO: show your menu here at the event mousex,mousey
			Cls
			Text 110,10,"click occurred at: "+ggTrayEventMouseX(ggTrayPeekRightClick())+","+ggTrayEventMouseY(ggTrayPeekRightClick()),True
			
			; clear out the events
			ggTrayClearEvents()
		EndIf
	
		; check for a left doubleclick
		If  ggTrayPeekLeftDblClick()>0
			Exit
		EndIf	
	Forever
	
	; clean up the tray
	ggTrayDestroy()	
EndIf




Bad-Rat2004
thx gman,now its work.
maybe you can include the FindWindowUltimate().bb in your zip file.

Nice work^^ cya


CASO2006
Wow your dll for the system tray icons actually works. I congradulate you.


gman2006
thx :) glad it could be of use.


Pineapple2006
Nice work gman... Really useful! :)

Dabz


Ked2007
I don't see the link anymore.


gman2007
sorry about that. i updated it last year to fix a memory problem and didnt update the link. it is still available:

http://www.gprogs.com/forum/viewtopic.php?id=30


Code Archives Forum