![]() |
Regarding Enabling/Disableing Menu |
Post Reply
|
| Author | |
KumarCJ
Groupie
Joined: 02 April 2007 Location: India Status: Offline Points: 96 |
Post Options
Thanks(0)
Quote Reply
Topic: Regarding Enabling/Disableing MenuPosted: 26 April 2007 at 2:03am |
|
Hi,
ISSUE: All Menu Item are in enabled state eventhough there is no active child window.
Our application was developed using Code jock 4.2 version. Now we are trying to implement code jock 10.4.2 in our application.
In our older version of application which is using code jock 4.2, we were using "ON_WM_INITMENUPOPUP()" command, whose definition is below:
void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)
{ TMDIFrameWnd :: OnInitMenuPopup( pPopupMenu, nIndex, bSysMenu);
HMENU hMenu = pPopupMenu->GetSafeHmenu();
MyApp_OnInitMenuPopup(m_hWnd, hMenu, nIndex, 0L);
}
and in the definition of "MyApp_OnInitMenuPopup(m_hWnd, hMenu, nIndex, 0L)" function we are enabling and disableing the menu item based on conditions.
In the older version of above given code if I am clicking EDIT Menu, the values for parameter of "OnInitMenuPopup()" we are getting for are below:
CMenu* pPopupMenu ----- CTempMenu
UINT nIndex ----------------- 2
BOOL bSysMenu ------------ 0 i.e FALSE
But when I used code of Code jock 10.4.2 version for setting the Menu using "pCommandBars" using below code,
// Create MenuBar using CXTPMenuBar*
m_wndMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME); the values what we are getting for above mention 3 paramenters
CMenu* pPopupMenu ----- CTempMenu
UINT nIndex ----------------- 0 [***ISSUE***]
BOOL bSysMenu ------------ 1 i.e TRUE [***ISSUE***]
Due to this for EDIT menu, all the Menu item such as Cut,Copy,Paste, Find.....all are in enable state eventhough the there is no active child window.
The Same this is happening for all other Menu.
Please help me out.
Thanks,
KumarCJ |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 26 April 2007 at 6:27am |
|
Hello,
OnInitMenuPopup is never called for CommandBars. Check notifications sample - you can use OnInitCommandsPopup event instead
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
KumarCJ
Groupie
Joined: 02 April 2007 Location: India Status: Offline Points: 96 |
Post Options
Thanks(0)
Quote Reply
Posted: 26 April 2007 at 8:22am |
|
Hi Oleg,
Thanks for your reply.
I had trying with the OnInitCommandsPopup() given in Notification sample.
I trapped "ON_XTP_INITCOMMANDSPOPUP()" i.e. OnInitCommandsPopup() function.
void CMainFrame::OnInitCommandsPopup(CXTPPopupBar* pCommandBar)
{ // get the list of commands for the popup.
CXTPControls* pCommandList = pCommandBar->GetControls(); CMenu* pPopupMenu;
CMainFrame * pMainFrame = (CMainFrame *)AfxGetMainWnd(); pPopupMenu = CMenu::FromHandle(pMainFrame->hMenuHandle); //Get Menu Handle
HMENU hMenu = pPopupMenu->GetSafeHmenu();
//MyApp_OnInitMenuPopup(m_hWnd, hMenu, nIndex, 0L);
[Note: For Edit Menu, hard coded nIndex = 2]
Pim_OnInitMenuPopup(m_hWnd, hMenu, 2, 0L);
}
But the issue is that i need to pass the "nIndex" parameter to MyApp_OnInitMenuPopup(m_hWnd, hMenu, nIndex, 0L) function.
How I can get the "nIndex" when i clicked on menu i.e. for Edit menu it 2, for view it is 3.
nIndex is the Menu Index i.e on which menu user clicks.
I had hard coded the nIndex to 2 i.e for Edit Menu and tried, the function MyApp_OnInitMenuPopup() is going fine,
but finally after clicking on EDIT menumenu Item such as Cut, Copy, paste are enabled eventhough there is no active child window.
[Question 1:]
How can i get "nIndex" using OnInitCommandsPopup(CXTPPopupBar* pCommandBar)???
[Question 2:]
If I hard coded the nIndex = 2 for Edit Menu and MyApp_OnInitMenuPopup() is going fine, then why Cut, Copy, Paste is not disabled. Is there any more messages i need to do add???
Waiting for reply.
Thanks,
KumarCJ
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 27 April 2007 at 1:10am |
|
Hello,
Do you use standard View/Document architecture? By defaul they have to be disabled if you don't have handlers for them. if you have handlers - just add also Update handlers and enable/disable them in this handler - not in OnInitCommandsPopup.
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
KumarCJ
Groupie
Joined: 02 April 2007 Location: India Status: Offline Points: 96 |
Post Options
Thanks(0)
Quote Reply
Posted: 27 April 2007 at 3:18am |
|
Hi Oleg,
Our application follows standard View/Document architecture, We do not have handler for cut,copy,paste and find in our OLDER version of application as well as NEW version of Application.
we are just using "ON_WM_INITMENUPOPUP()" message in older version of our application.
For above mentioned message we are having Handler
"void CMainFrame::OnInitMenuPopup(CMenu* pPopupMenu, UINT nIndex, BOOL bSysMenu)"
So when user click on any of the menu, MFC framework fills nIndex = 2 (Assume user selected EDIT Menu).
This nIndex value we are passing to OnInitMenuPopup() function with aother parameters such as window handle, Menu Handle, etc
MyApp_OnInitMenuPopup(m_hWnd, hMenu, nIndex, 0L);
In this function based on certain condition we are enabling/disabling menu items.
The Above mentioned flow is for OLDER as well as NEWER version of our application. Assume Edit Menu Contail following Menu Items: Cut, Copy, Paste, Find
AddRecord
When we were using below lines of code
CXTPMenuBar* m_wndMenuBar = pCommandBars->SetMenu(_T("Menu Bar"), IDR_MAINFRAME);
All Menu Item get Enabled, means cut,copy,paste and AddRecord are in ENABLED state.
But when we are using OLD code, Menu Item are displaying fine.
Means Cut,Copy, Paste, Find are in DISABLED state and AddRecord menu item is in ENABLED state.
So What I should do for this to overcome this issue....?
I went through the Notification Sample and tried with following handlers
OnCreateCommandBar
OnCreateControl
OnAfterCreateControl
OnCustomize
OnInitCommandsPopup
What I understand from this that as soon as we used SetMenu(), Program control is not comeing to "OnInitMenuPopup", but when i tried with OnInitCommandsPopup() and when user click on Menu, the Control is comming to "OnInitCommandsPopup()".
Is there any way to get the nIndex by using
OnInitCommandsPopup(CXTPPopupBar* pCommandBar)
Please help me out in this ISSUE.
Waiting for your kind suggetions.
Thanks,
KumarCJ. |
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 27 April 2007 at 3:56am |
|
Hello,
This is _very_ bad idea to use WM_INITMENUPOPUP to enable/disable state for some controls. users can customize menu and move Cut Command from one menu to another - to copy this menu to toolbar, delete it etc.
as I wrote use Update handlers for IDs:
in message map of your view add:
ON_UPDATE_COMMAND_UI(ID_ED_CUT, OnUpdateCut)
void CYourView::OnUpdateCut(CCmdUI* pCmdUI)
{ pCmdUI->Enable(m_bNeedToEnable); } it will work with your old application/new appliaction and any future applications.
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
KumarCJ
Groupie
Joined: 02 April 2007 Location: India Status: Offline Points: 96 |
Post Options
Thanks(0)
Quote Reply
Posted: 27 April 2007 at 6:20am |
|
Hi Oleg,
Thanks you very much for your seggestions and help.
Yes I do understand it is not good idea to implement WM_INITMENUPOPUP, but as we are following design patterns and handling all the enabling/disabling menu item in a single class, which required nIndex, which we were getting in OnInitMenuPopup() function's 2nd parapameter.
Is there any way to get nIndex (determine on which menu user clicks), so that I have to make few changes with changing the desgin pattern. Is there any other way to handle this ISSUE????
Waiting for your valuable suggestion.
Thanks,
KumarCJ.
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 27 April 2007 at 6:46am |
|
Hi, catch
OnInitCommandsPopup(CXTPPopupBar* pCommandBar)
loop all controls and check IDS of them:
nCount = pCommandBar->GetControls()->GetCount();
for (int i = 0;i < nCount; i++
{ if (pCommandBar->GetControl(i)->GetID() == ID_EDIT_CUT)
pCommandBar->GetControl(i)->SetEnable(FALSE);
}
etc.
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
KumarCJ
Groupie
Joined: 02 April 2007 Location: India Status: Offline Points: 96 |
Post Options
Thanks(0)
Quote Reply
Posted: 27 April 2007 at 8:29am |
|
Hi Oleg,
Thanks for your great suggestion.
When I placed the code what you sent it giving the error below:
Then I searched for SetEnable() in the help, and I found SetEnabled() in CXTPControl class.
Then i tried with SetEnabled () in the following code,
void CMainFrame::OnInitCommandsPopup(CXTPPopupBar* pCommandBar)
{ CXTPControl* pCommandNew = pCommandBar->GetControls()->FindControl(xtpControlButton, ID_EDIT_CUT, TRUE, FALSE);
//CXTPControl* pCommandNew = pCommandBar->GetControls()->FindControl(xtpControlPopup, ID_EDIT_CUT, TRUE, FALSE);
int nCount = pCommandBar->GetControls()->GetCount();
for (int i = 0; i < nCount; i++)
{ if (pCommandBar->GetControl(i)->GetID() == ID_EDIT_CUT) pCommandNew->SetEnabled(FALSE); //[Comment out due to error mentioned above] //pCommandBar->GetControl(i)->SetEnable(FALSE);
} }
But the ISSUE remains the same?
What need to be done for this Oleg????
Thanks,
KumarCJ
|
|
![]() |
|
KumarCJ
Groupie
Joined: 02 April 2007 Location: India Status: Offline Points: 96 |
Post Options
Thanks(0)
Quote Reply
Posted: 30 April 2007 at 2:37am |
|
Hi,
wating for your valuable suggestion.
I had mention the issue in code what you sent it to me in prvious post.
Please let me know the solution for that.
Thanks,
KumarCJ
|
|
![]() |
|
Oleg
Senior Member
Joined: 21 May 2003 Location: United States Status: Offline Points: 11234 |
Post Options
Thanks(0)
Quote Reply
Posted: 30 April 2007 at 4:03am |
|
void CMainFrame::OnInitCommandsPopup(CXTPPopupBar* pCommandBar)
{ int nCount = pCommandBar->GetControls()->GetCount();
for (int i = 0; i < nCount; i++)
{ CXTPControl* pCommandNew = pCommandBar->GetControl(i)
if (pCommandNew->GetID() == ID_EDIT_CUT) { pCommandNew->SetEnabled(FALSE);
pCommandBarNew->SetFlags(xtpFlagManualUpdate);
} }
}
Also check "Samples\CommandBars\ActionsSample" sample - if you don't want update handlers, you can use actions
pCommandBars->GetActions()->FindAction(ID_EDIT_CUT)->SetEnabled(FALSE);
again - don't use OnInitCommandBarsPopup for changing state - its very bad design. There is no pattern for such design.
|
|
|
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS |
|
![]() |
|
KumarCJ
Groupie
Joined: 02 April 2007 Location: India Status: Offline Points: 96 |
Post Options
Thanks(0)
Quote Reply
Posted: 30 April 2007 at 4:58am |
|
Hi Oleg,
Thank you very much for your great support and responce.
We will surely discuss the issue for using "OnInitCommandBarsPopup()" with our team.
Thanks,
KumarCJ.
|
|
![]() |
|
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 |