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 gman
(Posted 22 years ago)
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