is it better to include menus as a resource, hard code them, or create them on the fly?
is it better to include menus as a resource, hard code them, or create them on the fly?
Monday - what a way to spend a seventh of your life
I know it realy depends on what you are doing. If you want the user to be able to modify them you would creat them on the fly. But if you are going to have a specific type of menu that is static (will not change), depends on how you like to code (hard code or resource). That should be able to give you an idea.
C++ Is Powerful
I use C++
There fore I am Powerful
I like to just put it in my code, and avoid resources wherever possible for some reason.
The resources are mean and bad (lolz), load ur menu from a text file and create on the fly, And I STILL hav'nt gotton an answer about this mean resource and button Q I have on here.
SPH
no, don't load it from a TEXT file, just do something like....
Code:/*excpert from ASMEdit...*/ enum ID {ID_VIEW = 1, ID_FILE_EXIT = 9001, ID_FILE_OPEN = 9002, ID_FILE_SAVE = 9003, ID_HELP_ABOUT = 9004, ID_CMPL_A86 = 9005, ID_CMPL_NASM = 9006, ID_FILE_NEW = 9007, ID_HELP_HELP = 9008}; void MenuInit(HWND hwnd, HMENU hMenu, HMENU hSubMenu) { hMenu = CreateMenu(); hSubMenu = CreatePopupMenu(); AppendMenu(hSubMenu, MF_STRING, ID_FILE_NEW, "&New"); AppendMenu(hSubMenu, MF_STRING, ID_FILE_OPEN, "&Open"); AppendMenu(hSubMenu, MF_STRING, ID_FILE_SAVE, "&Save"); AppendMenu(hSubMenu, MF_SEPARATOR, NULL, NULL); AppendMenu(hSubMenu, MF_STRING, ID_FILE_EXIT, "E&xit"); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&File"); hSubMenu = CreatePopupMenu(); AppendMenu(hSubMenu, MF_STRING, ID_CMPL_A86, "Compile With A&86"); AppendMenu(hSubMenu, MF_STRING, ID_CMPL_NASM, "Compile With &NASM"); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Compile With"); hSubMenu = CreatePopupMenu(); AppendMenu(hSubMenu, MF_STRING, ID_HELP_HELP, "&Help"); AppendMenu(hSubMenu, MF_STRING, ID_HELP_ABOUT, "&About ASMEdit..."); AppendMenu(hMenu, MF_STRING | MF_POPUP, (UINT)hSubMenu, "&Help"); SetMenu(hwnd, hMenu); }
Ken! You noncompoop, thats wut I WAS TELLING THEM TO DO, just loaded from a file not hard coded strings lolz.
SPH
mine's prettier.
Why dont u go on IM instead of filling my email box with stupid "KEN HAS REPLIED" messages!
SPH
why don't you try unblocking me, cuz I just got off IM :-P and now I'm going.
TURN OFF E-MAIL REPLIES!!!
In general, I prefer to build them as a resource because my applications have a fix menu and I don't want to bother to much with it.is it better to include menus as a resource, hard code them, or create them on the fly?
If you need a more "dynamic" menu it's better to create it on the fly.
And you can always create a mixed menu, ie create a menu resource with some items and on the fly add/remove items depending on the application.
Chemanuel
Lo bueno si breve dos veces bueno (Baltasar Gracián 1601-1658)
Why does it have to be either or? I use resources for my base menus and then alter them at run-time. It does not seem any harder for me to alter a resource menu at run-time than a non-resource menu. Besides, generating resource menus also allows me to see how the thing is going to look and act before I place it in my main window. It's probably just a matter of personal preference, but creating huge menus within code really looks ugly. I'd much rather have the beast sitting in a resource file somewhere.
I don't see what the problem is with resource menus. If you are not using a library that allows for dynamic menus then write a small class that encapsulates the API calls and intercepts and translates the messages relating to menus and menu items. Once that is finished, just use that class in your future projects.