Visual Studio MFC Toolbar Editor icon order won't update - c++

I've been trying to create a custom toolbar in a MFC project in Visual Studio 2010. I've been following the Sketcher tutorial in Ivan Horton's Beginning Visual C++ 2010. The problem I'm running into is that the toolbar doesn't update to reflect the order and spacing of icons I have created.
I've created a small screenshot to demonstrate the problem:
In the background is the visual studio toolbar editor with my desired toolbar configuration. In the foreground is the actual app, which does not reflect the spacing or order of icons I've designed. It does reflect NEW icons being added, and the icons work fine, but I just can't seem to get them to re-order or appropriately space themselves. They just append to the end in whatever order I create them.
I've tried the rudimentary techniques of restarting both VS and windows, but to no avail.
Any tips on getting it to play nicely? Lacking that, is there somewhere to manually view or edit the code generated by the toolbar editor?

For starters, if you create an MFC SDI/MDI project in VS.NET 2005, there is no such issue. It happens in VS.NET 2008 and 2010.
In fact, your rearrangement of the standard toolbar does takes effect. It's just not showing you the default state. To restore the state: click the small arrow button at the end of toolbar -> Add or Remove Buttons -> Standard -> Reset Toolbar.
Though I'm not 100% sure why it happens like this(design like this or a bug), there is a way to work around it and it works:
Add following code to the end of CMainFrame::LoadFrame(...)
BOOL CMainFrame::LoadFrame(UINT nIDResource, DWORD dwDefaultStyle, CWnd* pParentWnd, CCreateContext* pContext)
{
...
// Explicitly restore toolbar state
m_wndToolBar.RestoreOriginalstate();
return TRUE;
}
I recommend you to contact Microsoft support engineers as there's little resource on the web.

The reason could be that the toolbar state is already loaded from the registry whenever your application starts. So the framework reads the toolbar state and adds the new buttons to the end. Is there a Workspace key in your Registry and did you try to delete it anytime you make changes to the toolbar? The key should be at a location like HKEY_CURRENT_USER\Software\MyCompany\MyApp\Workspace
The values for MyCompany and MyApp are usually set in InitInstance. Always calling RestoreOriginalState() would break the code to allow user modifications to the toolbar.

Related

Disabling menu compression in MFC

My English is not perfect. I am using Visual C++ 2019 and MFC. At my MDI-program, the menus are compressed: I do not see all the items, there is a double-arrow-like something on bottom of the menu, I always must click to them. I can not disable this. At Resource View, I can not open the whole menu's Properties Page, only for the File, etc. menu's Properties Page. I did not find the disabling on the Properties Page. In the code, in MainFrm.cpp, CBRS_SIZE_DYNAMIC and CBRS_FLYBY occur 2+2 times. I tried to put to comment them, but this did not solve the problem. How can I disable the compression? Thank you.
I can not open Properties Page of the whole menu. Maybe it has not Properties Page, or the cause is the lack of High DPI support in Visual Studio. For example, I can not edit icons: the icon editor is unusable. At the generated program, it seems the High DPI support of toolbar is depend on the style. At WinAPI programs, there are 3 pixel stairs: emulates 1/3 resolution. There is 3*96 dpi = 288 dpi at me, 0,16 mm * 3 = 0,48 mm.
Use CMFCMenuBar::SetShowAllCommands
Remarks
If a menu does not display all the menu commands, it hides the commands that are rarely used.
Whether the application should display all menu items or just the most recently used ones (and the user will have to expand the rest) is an option that can be set by the user: Toolbar Options->Add or Remove Buttons->Customize->Options->Personalized Menus and Toolbars->Menus show recently used commands first. This option is saved in the registry under HKEY_CURRENT_USER\SOFTWARE\CompanyName\ApplicationName\Workspace\MFCToolBarParameters\RecentlyUsedMenus, so the application "remembers" it.
Programmatically it can be changed using the CMFCMenuBar::SetRecentlyUsedMenus() function - it's a static function.
It would be best to let the user decide how the application should work, so I would recommend that you do... nothing about it. Or, you could set it to FALSE, but only for the very first time the application is run. Add a new boolean value in the registry, under ...ApplicationName\Workspace or ...ApplicationName\Settings, with a value always set to TRUE. The best place to do this is the SaveCustomState() member function of your application class. In the LoadCustomState() read that value (default FALSE), and if it is TRUE call CMFCMenuBar::SetRecentlyUsedMenus(FALSE);.

Coded UI Test winforms menu item identification wrong

