Main menu item enabling/disabling |
Post Reply |
Author | |
sunilwarke
Newbie Joined: 28 September 2006 Status: Offline Points: 6 |
Post Options
Thanks(0)
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 = ""; ::MessageBox(NULL, temp1, "Count ok", MB_OK); } Sunil
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
Hello,
Use Update handlers. See any sample from CommandBars folder.
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
sunilwarke
Newbie Joined: 28 September 2006 Status: Offline Points: 6 |
Post Options
Thanks(0)
|
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
|
|
Oleg
Admin Group Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
|
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 |
|
sunilwarke
Newbie Joined: 28 September 2006 Status: Offline Points: 6 |
Post Options
Thanks(0)
|
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
|
|
Post Reply | |
Tweet
|
Forum Jump | Forum Permissions You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |