MFC personalized menu behaviour - mfc

I generated a MDI tabbed CView project using App. wizard using Personalized menu behavior.
How can i disable personalized menu behaviour ( i dont want it), because i want to see the whole menu at once when i click it. Do i have to generate the project all over again or can i change something in the code to disable it ?

In your CMainFrame::OnCreate method, find the comment that says // enable menu personalization.
Following this will be a couple dozen lines of code that builds a CList of commands, and then calls CMFCToolbar::SetBasicCommands().
Remove the CList and the AddTail calls that build the list. And remove the call to SetBasicCommands. Your menu will now be a “normal” non-personalized menu.

Related

Change MFC Menu to show all items instead of arrows?

Have an MFC application that uses one of the various styles available that has a CMFCMenuBar and toolbar. For the CMFCMenuBar it only shows the items used, otherwise the double-down arrows have to be clicked to see the rest of the items. How do I set it up so it's just all items all the time, without the arrows having to be used?
TIA!!
It depends on how the menu is created and initialized. Look for the following code in CMainFrame class:
CList<UINT, UINT> lstBasicCommands;
lstBasicCommands.AddTail(ID_FILE_NEW);
lstBasicCommands.AddTail(ID_FILE_OPEN);
...
CMFCToolBar::SetBasicCommands(lstBasicCommands);
If you find it, then remove the call to SetBasicCommands
Or keep SetBasicCommands, and also add all the commands to lstBasicCommands
Try using CMFCMenuBar::SetShowAllCommands method.
According to Microsoft, you should call
CMFCMenuBar::SetShowAllCommands(TRUE);
https://learn.microsoft.com/en-us/cpp/mfc/reference/cmfcmenubar-class?view=vs-2019#setshowallcommands

How can I put a menu inside a CDockablePane?

I would like to put a menu inside a CDockablePane so that the pane can have a standard menu as well as a toolbar. The menu itself does not have to be dockable (neither does the toolbar).
As my first attempt, I started with a standard SDI from the VS project wizard, with a dockable Properties pane from which I cut out all the content except the toolbar (I'll be adding a form view eventually). I then tried putting a standard CMFCMenuBar into the pane in much this same way as is done for the main menu in the main frame, but with the dockable pane as the parent. This eventually displays OK in the pane, but only after ignoring various ASSERTS along the way (and on exit), presumably because it is expecting a CFrameWndEx rather than CDockablePane as parent. I suspect it's getting in a tangle with the main frame dock manager.
I would greatly appreciate any advice (or better still sample code) on how to do this properly. Clearly the CMFCMenuBar route is a kludge.

CMFCMenuBar and TestStack.White win.MenuBar is null

I'm trying to use TestStack.White to Automated an MFC Application (for UI testing purposes)
When using TestStack.White with an MFC Application written with CMFCMenuBar (the later Docking framework MFC) I noticed that code like the following fails due to window.MenuBar being null
var menu = window.MenuBar.MenuItem("Window");
menu.Click();
I know I can overcome this issue with the following
TestStack.White.UIItems.MenuItems.Menu windowMenu = win.Get<TestStack.White.UIItems.MenuItems.Menu(SearchCriteria.ByText("Window"));
windowMenu.Click();
But what I really want to do is get the ChildMenus so that I can check the list of windows open in the window menu, but the windowMenu.ChildMenus is empty
I am pretty sure this is because the menu is really a toolbar/toolstrip (dockable)
Does anyone know how to get the menu items (Tile,Cascale,Window1....) from the Window Menu
Has anyone else seen this issue or found a work around?
Thanks in advance
Paul
Yes, the MFC feature pack menu is really a toolbar with buttons. And it is fulfilled using a different process compared to the old style menu.
In your CFrameWndEx derived class, for getting the menu bar you can do:
CMFCMenuBar *pMenuBar= m_Impl.GetMenuBar();
Then it depends on what to do with it. For example, if you want to get the CMenu object that constitutes the menu bar you can do:
CMenu* pMenu= pMenuBar->GetMenu();
If you want to remove some of the menus, you can do (Notice the reverse order):
pMenuBar->RemoveButton(4);
pMenuBar->RemoveButton(3);
You can not get the menu the typical way by YourCFrameWndExDerivedClass::GetMenu() because these new MFC Feature Pack classes intentionally do SetMenu(NULL) when initializing the main frame, as you can see in the call stack:
I am not absolutely sure, but I think you won't also be able to do the override YourCFrameWndExDerivedClass::OnInitMenu() as you could in the old style menus. But you can still use the YourCFrameWndExDerivedClass::OnInitMenuPopup() overrride.

Programmatically and completely delete button from MFC toolbar

I have a document within MFC C++ application. I need to delete one the buttons from the particular CMFCToolbar within a code (not resources) completely, even preventing a user to restore the button via toolbar customization dialog. At this moment I use RemoveButton method of CMFCToolbar but it only makes the button invisible and it can be restored via toolbar customization dialog that is not an option for me at this time. I will be very glad if you suggest something that can help me there.
There are two internal lists in CMFCToolBar that are used to reset the Buttons upon customization.
They are named m_OrigButtons and m_OrigResetButtons.
You may need to derive your own class and delete the buttons with the specific IDs from there.
But better: Never to include such a button on the first time when the toolbar is created!

How Do I Launch a Dialog in MFC?

I'm fairly new to VC++ and MFC, so bear with me. I have created a new dialog, and I want to figure out how to display it when the user clicks a button.
I have not create a class or header file for the dialog -- I tried using the class wizard, but it pretty much sucked and didn't work. That, or I was doing something wrong. Either one is equally as likely if you ask me.
So what steps do I need to take when creating the source/header files and getting the dialog to launch/display? It is a modal dialog.
CLARIFICATION: I understand that I need to create an instance of the dialog class, then just call DoModal() on it, but I'm not sure how to create the class file (with and/or without the wizard).
Right click the project and select
Add | Resource...
Select Dialog under Resource
type and click New.
Select Project | Add Class...
Enter CMyDialog for the Class
name, CDialog for the Base class
and Click Finish.
Read more: How to Make MFC Dialog Boxes
Seems to me you can make the button click just create a new instance of the dialog object and activate it. You'll probably have to keep a reference to the dialog so it doesn't get killed when the button action fxn returns it doesn't get garbage collected..