Re: dynamic menus

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



Yes, you are right about the variable going out of scope. I'm new at Windows
programming, so I keep getting tripped up by little things like this.
Thanks, I'm able to move further now.

So every menu item ID within the entire project must be unique, but it
doesn't matter if the ID is reused by a button or string or any other
control? I see the standard menu ID have a special range stating near
0xE000, so I will stay away from that. I have to be careful that I don't use
an ID that the class wizard may later assign to another menu that is not
dynamically generated. Is it safe to use WM_USER and add one for each new
dymanic menu item?

More importantly, how do I 'connect' these to OnDynamicMenuItem() and
OnUpdateDynamicMenu()? Since I am creating the menus at runtimme, I can't
depend on compile time functions. That means I would prefer to have the
entire range of these dynamic menus be 'connected' to single functions that
are passed the ID, so they can look up the correct menu object to access. I
could put the dynamic menu item along with its two functions into a class.
But I still don't know how to programmatically add the 'connection' from the
ID to the functions.

Thanks...


"David Ching" <dc@xxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:PAfLe.1308$A%3.232@xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
>
> "Bill Brehm" <don't want any spam> wrote in message
> news:%23sLYUF8nFHA.2904@xxxxxxxxxxxxxxxxxxxxxxx
>>I want to be able to create a hierarchy of menus under the view menu. I
>>don't know at design time how many items will be under each submenu.
>>
>> I have been able to access and add to the view menu itself. By I have not
>> been able to add anything under that added menu. I know it shuold be a
>> popup menu. but when I make it a popup, I get an assert when I try to
>> open the view menu. Here's what I have so far (some experimentation still
>> remains):
>>
>> m_pWndMenu = GetMenu();
>> //int count = m_pWndMenu->GetMenuItemCount();
>> //CString string;
>> //m_pWndMenu->GetMenuString(2, string, MF_BYPOSITION);
>> CMenu *pViewMenu = m_pWndMenu->GetSubMenu(2); // gets view menu.
>> pViewMenu->InsertMenu(0, MF_BYPOSITION | MF_SEPARATOR);
>> CMenu objectMenu;
>> objectMenu.CreateMenu();
>> pViewMenu->InsertMenu(0, MF_BYPOSITION | MF_STRING | MF_POPUP,
>> (int)objectMenu.m_hMenu, "Objects");
>> CMenu *pObjectMenu = pViewMenu->GetSubMenu(0); // gets object menu
>> pObjectMenu->InsertMenu(0, MF_BYPOSITION | MF_STRING, 101, "Object 1");
>> pObjectMenu->InsertMenu(0, MF_BYPOSITION | MF_STRING, 102, "Object 2");
>>
>> What am I doing wrong and how do I fix it?
>>
>
> Most likely your objectMenu is going out of scope and being destroyed.
> Make objectMenu a member of a class (perhaps the CWnd that owns the menu)
> that will stick around for the lifetime of the menu.
>
>
>> Also, will have to call a function and/or work with OnUpdateCmdUI(). How
>> do I dynamically create IDs for these when I won't know in advance how
>> many levels deep and how many items at each level. (I have seen duplicate
>> IDs in resource.h. But I don't know where duplicates are allowed without
>> causing a conflict.) I have looked at the dynamenu example, but they are
>> only adding into a menu that already exists and they are not creating a
>> popupmenu. Furthermore, they have predefined all their IDs because they
>> know in advance that they will support four colors.
>>
>
> Each command ID generated by the menu items must be unique. Beyond that,
> there is no restriction. Perhaps you could use a counter, initialized to
> a value greater than any of the existing menu item command id's, and
> increment it each time you add one of your own. (I think Windows restrict
> command id's to some range, so you can't use just any number.) Then you'd
> have to remember which ID was for what function, so you could properly
> handle the commands when they are selected from your menu.
>
> -- David
> http://www.dcsoft.com
>
>


.



Relevant Pages

  • Re: Connecting to Linux from Windows XP
    ... >> variety of the kinds of software that Windows users like. ... > switching to CP/M, DOS, Mac, then Windows, so I grew up with command lines. ... configuration and/or programming give me command line any day. ... I remember having to use some configuration interfaces that force ...
    (alt.os.linux.suse)
  • Re: [OT] Accessing OS Functionality [was Re: _popen "mail -s" unrecognised command]
    ... >> something similar in Windows, but it is now apparent that I ... > Windows, on the other hand, encourages GUI usage over command line usage, ... Although I have done considerable VB API programming, ... You are right in everything you say Anthony, ...
    (alt.comp.lang.learn.c-cpp)
  • Re: what kind of scripting is this ?
    ... scripting or just windows scripting? ... command line window. ... Microsoft used to have a newsgroup for batch programming. ...
    (microsoft.public.scripting.vbscript)
  • Preferred language for shell scripting?
    ... I've install a Unix like programming environment, call MSys, which let's me ... do command line programming the way I want to, with the bash shell, and this ... what do experienced Windows programmers use for shell ...
    (microsoft.public.dotnet.languages.csharp)
  • RE: re-setting boot partition
    ... Description of the Windows 2000 Recovery Console ... For a Microsoft Windows XP version of this article, ... MB of hard disk space on your system partition to hold the Cmdcons folder ... Windows NTBoot Console Command Interpreter. ...
    (microsoft.public.win2000.setup_upgrade)