Can't find the information you are looking for here? Then leave a message over on our WinBatch Tech Support Forum.
Keywords: popup menus systray icons popmenu
The following creates a SysTray Icon and then creates a right-click popup menu to go along with it:
;NOTE: This example will not work AT ALL in WinBatch Studio, as IntControl 1007 ;and WinBatch Studio debug mode are not compatible. ;Magic. Real Magic. Don't ask. Thanx to Guido for making it work the first time. ;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") While 1 ;1=left button 2=right button button=IntControl(1007, 3,0, "", "") Switch button Case 1 ; left mouse button Message("Hi There","You clicked the left mouse button") Break Case 2 ; right mouse button choice=PopupMenu("Notepad|Calculator|Exit") ; | delimited list of menu items Switch choice Case 1 ; Notepad Run("notepad.exe","") Break Case 2 ; Calc Run("Calc.exe","") Break Case 3 ; Exit IntControl(1007, 2,0, "", "") Message("Exit","ByeBye") Exit EndSwitch Break Case button Message("Default button",button) Break EndSwitch EndWhile
Article ID: W15689
File Created: 2004:12:09:12:30:10
Last Updated: 2004:12:09:12:30:10