Hi
I've migrated my project from EVC4 to VS2005. It's targeting Pocket PC 2003. I'm trying to append menus to a CCommandBar like this:
CMenu *menu = AfxGetMainWnd()->GetMenu();
CMenu *submenu = menu->GetSubmenu(0);
submenu->InsertMenu(0, MF_BYPOSITION, 100100, L"test");
AfxGetMainWnd()->DrawMenuBar();
The function doesn't return any errors, and in fact the number of items returned by submenu()->GetMenuItemCount() increases by one, so it seems that the item is added. However, it isn't displayed.
I tried deleting items, and the same thing happens there - no errors, but the item is still there.
I tried getting the menu handle from CCommandBar using GetMenu(), and then attaching a CMenu object to it and using that object to add an item, but that doesn't work either.
Would anyone have any suggestions, or has anyone had similar problems Any help would be greatly appreciated.
Alex.

Can't append menu items to command bar menu after migration from EVC4
GMehta
Hi,
That will mean you are using tradional menus and not the smartphone style menus created with RCDATA in rc2 files. Did you try the link in my last post
Thanks
Nathan Wiegman
Sorry, I haven't tried to swap toolbars.
Best regards
Alex.
Ys
Hi,
The code provided in my previous posts should get things working, if you are using a SHMENUBAR resource. In case you aren't then have a look at http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=369959&SiteID=1 to see how to handle traditional menus.
The problem must be in getting the right menu handle HMENU for the given menu button.
Thanks
tobiasly
Hi,
I found:
IDR_MAINFRAME SHMENUBAR MOVEABLE PURE
in *.rc. From that is was able to discern the proper sub-menu ID. And the code above works fine.
I guess the project is using smartphone style menus created with RCDATA in rc files, instead of rc2 files. This app has been around since the original Pocket PC in 2000.
Thanks,
JEK
dsweb7870
Hi,
While dealing with with the menus displayed at the bottom of the screen( smartphone style), we should remeber that its actually a toolbar that has 2 menu buttons placed on it; and it should be delt with accordingly. The GetMenu functions just tries to return the Menubar actually inserted in the toolbar as the buttons. But to actually make the changes we need to handle the toolbar. So please use the SendMessage API to get the actual handles, from the toolbar.
I think the code should look something like this ( assuming that this is a frame window). The first 3 lines get us a CMenu object that can then be used to handle the corresponding menus.
HWND hMenuMB = (HWND)SHFindMenuBar(this->m_hWnd);HMENU hMenu = (HMENU) ::SendMessage(hMenuMB, SHCMBM_GETSUBMENU,0,IDM_MENU);
CMenu *submenu = CMenu::FromHandle(hMenu);
//Now do the normal stuff with the menu object
//Menu /submenu navigation etc.......
//Make some chnages to the submenu obtained from these menus
subsubmenu->DeleteMenu(pos,MF_BYPOSITION);
subsubmenu->InsertMenuW(pos,MF_BYPOSITION,ID_TOOLS_APPENDITEM ,_T("Changed Text"));Hope this helps. Feel free to contact me offline, if need be.
Thanks
Avinash
david_chai_kf
I sorted out all my problems, and posted what I did here
http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=952864&SiteID=1&mode=1
UIUCBiehl
Jmelgaard
Hi,
What is IDD_MAIN_DLG Is it the command that you associate with the popup menu in SHEMNUBAR segement of resources IDD suggests that its name for the dialog template.
Thanks and good luck
Sheynema
Hi,
The code works fine on a default Wizard project. However, my app fails. This statement returns a NULL hMenu
HMENU hMenu = (HMENU) ::SendMessage(hMenuMB, SHCMBM_GETSUBMENU,0,IDM_MENU);
The reason being IDM_MENU is not the proper sub-menu ID. In the default Wizard project IDM_MENU is wired-up via *.rc2.
I my app, migrated from eVC, *.rc2 has no such info. It's basically empty.
What do I use for the sub-menu ID I tried 0,1and 2; they all fail.
Thanks
JEK
questaware
Alex,
Did you ever get this problem resolved I'm fighting the same issue now.
Thanks
JEK
rduclos
Thanks for your reply.
I tried to use the code you suggested, but I cannot get the menu handle. The code looks like this:
HWND hMenuMB = (HWND)SHFindMenuBar(m_hWnd);
HMENU hMenu = (HMENU) ::SendMessage(hMenuMB, SHCMBM_GETSUBMENU, 0, IDD_MAIN_DLG);
CMenu *menu = CMenu::FromHandle(hMenu);
CMenu *submenu = menu->GetSubMenu(0);
submenu->InsertMenu(0, MF_BYPOSITION, 100100, _T("Changed Text"));
I get the menu window handle, but hMenu is always zero.
In case there is something wrong with the way I create the menu, here is the code:
if (!m_wndCommandBar.Create(this) ||
!m_wndCommandBar.InsertMenuBar(IDR_MAINFRAME, 0) ||
//!m_wndCommandBar.AddAdornments(dwAdornmentFlags) ||
!m_wndCommandBar.LoadToolBar(IDR_MAINFRAME))
{
TRACE0("Failed to create CommandBar\n");
return -1; // fail to create
}
m_wndCommandBar.SetBarStyle(m_wndCommandBar.GetBarStyle() | CBRS_SIZE_FIXED);
Is there anything else I could try
Best regards
Alex.