|
|
Are Foundation Classes supported in the latest version of Visual Studio 2016 (or whatever version of Visual Studio is currently being published?
Thanks,
Barry
|
|
|
|
|
|
I have added a menu with submenus to my MFC frame program. I also have a child view window instantiated within a main frame.
In the child window i can successfully do a MouseRight click and popup of some menu with its submenus from the main menu bar.
However, when i want to disable some submenu I cannot do it.
I already have the following functions:
bool CMViewOption1Enabled;
.
.
.
.
.
ON_COMMAND(CM_VIEW_OPTION1, CmViewOption1)
ON_COMMAND(CM_VIEW_OPTION2, CmViewOption2)
ON_UPDATE_COMMAND_UI(CM_VIEW_OPTION1, CmEnableViewOption1)
.
.
.
.
.
.
.
void ChildView::CmViewOption1()
{
MessageBox("View Option1", "MENU", MB_OK | MB_ICONEXCLAMATION);
CMViewOption1Enabled = false;
}
void ChildView::CmEnableViewOption1(CCmdUI *ptrenabler)
{
ptrenabler->Enable(CMViewOption1Enabled);
}
void ChildView::CmViewOption2()
{
MessageBox("View Option2", "MENU", MB_OK | MB_ICONEXCLAMATION);
}
So, i right click inside my child view i see Option1, Option2, and when i click on either i can see message window popping up, meaning that they work.
However, if you noticed, when i click Option 1, it must disable this same option in menu (it must be grayed out) but that does not happen.
What is the proper way to get it to work?
to give additonal details, when i right click and select Option 1, i do see message about it, and as i mentioned above I do not see it grayed out, however when i click it again, no message appears, which means (i assume) that menu is already disabled, but not grayed out..so how to permanently disable/gray it out?
modified 11-Jan-16 10:44am.
|
|
|
|
|
You should use your debugger to trap when the call to CmEnableViewOption1 occurs. Or move the message box there; that is the code you need to validate.
|
|
|
|
|
ok so here is a thing,
the CmEnableViewOption1 occurs only when i do View-> from top bar menu, there i see Option 1 and Option2 popping down.
However, when i mouse right click from inside ChildView window i do see |Option1,2 menu popping up but inside debugger it does not enter the CmEnableViewOption1, meaning that this function does not run.
In that case my question would be, why when i click directly inside top frame menu that function is called, but when i right click from child view window and properly getting that menu and can even run its commands, but CmEnableViewOption1 is not executed?
|
|
|
|
|
Have you checked that your ON_UPDATE_COMMAND_UI in the FrameWnd class gets called? It's a long time since I used MFC but I do not recall ever seeing this problem. Take a look at the area where you create and display the popup menu.
|
|
|
|
|
Member 11203277 wrote: In the child window i can successfully do a MouseRight click and popup of some menu with its submenus from the main menu bar.
So you are using a popup (context) menu here and not the menu of the main frame (only the menu items / resources are re-used).
Then you should handle enabling/disabling when opening the popup menu and pass AfxGetMainWnd() as the owner window (see code comments):
CMenu *pMenu = new CMenu;
pMenu->LoadMenu(IDR_OF_MENU);
CMenu *pPopupMenu = pMenu->GetSubMenu(0);
pPopupMenu->EnableMenuItem(CM_VIEW_OPTION1, CMViewOption1Enabled ? 0 : MF_GRAYED);
pPopupMenu->TrackPopupMenuEx(flags, x, y, AfxGetMainWnd(), NULL);
delete pMenu;
A dynamic update is not necessary here when the popup menu closes with the first click. Otherwise make pPopupMenu a member of your child view so that it can be used to change items and/or their state dynamically.
|
|
|
|
|
Perfect! I did almost exactly what you suggested with slight difference;
void ChildView::OnRButtonDown(UINT, CPoint point) {
CWnd* pMain = AfxGetMainWnd();
CMenu *ptrmenu = pMain->GetMenu(); CMenu *ptrpopup = ptrmenu->GetSubMenu(1); ClientToScreen(&point);
ptrpopup->EnableMenuItem(CM_VIEW_OPTION1, CMViewOption1Enabled ? 0 : MF_GRAYED);
ptrpopup->TrackPopupMenu(0, point.x, point.y, AfxGetMainWnd(), 0);
}
Now it works great! thanks
|
|
|
|
|
HI all,
can anybody please suggest me can i change the alignment of text in CStatic label.
i want to change the alignment of text at runtime.
please help me for this.
thanks in advance.
|
|
|
|
|
|
sir have already use this.
but its not working properly\
m_st_label.ModifyStyle(0,SS_CENTER);
|
|
|
|
|
Le@rner wrote: not working properly What does that mean? Are you sure there are no style settings to be removed?
|
|
|
|
|
it means when i change alignment from left to center its shown but again when i change in any other alignment nothing is shown here.
|
|
|
|
|
You should use your debugger to check what options are set each time you make a change, and remember to remove the ones not needed. You also need to refresh the Window after making any changes.
|
|
|
|
|
How to determine whether the disk is bitlocker or or truecrypt?
|
|
|
|
|
|
I am using version C++ 6.0 (and ported another application to VS2008 and I have the same problem). I have multiple dialogs in my application. It has been in use for years and now it has been noticed that if a edit box, checkbox, etc. is changed and then the dialog is dragged to more than 1/2 off the monitor's screen, that the data is reset. This is confusing to me. It seems like it has something to do with Paint, but I am not able to figure it out. Any assistance would be appreciated.
Thanks.
Walt
modified 8-Jan-16 18:30pm.
|
|
|
|
|
Is there an OnActivate handler that might be getting called which is resetting the controls?
What message handlers have been implemented for the dialog?
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
Richard,
Thanks for the reply. I checked my code and I do not have any OnActivate handlers.
Thanks.
Walt
|
|
|
|
|
How to analyze what time Windows 7(XP) once run any program?
modified 8-Jan-16 4:07am.
|
|
|
|
|
|
|
Member 2980860 wrote: ...once run any program?
"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles
|
|
|
|
|
yes,once run any program.
|
|
|
|