How to Get a pointer to MFC Ribbon ComboBox - visual-c++

I'm developing an MFC Ribbon application on visual studio 2013 and I'm new in MFC developement.
I've added MFC Ribbon ComboBox from designer window. Now, I want to add data runtime into MFC Ribbon ComboBox, I've done google & read MSDN as well as Code Project example regarding MFC Ribbon. but, I was unable to figured how to get pointer to combobox and add data into it.

You can use CMFCRibbonBar::FindByID. So, something like this:
CMFCRibbonComboBox *pCombo = DYNAMIC_DOWNCAST(CMFCRibbonComboBox,
m_wndRibbonBar.FindByID(ID_COMBO1));
The ID you use (in the above example ID_COMBO1) is the ID you gave it in the Properties window in the ribbon designer, and m_wndRibbonBar is the member variable of the ribbon itself, which is usually auto-generated in your CMainFrm class.

Related

How can I change toolbar runtime in MFC Visual C++ 2010

I have two toolbars desgined of equal size and equal number of buttons.
Now based on some condition in code I want to change toolbars run time.
My prject is MDI application built in Visual C++2010 MFC.
Please help as early as possible.My application uses CMFCToolbar
If you are using CMFCToolbar you can just call: CMFCToolbar::GetCommandButtons (a static function). You get an Object array of all buttons in your system and you can change them accordingly (SetToolTip, SetImage ...)
The problem is that CMFCToolbar is variable and buttons can be inserted and dragged around. SO you need the access via GetCommandButons.
If you are using the classical CToolBar class the easiest way is just to add the button, so it always exists in the toolbar and in the bitmap.
If the button should not be visible at startup you just call DeleteButton with the index you receive from CommandToIndex.
To change the button you can just use SetButtonInfo.
If you need the button again, just call InsertButton, with the index where you want to have this button.You may save the previous index and used bitmap index before you delete it.

Excel VBA - Intercept AddIn Ribbon Click

i would like to know if it is possible to intercept the event generated by the Ribbon Button of an Excel Addin. I'm able to access to the .xlam source but seems there is no code in it that intercept that event, so I think the handler is in the compiled component. Is my assessment correct? And then, if yes, can I intercept a click on a button of the ribbon, maybe using an Application Level Handler?
Thank you,
DD
The Ribbon button has a callback assigned to its onAction attribute - it will be a Sub in the addin that has an iribboncontrol parameter (or similar). If you have can view the customui part of the add-in's XML you will be able to determine exactly which callback is relevant.

Catastrophic failure (Exception from HRESULT: 0x8000FFFF (E_UNEXPECTED)): ActiveX and C# Console Application

So, I am playing around with ActiveX and C# and ways how both of them can work together. the thing is I have hit the wall right in the beginning with mentioned error. Steps I have followed:
In VS2010 I selected MFC ActiveX Control project. Then I added a method "SHORT Multiply( SHORT a, SHORT b);" by clicking the Add method option in the menu that pops when you right click _DProjectname under ProjectnameLib in solution explorer. The code for the method is as follows:
SHORT CSampleProgramActivex01Ctrl::Multiply(SHORT a, SHORT b)
{
AFX_MANAGE_STATE(AfxGetStaticModuleState());
// TODO: Add your dispatch handler code here
return ( a * b);
}
Now I have created a simple C# console application that references the generated COM file and when I try to use the method, the application stops with the above mentioned error. I have searched the error on the internet but no clear solution is mentioned. Any help appreciated. If you guys want clarification, let me know.
I don't know whether this is considered as solving the problem or not but I found a workaround:
First instead of C# console application, I created C# windows form application. After creating the form, I have added the whole ocx as component in the toolbox. You do this by right-clicking the Toolbox types in Toolbox menu. In the new menu, you click Choose Items. This pops up new menu and in that select the COM tab and in that check your COM component and the COM component will be added to the Toolbox menu. Now drag and drop the component on the menu and you should be good to go.
This seems to be workaround that everybody is following. Not neat but that is the norm I think.
look at here: How to use an OLE control as an automation server in Visual C++
http://support.microsoft.com/kb/146120/en-us

Accessing Ribbon Controls Programatically in an XML Ribbon

For programming Office Add-ins using C# 4.0, Microsoft provides two different ways of creating and/or modifying the Ribbon interface: you can use the Ribbon Designer or define the Ribbon's layout in Ribbon XML.
If you create a ribbon using the Ribbon designer, the class generated in the code behind has visibility to all the controls you've placed on the ribbon. So if I've placed a RibbonDropDown called "dropdown1", I could use the following code to add an item to it:
RibbonDropDownItem item = Factory.CreateRibbonDropDownItem();
item.Label = submatrix.Name;
item.Tag = submatrix;
this.dropDown1.Items.Add(item);
However, if you create the same Ribbon using Ribbon XML, dropDown1 or Factory aren't found ("The name does not exist in the current context").
Is there a way to access the items added to a Ribbon XML-defined ribbon in code?
Might be a little late, but hopefully this helps someone.
I was utterly confused about this same issue. Turns out, you can only access these controls as string ids, and the model is heavy on invalidation events. So for example, when you get a button click via onAction method, you only have the sender's id from the control object, however, in this event handler, you can invalidate the other controls and have their events called using
ribbon.InvalidateControl("MyCtl");
check out this MS Lab, it has everything you need to get up and running

VC++ and MapPoint OCX control dialog issue

I am writing a VC++ MFC dialog based app which requires Microsoft MapPoint embedding in it. To do this I'm using MS VC++ .NET 2003 and MapPoint Europe 2006 to do this but am having problems as when I select "Insert ActiveX Control" no MapPoint control appears in the list of options. I have tried manually registering mappointcontrol.ocx with regsvr32 which appears to succeed but still the control doesn't appear on the list.
Can anyone suggest what I am doing wrong here, and any possible solutions.
Thanks
Ian
Have you tried using the ActiveX control test container? Is it in the list of controls? How about using the register button in the test container?
Also check the registry to see if it is registered. You should have an entry in HKEY-CLASSES-ROOT\controlName that has a CLSID element that points to a UUID. That UUID should also be in HKEY-CLASSES-ROOT\CLSID\uuid and have a LocalServer32 entry that points to the DLL and ProgID that points back to controlName.
I have now got the Mappoint control working but in a slightly different way. The control does appear on the list of controls the test container can use. I have tried reregistering it and unregistering it but still it doesn't appear on the list of controls when I try a "Insert ActiveX Control". However if I use "Add/Remove Toolbox Items" I can add it to the toolbox and then drag it into my app where it works fine. I'm not sure why this method works but it does and I can get on with my coding.
Many thanks for all your help with this.

Resources