I use the assertion function to identify controls. When I use the assertion function for the Coded UI Test (Ctrl + Shift + I) the menu items in my .NET application running on Windows 10 are always recogniced at the wrong position. I use Visual Studio 2017 Enterprise (version 15.5.7).
My cursor was at the "Öffnen" menu item but the MSAA thinks it is the "Speichern" menu item. It seems shifted for one menu entry.
For other application the control identification works fine. It seems a problem with this particular application.
What could possibly be wrong in using Coded UI Test Builder?
Update
I also tried to increase the MaxLevelsForItemContainer from the default value of 2 to 5 in the CodedUITestBuilder.exe.config without success.
The SearchConfiguration.NextSibling() method didn't work either.
It is probably an issue with the Spiechern button masking the Öffnen button -
atleast so far as the test builder sees it.
Try navigating to the Öffnen button through usage of the parent child navigator in the test builder (the button button 4 arrows around a blue box, next to Retry and Add Assertion), and then identify with the NextSibling() method. This would look like:
// Clicks Öffnen - Change NextSibling()to be whatever filial relation is required
var offnen = new WpfButton();
offnen = offnen.SearchProperties.Add(WpfButton.PropertyNames.Name, "Spiechern").NextSibling();
offnen.Click();
If that doesn't work set your tests up to use the identification of the Spiechern button, and then alter the portion that needs to click on the Öffnen button to click slightly above above the Spiechern button. That would look like:
// Clicks Öffnen - Change xOffset and yOffset to whatever is required to click Öffnen
var spiechern = new WpfButton();
spiechern= spiechern.SearchProperties.Add(WpfButton.PropertyNames.Name, "Spiechern");
Mouse.Click(spiechern, new Point(xOffset, yOffset));
I was able to do what I wanted by using the menu keyboard shortcuts and navigating through the menu and record this.
Possible solution in this case:
use keyboard shortcuts
After an Visual Studio 2017 Enterprise update from version 15.5.7 to 15.6.1 the menu item was recognized correctly. I'm not aware of any other change I did on my system but since the update it seems to work.
Solution:
Update Visual Studio 2017

Quick Access Toolbar (QAT) doesn't shown in Ribbon MFC

I'm converting an existing application to use ribbon. I'm using visual studio 2012. I tried to add buttons through QAT properties editor in the ribbon designer. The QAT shown in the Test Ribbon mode correctly. But It's not shown when I debugging the application. The dropdown box button is there but not functional.
I've also tried to add buttons in code, but it makes no difference:
MFCRibbonQuickAccessToolBarDefaultState qatState;
qatState.AddCommand(ID_FILE_SAVE);
qatState.AddCommand(ID_EDIT_UNDO);
m_wndRibbonBar.SetQuickAccessDefaultState(qatState);
Any idea would be appreciated. The part of QAT in ribbon1.mfcribbon-ms is:
<QAT_ELEMENTS><ELEMENT_NAME>QAT</ELEMENT_NAME><QAT_TOP>TRUE</QAT_TOP><ITEMS><ITEM><ID><NAME>ID_FILE_NEW</NAME><VALUE>57600</VALUE></ID><VISIBLE>TRUE</VISIBLE></ITEM><ITEM><ID><NAME>ID_FILE_OPEN</NAME><VALUE>57601</VALUE></ID><VISIBLE>TRUE</VISIBLE></ITEM></ITEMS></QAT_ELEMENTS>
I solved it. In the CAppnameApp::InitInstance() function in the Appname.cpp, call InitContextMenuManager() function. This initialize the CContextMenuManager object which manage shortcut menus. This object is introduced in VC2008. Also other functions like InitShellManager(); InitKeyboardManager(); InitTooltipManager();need to be called at the same place.

Changing program icon dynamically

In C++, is there anyway to let the user chose the icon of the app? For example, Winamp lets you select which icon you wish to use from a list of icons in it's preferences. How is it done?
There is the icon that you see in explorer. This is a resource in your executable. You could change that, but I wouldn't advise you too. Virus scanners can get nervous if executables are modified, and in Windows Vista you will not even be allowed to write in the Program Files folder.
But the icon that is displayed on the task bar or in the system tray can be changed. This is actually the icon of your application window and it can be set by sending a WM_SETICON message.
And there are shortcuts. They can be changed too, and in a shortcut you can specify which icon should be used.
I found a discussion on changing icons that has information about the first two options.
For Visual Studio 2010 in an MFC dialog based app
A. In the resource view, rightclick Icon folder and add icon. Give it an ID like IDI_MYICON. Leave it as is or draw something nice.
B. Go to OnInitDialog. Add the following two lines of code:
HICON hMyIcon = LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE(IDI_MYICON) );
SetIcon( hMyIcon, FALSE ); // FALSE == use as small icon
You can read about these functions in the help to understand what is happening.
This sets the icon as icon for the sysmenu (topleft) and in the taskbar. This is however not automatically reflected in all situations. E.g. for a systray icon you need to explicitly specify the icon again in the call to Shell_NotifyIcon().

How to show available windows in the Window menu

I have a MFC MDI application that I've recently ported from VS2003 to VS2008, and at the same time moved from Stingray Objective Studio 2006 v2 to v10.1. On the previous versions of my application, if I had more than one view open, the Window menu would be populated by an enumerated list of available views, e.g. 1 MyViewA, 2 MyViewB etc... If I had a large number of views, I would also get a Windows... menu option to allow me to select a view. This no longer happens, which is breaking some of my GUI level regression tests. My guess is that this functionality was implemented by either CMDIFrameWnd or SECMDIFrameWnd but I couldn't find a reference to it in the documentation. Does anyone know how I can get this functionality back.
First thing I'd do is create a new MDI application with the ClassWizard and check if the functionality you're missing is present. If so, poke around and see if you can tell what's different. One place to look may be the menu resource for the main menu.
If there is no in-built functionality to provide what you need, you can dynamically build the menu with the following pseudocode:
foreach registered CDocumentTemplate
foreach document
foreach view
{
if (numberOfWindowMenuItems < 5)
{
Add menu item
}
else
{
Add "Windows..." menu item
break all loops;
}