Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Help with dynamic menu items
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Help with dynamic menu items

 Post Reply Post Reply
Author
Message
thomasmfields View Drop Down
Newbie
Newbie


Joined: 23 June 2021
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote thomasmfields Quote  Post ReplyReply Direct Link To This Post Topic: Help with dynamic menu items
    Posted: 20 February 2025 at 8:13am
Hi there,

I'm trying to manage my own recent files list as part of my File drop down menu.

In my .rc file I have:

IDR_MAINFRAME MENU
BEGIN
    POPUP "&File"
    BEGIN
        MENUITEM "&New",     ID_FILE_NEW
        MENUITEM "&Open", ID_FILE_OPEN
        MENUITEM "Recent File",      ID_RECENT_FILE
        MENUITEM "&Exit",            ID_FILE_EXIT
    END
END

Then in my callback for ID_RECENT_FILE I have:

CXTPCommandBar* menuBar = MainFrame::GetInstance()->m_menuBar;
if (menuBar)
{
CXTPControls* pControls = menuBar->GetControls();
CXTPControl* pControl = pControls->GetAt(0); // File menu is 0
CXTPControls* pUtilCtrls = pControl->GetCommandBar()->GetControls();
CXTPControl* pSubMenuItemCtrl = pUtilCtrls->GetAt(2); // New (0), Open (1), Recent File (2)
CMenu *SubMenu = new CMenu;
SubMenu->CreatePopupMenu();

SubMenu->AppendMenu(MF_BYPOSITION | MF_STRING, kBaseEffectMenuOptionId2+1, _T("Item3-1"));
SubMenu->AppendMenu(MF_BYPOSITION | MF_STRING, kBaseEffectMenuOptionId2+2, _T("Item3-2"));
SubMenu->AppendMenu(MF_BYPOSITION | MF_STRING, kBaseEffectMenuOptionId2+3, _T("Item3-3"));
CMenu *SubSubMenu = new CMenu;
SubSubMenu->CreatePopupMenu();
SubSubMenu->InsertMenu(0, MF_BYPOSITION | MF_POPUP | MF_STRING, (UINT_PTR)SubMenu->m_hMenu, _T("Recent File"));

pUtilCtrls->AddMenuItem(SubSubMenu, 0);
}

The problem is that the AddMenuItem() seems to just put the new menu at the bottom of my File menu. So I get:

New
Open
Recent File
Exit
Recent File

How do I move it (and replace) the existing "Recent File" entry that appears 3rd in the list?

Many thanks
Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.047 seconds.