Print Page | Close Window

Dynamically Adding Menu Items

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=1138
Printed Date: 06 November 2025 at 2:17pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Dynamically Adding Menu Items
Posted By: cdrew
Subject: Dynamically Adding Menu Items
Date 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




Replies:
Posted By: Oleg
Date 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



Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net