WinBatch Tech Support Home

Database Search

If you can't find the information using the categories below, post a question over in our WinBatch Tech Support Forum.

TechHome

PopMenu

Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.

Create your own Popmenu like WinBatch script


Create your own Popmenu like script

This program reads tray.ini for making a menu in systray. We take PopupMenu fonction and main idea from TechnicalDatabase.

TRAY_INI.WBT

; date    : June 3 2003
; author  : Delgove jean-jacques
; purpose : Create a systray menu from an inifile
; version : 1.0
; this program reads tray.ini for making a menu in systray.
; we take PopupMenu fonction and main idea from TechnicalDatabase

;Magic.  Real Magic.  Don't ask.  Thanx to Guido for making it work the first time.
; vraiment magique. Merci Guido
;The PopupMenu UDF takes a | delimted list of menu items. and presents them to the user
#DefineFunction PopupMenu(choices)
   user32=StrCat(DirWindows(1),"User32.DLL")
   MF_STRING = 0
   TPM_RETURNCMD = 256
   TPM_LEFTBUTTON = 0
   hwnd=DllHwnd("")
   ;create menu
   hmenu = DllCall(user32,long:"CreatePopupMenu")
   choicecount=ItemCount(choices,"|")
   For xx=1 To choicecount
      thischoice=ItemExtract(xx,choices,"|")
      DllCall(user32,long:"AppendMenuA",long:hmenu, long:MF_STRING, long:xx, lpstr:thischoice)
   Next
   DllCall(user32,long:"SetForegroundWindow",long:hwnd)
   mc = MouseInfo(3)
   mcx=ItemExtract(1,mc," ")
   mcy=ItemExtract(2,mc," ")
   wFlags=TPM_RETURNCMD|TPM_LEFTBUTTON
   s=DllCall(user32,long:"TrackPopupMenu",long:hmenu, long:wFlags, long:mcx, long:mcy, long:0, long:hwnd, lpnull)
   ;Destroy Menu
   DllCall(user32,long:"DestroyMenu",long:hmenu)
   Return(s)
#EndFunction


;This is a system tray icon example.  Left clicking it runs code in case 1
;Right clicking the icon pops up a menu

;BoxOpen("","")
;WinZoom("")

IntControl(12,1+4,0,0,0)   ; maybe 1+8 after debugged
IntControl(1007, 1, 1, "Click me!", "shell32.dll|39")

tray_ini=FileLocate("tray.ini")
if( tray_ini == "") then
	message("ERROR",strcat( "Ini file tray.ini not found "))
	exit
endif
all_section=IniItemizePvt("",tray_ini)
nb_section = ItemCount(all_section, @TAB)
liste_prog=""
last=0
for j=1 to nb_section
	p = ItemExtract(j, all_section, @TAB)
	c=IniReadPvt(p, "prog", "", tray_ini)
	if( c != "") then
		liste_prog=strcat(liste_prog,p,"|")
		last=last+1
		run%last%=c
	endif
next

liste_prog=strcat(liste_prog,"exit")
last=last+1
While 1
	button=IntControl(1007, 3,0, "", "")
	
	choice=PopupMenu(liste_prog)
	if ( choice == last) then
		IntControl(1007, 2,0, "", "")
		exit
	endif
	if( choice >= 1) then
		c=run%choice%
		%c%
	endif
EndWhile


TRAY.INI

[calculator]
prog=Run("calc.exe","")
[notepad]
prog=Run("notepad.exe","")
[winbatch BBS]
prog=ShellExecute("http://forum.winbatch.com","","",@NORMAL,"")

Article ID:   W15947
File Created: 2013:06:19:13:41:10
Last Updated: 2013:06:19:13:41:10