Hi,
How do I add dynamic menu items to a menu bar, and change them during the program? - thanks!
You can add new menu items using something like the following. It will add a new menu item just before the 'Exit ' menu item:
You need to make the new menu identifier global if you want to respond to it elsewhere in your program (e.g. WM_COMMAND)
Global IDC_FORM1_MNUPRINT As Long
In the WM_CREATE message for the Form:
Local NewCaption As Asciiz * %MAX_PATH
NewCaption = "Print..."
IDC_FORM1_MNUPRINT = 10001 '<-- must not conflict with other menu id's
InsertMenu HWND_FORM1_TOPMENU, IDC_FORM1_MNUEXIT, %MF_BYCOMMAND Or %MF_STRING, IDC_FORM1_MNUPRINT, NewCaption
Thanks for the advice Paul.
One thing though;
In your example you use IDC_FORM1_MNUEXIT to let the API know to put the new, dynamic menu item before the 'Exit' menu item...
I've played around with this parameter and so far is seems to accept all IDC's of menu items, except for seperators. E.g., IDC_FRMMAIN_MNUSEP02 (the IDC of the second seperator in my menu) generates error 519 when compiling and so do all seperators!?
Hi Mark,
Right you are. Looks like a problem. When I moved menu creation to the resouce file (instead of in-line) I think that I remember that I could not assign an ID to separator items???
e.g.
MENUITEM MFT_SEPARATOR
I'll have to look at this again. It does seem that ID's that FireFly is generating for separators are invalid. :(