I need to go a little beyond the standard MFC handling of enabling and disabling a toolbar item. That part works and is great. But I have a CTreeView where I need to also enable/disable a toolbar item based on what is selected on the tree view. I can get the CMainFrame pointer via AfxGetMainWnd() but the m_wndToolBar in inaccessible.
What is the recommended way to handle this in MFC?
TIA!!
One of solutions is to simply add GetMyToolbar public method to your CMainFrame class, that will return the pointer to m_wndToolBar.
CMFCToolBar* CMainFrame::GetMyToolbar()
{
return &m_wndToolBar;
}
Related
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
I'm trying to display a ToolTip for a CStatic derived control in my dialog.
What I've already done:
Added a CMFCToolTipCtrl item to my CDialogEx member.
In the init dialog member I've specified CMFCToolTipInfo structure and passed it as argument in CMFCToolTipCtrl item constructor.
Call the EnableToolTips(); member for my CStaticExts and for my CDialogEx.
Overrided the PreTranslateMessage of my CDialogEx adding the "RelayEvent".
Set "Notify: TRUE" in the resource editor.
Doing so I managed to display the tooltip in a partially customized way (baloon and background color) but now I would like to enlarge the font, make it bold and, eventually, display an icon, similarly to the tool tips I can see on my toolbar.
I already tried calling "SetFont" and "SetIcon" methods for the CMFCToolTipCtrl item but it didn't work.
Is that possible?
The normal Font that is used in CMFCToolTipCtrl ist retrieved from a global data store inside the MFC (see GetGlobalData()->fontTooltip). This data structure AFX_GLOBAL_DATA is filled when the MFC is started. SetFont has no effect here.
If you want to change the behaviour you have to create your own CMFCToolTipCtrl class and overwrite OnDrawLabel. You have the source of the MFC so it is easy to provide your own implementation.
I would like to update the ribbon from the CDocument derived class because the information relevant for ribbon's status is stored there. The was created by the Wizard and edited in resource manager
Some elements (Buttons, checkboxes) can be updated with ON_UPDATE_COMMAND_UI macro.
But I have a headache with update other things like CMFCRibbonComboBox or CMFCRibbonProgressBar because CCmdUI doesn't provide suitable functions to deal with them (ie AddItem)
Other option using GetDlgItem doesn't work, because neither CDocument nor RibbonBar elements are derived from CWnd.
So what is the way to update CMFCRibbonComboBox and others?
I faced a similar problem with combo boxes on a toolbar. The combo box was used to display the current mouse coordinates of a point in "world coordinate" space while the mouse was moved. I derived my own class for the combo and exposed some methods that would update its contents. I then picked the most appropriate point in the code to make the appropriate calls to those methods. That may be during the paint cycle (eg. OnDraw), or, during idle time. A similar approach of deriving and exposing methods should work for you. The only caveat is to pick the correct location to inject your calls to perform the update.
I first tried RogerRowland's solution, but it soon became annoying to add a function to MainFrame for every trifle , then to call AfxGetMainWnd() from document and apply static_cast on it.
Instead I now store pointers to the ProgressBar and the combobox inside the document. I added the methods to CMainFrame to get them and removed the rest.
The only dificulty with it is the fact that the document is constructed before the main window. So I have to delay the initialisation of the mentioned pointers. I solved it by adding setRibbonBarPointers() to the document and calling it from OnInitialUpdate() of the view
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!
I am developing an MFC application, can i use SHAutoComplete with a CEdit control? Also is there any ready made auto complete controls are available? or i need to use write all the code for creating the list box below the edit control as user types in edit control?
Just pass CEdit's m_hwnd member to SHAutoComplete. I don't think that extension warrant another class. The listbox is created by the AutoComplete object created by SHAutoComplete.
SHAutoComplete helps to autocomplete paths (system or URL).
If this is a combo box and you want to use autocomplete for suggesting string contained in the combo, you have to write a code to handle it.
There are samples you can find. One I found (working):
http://www.ucancode.net/Visual_C_MFC_COM_faq/Visual-C-Auto-completion-ComboBox-CComboBox.htm