Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Dynamically Adding Menu Items
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Dynamically Adding Menu Items

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


Joined: 03 September 2004
Status: Offline
Points: 1
Post Options Post Options   Thanks (0) Thanks(0)   Quote cdrew Quote  Post ReplyReply Direct Link To This Post Topic: Dynamically Adding Menu Items
    Posted: 03 September 2004 at 6:28pm

I am a new user to the Pro version of toolkit and am trying to get to grips with the menus and toolbars which are very different from their MFC equivalents.  As such I am updating my application to work as it did before under the toolkit.

I want to add a list of MRU reports to a Reports menu.  I have added a handler for OnInitCommandsPopup, ensured that the popup menu is in fact the Reports menu and then wondered how to add items to it.

My thoughts were to create a CMenu popup menu and then add my new items to it, finally calling LoadMenu to load the CMenu into the command bar.  This should have loaded a menu with 10 items but instead I only got the one and this was disabled.

I have used the following code:

    // get the list of commands for the popup.
    CXTPControls* pCommandList = pCommandBar->GetControls();

   // Is this the ReportWizard menu?
   CXTPControl* pReports = pCommandList->FindControl(xtpControlButton, ID_AUDIT_REPORT, TRUE, FALSE);
    if (!pReports)
      return;

// OK - we are popping up the Reports Menu - let's build the menu first
 CMenu  PopupMenu;
 PopupMenu.CreatePopupMenu ();

 DWORD dwCmdID = ID_FILE_MRU_FILE1;
 for (DWORD dw=0; dw<RptIni.m_listMRUReports.GetCount(); dw++)
 {
  PopupMenu.AppendMenu(MF_STRING ,dwCmdID++ ,RptIni.m_listMRUReports[dw]); 
 }

 // ...add ReportWizard to the end of the menu
 PopupMenu.AppendMenu (MF_SEPARATOR ,0 ,"");
 PopupMenu.AppendMenu (MF_STRING ,ID_AUDIT_REPORT ,"Report&Wizard");

 // ...and then load this menu
 pCommandBar->LoadMenu(&PopupMenu ,TRUE);

This should have created loads of entries but instead I get 1 entry in the menu from the array of reports and the final ReportWizard entry - however the menu items entered in the loop are all disabled.

I have also added

 ON_COMMAND_RANGE(ID_FILE_MRU_FILE1, ID_FILE_MRU_FILE16, OnMRUReport)

to my message map so it should (and did under MFC) work.

Any suggestions would be very welcome

Back to Top
Oleg View Drop Down
Senior Member
Senior Member


Joined: 21 May 2003
Location: United States
Status: Offline
Points: 11234
Post Options Post Options   Thanks (0) Thanks(0)   Quote Oleg Quote  Post ReplyReply Direct Link To This Post Posted: 05 September 2004 at 3:31am

use CXTPCommandBars::Add method to add dynamic items:

pReports->Add(xtpControlButton, dwCmdID);

 

or try to review DynamicPopups sample.

Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS
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.