
FB II Compiler
PG PRO
Debugging
Memory
System
Mathematics
Resources
Disk I/O
Windows
Controls
Menus
Mouse
Keyboard
Text
Fonts
Drawing
Sound
Clipboard
Printing
Communication
ASM |
MENUS
Handle popup menus
here is the code that I use (hacked out of a non-crashing app) locking the menu handle is probably overkill but... as it works i'm not inclined to change
'/--------------------------------------------------------------------------
CLEAR LOCAL MODE
' this takes the menuRef, the Pt& where it is to be displayed, and the
' default item to de chosed at pop up. MenuRef% is used for those
' that must be created on the fly
' It returns the ID of the item chosen.
LOCAL FN doPopUp( rectPtr&, defaultChoice%, menuRef%)
DIM menuRectPt&; 0, rectTop%, rectLeft% ' rect of popup menu
DIM menuResult&; 0, menuID%, itemID% ' results go to menuID and itemID
DIM oldPort&, mHndl&
DIM err
'
' grab the point info
menuRectPt&;4 = @rectPtr&.top%
' prepare the pop up menu
CALL INSERTMENU( FN GETMENU( menuRef%), -1)
' convert rect to global (screen)
CALL LOCALTOGLOBAL( menuRectPt&)
CALL GETPORT( oldPort&)
mHndl& = FN GETMHANDLE( menuRef%)
err = FN HLOCK( mHndl&)
' do we need to build the menu?
SELECT menuRef%
CASE _mConstPopUp : FN doBuildConstPopUp( mHndl&)
END SELECT
' show the menu
menuResult& = FN POPUPMENUSELECT( mHndl&, rectTop%, rectLeft%, defaultChoice%)
err = FN HUNLOCK( mHndl&)
CALL DELETEMENU( menuRef%)
CALL RELEASERESOURCE( mHndl&)
CALL SETPORT( oldPort&)
'
IF( menuResult& <> 0) THEN itemID% = itemID% ELSE itemID% = 0
'
END FN = itemID%
I don't use insert, or delete. I already had built the menu in my resource file with a unique rez id so it comes up with mine first (because of the way resource files are searched). But in two years of using this routine on a MUCH daily basis, it never crashed once.
LOCAL FN test16ColourBar(theMouse&)
DIM rect;0,T,L,B,R:' default rect to use
DIM deMousePt;0,chkMY,chkMX:' my mouse points
CALL SETRECT(rect,12,170,30,180):' where to show the rects for the colours
deMousePt;4=theMouse&:' copy over the point they clicked at
found=_False
count=1:' start looking here
DO
LONG IF FN PTINRECT(deMousePt,rect):' find the icon yet?
chkMY=T
chkMX=R
CALL LOCALTOGLOBAL(chkMY):' convert to screen positions
mHndl&=FN GETMENU(244):' get the menu handle for the popup to use
LONG IF mHndl&:' did we actually get a menu
result&=FN POPUPMENUSELECT(mHndl&,chkMY,chkMX,0):' handle the popup
menuID={@result&}:' get the menu id for us now
itemID={@result&+2}:' get the item they selected now
LONG IF menuID:' did they select something
found=_True
END IF
XELSE
count=128:' just bail out
END IF
XELSE
INC(count):' point to the next tool
T=B+1:B=B+12
END IF
UNTIL count>totalRegions OR found:' go til something happens
END FN=found
My logic, you can't fix it if it ain't broke.
|