Bay Six Software Forum Index Bay Six Software
Beyond the Basics
 
 FAQFAQ   SearchSearch   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem (with system tray menu)

 
Post new topic   Reply to topic    Bay Six Software Forum Index -> WMLiberty DLL
View previous topic :: View next topic  
Author Message
lnenad
Guest





PostPosted: Mar 13th, 2007, 8:52pm    Post subject: Problem (with system tray menu) Reply with quote

I didn't know where to post this so i posted it here,

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



 
Back to top
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 728

PostPosted: Mar 13th, 2007, 11:13pm    Post subject: Re: Problem (with system tray menu) Reply with quote

Quote:
Code:
sub showMenu
    popupmenu "&Show main", [show], "&exit", [exitall]
end sub


Branch labels like [show] and [exitall] must be at the same scope as the POPUPMENU statement. That means if POPUPMENU is in a SUB or FUNCTION, also must be the labels.

Personally, I would use the TrackPopupMenu API. It would allow your code to be more flexible.

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
lnenad
Guest





PostPosted: Mar 14th, 2007, 9:44am    Post subject: Re: Problem (with system tray menu) Reply with quote

Can you give me a trackpopupmenu example?

EDIT: fixed it[/code]
Back to top
lnenad
Guest





PostPosted: Mar 14th, 2007, 7:21pm    Post subject: Re: Problem (with system tray menu) Reply with quote

Me again, i ran into a problem, i succeed in using the menu and it does what it needs to do, to show a window, but when i show the window after hiding it the window can't be closed and it reports that the [exit] branch isn't found? ? ? ?

And the solution that fixed my last problem is that i placed the branches in the showmenu sub so this must be connected with that?

Also can you give me an example on using trackpopupmenu api, i did a little search, does the menu need to be created by api (please example)?
Back to top
lnenad
Guest





PostPosted: Mar 15th, 2007, 6:23pm    Post subject: Re: Problem (with system tray menu) Reply with quote

Can you help me or not?
Back to top
Brent
Site Admin


Joined: 01 Jul 2005
Posts: 728

PostPosted: Mar 15th, 2007, 9:23pm    Post subject: Re: Problem (with system tray menu) Reply with quote

You can use an LB-created MENU as a popup menu using GetMenu and GetSubMenu. You can remove the menu if you like (RemoveMenu).

TrackPopupMenu/TrackPopupMenuEx should allow your app to receive the usual WM_COMMAND messages. All of you event handlers (I strongly suggest) should be SUBs to avoid potential out-of-scope errors.

You can also use TrackPopupMenu[Ex] to return the index of the selected menu item. With a SELECT CASE, this is safer than LB's POPUPMENU because it too avoids branch labels.

If you still need a demo, I could cobble one together.

_________________
Brent
Back to top
View user's profile Send private message Send e-mail
lnenad
Guest





PostPosted: Mar 16th, 2007, 7:25am    Post subject: Re: Problem (with system tray menu) Reply with quote

Well it wouldn't hurt, please if you can?

EDIT: It seams that the problem with my code is that it never gets out of the sub, and when i end sub, it closes the entire program(reports please add close commands error?)? Also I've tried exit sub it doesn't work either?
Back to top
Display posts from previous:   
Post new topic   Reply to topic    Bay Six Software Forum Index -> WMLiberty DLL All times are GMT
Page 1 of 1
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum



Lo-Fi Version
Powered by phpBB © 2001, 2005 phpBB Group