Print Page | Close Window

Main menu item enabling/disabling

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=5634
Printed Date: 04 October 2024 at 5:25pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Main menu item enabling/disabling
Posted By: sunilwarke
Subject: Main menu item enabling/disabling
Date Posted: 29 November 2006 at 5:46am
Hi,
 
I have the following code, I want to enable and disable some menu buttons on creating MDI application. But wherever I call GetMenu, it always return NULL and the program crashes.
 
Can anybody tell me how to enable or disable the Main Menu controls when using CXTPCommandBars?
 
I tried several options to get the control on the Menu buttons but could not succeeded. If anybody knows how to do it especially in MDI application then please let me know.
 
Here is the code
-----------------------------------------------------------------------------------------
// Get a pointer to the command bars object.
 CXTPCommandBars* pCommandBars = GetCommandBars();
 if(pCommandBars == NULL)
 {
  TRACE0("Failed to create command bars object.\n");
  return -1;      // fail to create
 }
 // Add the menu bar
 CXTPCommandBar* pMenuBar = pCommandBars->SetMenu(
  _T("TIS Menu Bar"), IDR_MDI_TYPE);
 if(pMenuBar == NULL)
 {
  TRACE0("Failed to create menu bar.\n");
  return -1;      // fail to create
 }
 // System popup menu
 pMenuBar->SetFlags(xtpFlagAddMDISysPopup);
 // Create ToolBar
 CXTPToolBar* pToolBar = (CXTPToolBar*)
  pCommandBars->Add(_T("Standard"), xtpBarTop);
 if (!pToolBar || !pToolBar->LoadToolBar(IDR_MDI_MAIN))
 {
  TRACE0("Failed to create toolbar\n");
  return -1;
 }
 
CMenu *mymenu = pMenuBar->GetMenu();
//CMenu *mymenu = GetMenu();

 CString temp, temp1 = "";
 if(mymenu->GetMenuItemCount() > 0)
 {
  for(int j = 0; j < mymenu->GetMenuItemCount(); j++)
  {
   mymenu->GetMenuStringA(j, temp, MF_BYPOSITION);
   temp1.Append(temp);
  }

  ::MessageBox(NULL, temp1, "Count ok", MB_OK);

 }
-----------------------------------------------------------------------------------------

TR,
Sunil



Replies:
Posted By: Oleg
Date Posted: 29 November 2006 at 6:09am
Hello,
 
Use Update handlers. See any sample from CommandBars folder.


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: sunilwarke
Date Posted: 29 November 2006 at 6:42am
Dear Mr. Oleg
 
Thank you for your reply. I have looked at the CommandBar folder for the similar sample code but I did not find the specific one.
 
In my application, there are 4 child windows and the Menu enabling and disabling is not depend on the child selection or creation. The menu items shall be enabled or disabled on some event (coming from database). So I have written a function which shall enable or disable menu items based on the event.
 
On creation some controls will be enabled and some of them shall be disabled.
 
Can you point out specific example for me? Or can you please send me a sample code like a function.
 
void EnableMenuItem(True)
{
    GetMenu()
    EnableItem(Id, enable);
    Update();
}
 
My problem is to get the pointer to the Menu so that I can enable/disable the item based on the Id.
 
 
TR,
Sunil


Posted By: Oleg
Date Posted: 30 November 2006 at 1:52am
Here steps:
 
Add member variable for CMainFrame m_bDatabaseCommandEnabled;
 
Change EnableMenuItem to:
 
void CMainFrame::EnableMenuItem(BOOL bEanbled)
{
    m_bDatabaseCommandEnabled = bEanbled;
}
 
add handlers for all commands you need:
 
 
ON_UPDATE_COMMAND_UI(IDC_TOOLBARCOMMAND, OnUpdateToolbarCommand)
...
void CMainFrame::OnUpdateToolbarCommand(CCmdUI* pCmdUI)
{
pCmdUI->Enable(m_bDatabaseCommandEnabled );
}
 


-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: sunilwarke
Date Posted: 30 November 2006 at 5:02am
Dear Oleg,
 
Thank you very much. I have solved my problem using the solution you gave me.  I have learnt more about ON_UPDATE_COMMAND_UI which was new to me.
 
Once again thank you.
 
TR,
Sunil Warke



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