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

Samples from Users
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus
plus

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

Make PopUp Menus from SysTray Icons

Keywords: 	   popup menus systray icons popmenu

Question:

Using IntControl 1007 I created a WB exe that resides in the system tray. How do I create a menu that can be display when right-clicking the icon? Thanx for any information.

Answer:

Your script can detect the right click and although not popping up a standard sort of menu it can maybe do something like put up a dialog box with choices in it.

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