Use popup menus as controls
Weee, no more DEF SHOWPOP, DEF SHADOWBOX etc...
The following code will use the proper system pop - up CDEF , and Jam it into the FB button list. Then you will get a Button event when the pop - up is selected. Use SCROLL BUTTON to set the popu - menu, and x% = BUTTON(id) to get the value of the menu. The Settings% paramater will take things like _useWndFont etc. You will also need a menu resource as specified by MenuResID%.
It will also do all the left & Right justification, Fixed Width,No title pop - ups etc,etc just have a flick thru IM to find out how, it would take me too long to go thru all the options...
CLEAR LOCAL LOCAL FN PopupMenuButton(theName$,IDtoUse%,MenuResID%,theRect&,Settings%) myWindow& = WINDOW(_wndPointer) LONG IF myWindow& > 0 PopupMenuProc = 1009 Settings% = _PopupMenuProc + Settings% theWidth% = FN STRINGWIDTH(theName$) IF theWidth% > 0 THEN theWidth% = theWidth% + 13 hControl& = FN NEWCONTROL(myWindow&,theRect&.top%,theName$,_True,0,MenuResID% ¬ ,theWidth%,Settings%,IDtoUse% * 65536) END IF END FNeg :
DIM myRect.8 CALL SETRECT(myRect,10,30,200,30 + 30) FN PopupMenuButton("Font Size : ",1,4000,@myRect,0)... or something like that...
The Apple system popup menu CDEF has been available since System 7. If you use this, you will get System 7 style popups on System 7.x, and System 8 style on systems running under 8.x. Warning: vast oversimplification ahead!!
There are a few ways of doing this, but the easiest method is to first define menu resources in your resource fork for the menu/menus you wish to use.
You then use the toolbox NewControl to build a popup menu using the menu you have defined, and specifying _popUpMenuCDEFProc as the CDEF process in NewControl.
By stuffing a button number into the control refCon's upper word, you can trick FB into thinking it is an FB button, and then handle it using your normal button handling routines. Using the toolbox Menu commands, you can change menu items, enable/disable items, etc.
I have some code I can send you if you need more help than this.
I created a control using FN NEWCONTROL(blah). It's a popup menu, that's why I used newcontrol. How can I use the event loop to determine which button was clicked? Buttons created this way don't have an ID, do they?
In this case, dlgID% is zero, and I can't use that, because there is more than one of these newcontrols, and dlgID% is zero for all of them.
CASE _btnClick SELECT dlgID% CASE ????
I assume you are using either the system popup menu CDEF, or another CDEF. FB stuffs the button number in the upper word of the control refcon. If you have the FB Reference manual, look at page 341 under the WNDBLK statement for details (not sure why control records are detailed here, but....)
At any rate, you can make up your own button numbers for your popups, and do something like:
refCon& = myBtnNo << 16 CALL SETCREFCON(ControlHandle&, refCon&)Your button will now show up during _btnClick events, and you can do whatever processing you need to do. Also, if you use FB's BUTTON statement to get the popup value, it will be off by one (1st menu selection will return 2, etc.), so you will need to do
myCtlVal = BUTTON(ControlHandle&) - 1