Displaying the preferred accelerator in MFC feature pack menus and tooltips - c++

We have converted an existing MFC application to use the MFC Feature Pack, retaining menus and toolbars rather than ribbons. It has two shortcuts defined in the accelerator resources for Cut, Ctrl+X and Shift+Delete. The older version of the program advertises the preferred shortcut of Ctrl+X in the second column of the menu and in brackets at the end of the tooltip for the toolbar icon. The feature pack, however, sets these up for itself by calling CKeyboardManager::FindDefaultAccelerator(), which returns Shift+Delete.
Is there a way to set up the accelerator resources so that the program displays the preferred shortcut, or some other way?

Related

Can Power BI custom visuals accept keyboard focus?

I am trying to create a custom slicer that supports keyboard navigation.
I have come across the supportsKeyboardFocus property in capabilities.json, and I see that this changes the visual HTML element to look like the built in slicer which does support keyboard navigation (removes aria-hidden="true" and adds keyboard-shortcuts="ctrl-ArrowRight scoped") but am still unable to get keyboard focus inside a simple custom visual. Are there any working examples of a custom visual that supports keyboard navigation?
There was a regression in custom visuals' keyboard focus support, it has been fixed a few months ago.
In order to enable keyboard focus and navigation, the visual should:
Set supportsKeyboardFocus: true in capabilities.json file.
Contain focusable elements1
Also note that in a Power BI report, visuals behave as context groups, so navigation between visuals is achieved using Tab, and navigation into a visual's context is done by ctrl+rightArrow (or cmd+rightArrow for Apple).
1: While there are many DOM elements which are focusable by default (e.g. buttons, text input etc.), many custom visuals are based purely on SVG graphics, so they can end up with no focusable elements. For the most basic tab based navigation, adding tabindex=0 to an element is enough. For good accessibility, depending on the visual, it's typically required to add keyboard support for selection and multi-selection, and better navigation (e.g. arrow based grid navigation, or some reasonable grouping of elements etc.)

Disabling a ComboBox item in Win32 API

I would like to disable an item in a combobox in my Win32 application (C++). I'm not quite sure how to do this. I'm trying to achieve something that looks like this:
Notice how CollectionItem2 and 3 are greyed-out.
Any help would be very much appreciated!
If you truly need a combobox for this, then (as #IInspectable said) you'll need to do a custom drawn control. Basically, you'll have to store some information saying which items are disabled/grayed, and draw the items appropriately based on whether they're enabled or not.
There may be a somewhat easier way though. This is normally done with a Split Button. This is button with the BS_SPLITBUTTON style set. When the drop-down part of the button is clicked, it sends a BCN_DROPDOWN notification.
You normally respond to that by displaying a menu, typically using TrackPopupMenu to display it immediately below the button (or immediately to its right, if you prefer). This is a normal menu, so it can have items enabled, disabled, grayed, have check boxes, etc., as you see fit.
If you're using MFC, it has a CSplitButton class that wraps the Split Button, simplifying the code a little bit--you can pass an identifier of a menu and sub-menu when you create the CSplitButton object, and it handles things from there.
A sample result probably looks pretty familiar:
Note: MFC also has a CMfcMenuButton class. This has roughly similar functionality, but is somewhat clumsier to use. If memory serves, it is compatible with older versions of Windows (but the split button goes back to Vista, so it's fine unless you really need to support XP).

Qt on macOS: display two keyboard shortcuts for one menu item

I'm writing an app using Qt 5 on macOS, and I'd like to find a way to display more than one keyboard shortcut for a menu item. It's not necessary for either shortcuts to actually work as I'm utilizing a different mechanism for triggering the shortcuts than the usual method with QAction. I just want both shortcuts to be displayed in the menu. Something like:
I've tried using QAction::setKeyboardShortcuts, but only the first shortcut is displayed.
I've also tried using a facility of QAction where you specify a shortcut in its text using a tab character (e.g. "Throw Party\tCtrl+P"), but adding more than one shortcut (e.g. "Throw Party\tCtrl+P Ctrl+Alt+A") results in none being displayed at all, unless they're separated by a comma, in which case a) they display with buggy formatting, and b) it implies that it's one shortcut that requires two consecutive keystrokes, rather than two separate shortcuts.

How to add or remove textboxes by changing the options in the combobox in Visual c++?

I want to know that whether I can add a textbox or label by changing the options in combo box. For example, I have 2 options in Combobox. If I choose the #1, it must show me 2 textboxes, but if I choose #2 it must show 3 textboxes.Can I do something like this in Visual Studio C++?
This can be done in two ways:
Dynamically create and destroy the edit controls using CreateWindowEx and DestroyWindow.
Statically create your GUI with 3 edit controls and set the visibility of the controls based on the selection using ShowWindow.
Have as many text-boxes you want. But hide them.
Handle CBN_SELCHANGE (ON_CBN_SEL_CHANGE in MFC).
In the handler, show (or hide) the text boxes depending on selection.
Showing/hiding text boxes aren't good from UI perspective. You better enable/disable them appropriately. You may put alternate text when they are disabled, and bring back original change when they have to be enabled.
Creating textboxes at runtime, and then deleting them isn't' good approach. You will need to keep track of Win32 UI handle and/or MFC object. This approach will also need more of UI resource creation/deletion, parent-child relationship handling et. al.

Modifying a ribbon control at runtime

I'm using the Windows Ribbon Framework in an unmanaged C++ application in Visual Studio.
Is it possible to add a button or other control at runtime? I can set up my ribbon using IUIFramework::LoadUI, but I can't modify it afterwards.
It is not possible to add or remove a button at runtime, but you may hide or show a Tab or Group at run time using Application Modes and you can set any button texts and images at runtime.
So you can declare and use multi-purpose buttons that will show only when a specific Application Mode is set and contain runtime defined texts and images.
You can switch modes at runtime depending on what is defined in the markup - see here for details:
After modes are defined in markup,
they can be easily enabled or disabled
in response to contextual events. As
mentioned previously, Ribbon
applications always start in the
default mode 0. After the application
has initialized and mode 0 is active,
the set of active modes can be changed
by calling the IUIFramework::SetModes
function.
There is a comment here to the effect that changes at runtime are quite limited - this is in regard to a third-party wrapper, note.
You can dynamically add items at
runtime only to the galleries
controls:
ComboBox, SplitButtonGallerty,
DropDownGallery and InRibbonGallery
If you know what you want to add from
advance you can use ContextualTabs and
ApplicationModes to change the
visibility of (predefined) tabs and
groups.
Unfortunately, you can add dynamically
groups at runtime.
Note this is a limitation in the
Windows Ribbon Framework and not in
the wrapper library.