[bb] ggTray system tray DLL by gman [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

Title : ggTray system tray DLL
Author : gman
Posted : 1+ years ago

Description : a ZIP download for the DLL, decls, and example code is <a href="http://www.gprogs.com/ggTray/2005_05_13_ggTray.zip" target="_blank">here.</a>

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 <a href="codearcs6423.html?code=697" >Advance PopupMenu</a> and <a href="codearcs325c.html?code=1132" >Advance Popup Menu extras</a>.  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"


Code :
Code (blitzbasic) Select
; !*! 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 rayexamp"

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 K(Posted 1+ years ago)

 where can i find the dll?


gman(Posted 1+ years ago)

 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 Mattis(Posted 1+ years ago)

 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!


gman(Posted 1+ years ago)

 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 Mattis(Posted 1+ years ago)

 Thanks for the email!


Bad-Rat(Posted 1+ years ago)

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


gman(Posted 1+ years ago)

 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-Rat(Posted 1+ years ago)

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


gman(Posted 1+ years ago)

 some searching found <a href="../Community/posts585b-3.html?topic=18287" target="_blank">this</a> 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.


gman(Posted 1+ years ago)

 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 <a href="../Community/posts585b-3.html?topic=18287" target="_blank">here</a>

; !*! 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 <a href="../Community/posts585b-3.html?topic=18287" target="_blank">http://www.blitzbasic.com/Community/posts.php?topic=18287</a>
;

; 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 rayexamp"

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-Rat(Posted 1+ years ago)

 thx gman,now its work.maybe you can include the FindWindowUltimate().bb in your zip file.Nice work^^  cya


CASO(Posted 1+ years ago)

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


gman(Posted 1+ years ago)

 thx :)  glad it could be of use.


Pineapple(Posted 1+ years ago)

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


Ked(Posted 1+ years ago)

 I don't see the link anymore.


gman(Posted 1+ years ago)

 sorry about that.  i updated it last year to fix a memory problem and didnt update the link.  it is still available:<a href="http://www.gprogs.com/forum/viewtopic.php?id=30" target="_blank">http://www.gprogs.com/forum/viewtopic.php?id=30</a> [/i]