I have a prog of mine that has a tray icon (learned how to do that from the nl) When i right click it, it popsup a menu, but when i click on any of the choices it reports an branch not found error, now i know that the branch is there.
Here are the pieces of code that i use for the systray.
Code: |
struct OSVInfo,_
OSVInfoSize as long,_ MajorV as long,_ MinorV as long,_ Build as long,_ PlatformId as long,_ CSDV$ as char[128] OSVInfo.OSVInfoSize.struct=len(OSVInfo.struct) call getOSVersion param(4)=OSVInfo.MajorV.struct struct iconData,_ 'used to minimize to the "system tray" iDSize as long,_ 'size of this structure hwnd as long,_ 'handle of window that owns the Icon uID as ulong,_ 'unique identifier (unique to the owning window) uFlags as ulong,_ 'flag denotes which struct items are being sent uCallbackMessage as ulong,_ 'app. defined message that windows will send to the window in this case _WM_USER+1 hIcon as long,_ 'handle to the Icon to use szTip$ as char[64],_ 'tooltip for this Icon dwState as long,_ dwStateMask as long,_ szInfo$ as char[256],_ unionTimeoutVersion as long,_ szInfoTitle$ as char[64],_ dwInfoFlags as long,_ guidItem as ulong open "WMLiberty.dll" for dll as #wmlib dim handle(2) 'array for windows handles dim param(4) 'need some parameters to be global dim defDir(1) 'make the default dir available inside subs and functions NIM.ADD=0 'windows constant that LB doesn't recognise NIM.MODIFY=1 ' ditto NIM.DELETE=2 ' ditto NIM.SETVERSION=4 NIF.MESSAGE=1 ' ditto NIF.ICON=2 ' ditto NIF.TIP=4 ' ditto param(1)=NIM.DELETE 'make these global param(2)=NIF.MESSAGE param(3)=NIM.SETVERSION iconData.uID.struct=8 'icon identifier unique to this window (not necessarilly unique to the system) iconData.uCallbackMessage.struct=_WM_USER+1 'window message OS will send to my window when Icon is activated Tip$="Right click for menu, left to open the main window."+null$(1) 'tooltip text iconData.szTip$.struct=Tip$ 'load tooltip text into struct defDir$(1)=DefaultDir$ if alreadycalled = 0 then callback iconNotice,iconMessage(long,long,long,long),long 'callback for icon message notice calldll #wmlib, "SetWMHandler",_ 'set up WMLiberty.dll to trap and relay this message h1 As long,_ 'handle to the program window wmMessage As long,_ 'message to intercept iconNotice As long,_ 'address of callback in memory 0 As long,_ 'value to send dll to indicate successful handling of message ret As long 'dll returns this value to indicate successful setup alreadycalled = 1 end if sub showMenu popupmenu "&Show main", [show], "&exit", [exitall] end sub [show] print #npp, "show" wait [exitall] hIcon=loadIcon() 'call our function to load the Icon handle(2)=hIcon 'make this handle global uFlags=NIF.MESSAGE or NIF.ICON or NIF.TIP 'set our flags iconAdded=minToTaskbar(h1,uFlags,hIcon,NIM.ADD) wmMessage=_WM_USER+1 callback iconNotice,iconMessage(long,long,long,long),long 'callback for icon message notice calldll #wmlib, "SetWMHandler",_ 'set up WMLiberty.dll to trap and relay this message h1 As long,_ 'handle to the program window wmMessage As long,_ 'message to intercept iconNotice As long,_ 'address of callback in memory 0 As long,_ 'value to send dll to indicate successful handling of message ret As long if iconAdded then notice "your Icon has been added" main = 0 wait 'Close it hwnd=handle(1) flags=param(2) hIcon=handle(2) message=param(1) rIcon=minToTaskbar(hwnd,flags,hIcon,message) 'remove Icon from taskbar call unloadIcon hIcon 'functions 'note: i'm still using the original icon for testing purposes! function loadIcon() fuLoad=_LR_DEFAULTSIZE or _LR_LOADFROMFILE or _LR_LOADTRANSPARENT 'flags for image information if right$(defDir$(1),1)="\" then iconName$=defDir$(1)+"SShot.ico" else iconName$=defDir$(1)+"\SShot.ico" end if calldll #user32,"LoadImageA",_ 'load our Icon into memory so that we can use it 0 as long,_ 'if you load the icon from a bmp, ico, or similar file this must be 0 iconName$ as ptr,_ _IMAGE_ICON as long,_ 'let the call know that we are loading an icon file 0 as long,_ 'xExtent desired **0 because I used the defaultsize flag 0 as long,_ 'yExtent desired **0 because I used the defaultsize flag fuLoad as long,_ loadIcon as long 'return value, nonzero for success loadi = 1 end function function iconMessage(hwnd,uMsg,wParam,lParam) 'icon message handler--lParam hold the mouse message from the icon select case lParam 'wParam holds the icon identifier (in case you have more than one icon) case _WM_LBUTTONDOWN 'don't do anything unless they let the button up while the cursor is over our icon isOk=0 case _WM_LBUTTONUP 'tell them how to use the prog if they left click icall= 1 wait icall = 0 isOk=0 case _WM_RBUTTONDOWN 'don't do anything unless they let the button up while the cursor is over our icon isOk=0 case _WM_RBUTTONUP call showMenu 'haven't been able to get the popup menu to work here yet isOk=0 case else isOk=99 'let the dll know that we don't do anything with _WM_MOUSEMOVE etc. end select iconMessage=isOk 'return a value to the dll to indicate if the message was handled end function sub unloadIcon hIcon calldll #user32,"DestroyIcon",_ hIcon as long,_ ret as long end sub function minToTaskbar(hwnd,uFlags,hIcon,dwMessage) if param(4)<5 then iconData.iDSize.struct=88 else message95=param(3) iconData.iDSize.struct=428 calldll #shell32,"Shell_NotifyIconA",_ 'here we tell the taskbar to behave message95 as long,_ 'like a Win95 taskbar iconData as struct,_ ' result as long ' if not(result) then notice "oops" end if 'if you have more than one Icon for a window then all of your struct iconData.hwnd.struct=hwnd 'elements should be passed to this function then loaded into the iconData.uFlags.struct=uFlags 'structure here. because your tooltip could be different for each one iconData.hIcon.struct=hIcon 'the unique id has to be different for each one, etc. calldll #shell32,"Shell_NotifyIconA",_ 'add the Icon to the taskbar dwMessage as long,_ 'value for 'ADD, MODIFY, or DELETE iconData as struct,_ 'pointer to the struct we just loaded minToTaskbar as long 'return value, nonzero denotes success end function sub getOSVersion calldll #kernel32,"GetVersionExA",_ OSVInfo as struct,_ result as long if result=0 then notice "Critical ERROR!!"+chr$(13)+"Unable to Continue!" end end if end sub |