-
Notifications
You must be signed in to change notification settings - Fork 1
Basic Ribbon Wrapper
We will start looking at some code.
Creating .NET wrappers The first thing needed for using WinForms-Ribbon from .NET is converting the C++ / COM definitions to C# ones. The conversions are done mainly by Microsoft CsWin32 project. I only have to define the needed COM-interfaces and other native methods to the files NativeMethods.txt and NativeMethods.json
The files relevant to Ribbon are: UIRibbon.idl, UIRibbonKeydef.h and UIRibbonPropertyHelpers.h. Note that UIRibbon.h is not interesting since it is auto-generated from UIRibbon.idl by the MIDL compiler. All these files are installed with Windows 7 SDK or a later Windows SDK.
How does the Windows Ribbon Framework work? The full details are provided in MSDN, which I recommend reading. Here I’ll only give a short overview so we are all on the same page.
To initialize a ribbon in your application you need to do the following:
-
Design your ribbon appearance using XAML-like markup (Can be done with RibbonTools64).
-
Compile your XAML-like markup using Microsoft Ribbon Markup Compile, provided with Windows 7 SDK (Can be done with RibbonTools64).
-
Have the binary output of the markup compiler stored as a (unmanaged) resource of your application.
-
On application load, CoCreateInstance the UIRibbonFramework class which implements IUIFramework interface.
-
Call IUIFramework.Initialize and pass it a reference to your implementation of the IUIApplication interface along with the HWND of your application window.
-
The IUIApplication interface supply a callback for the ribbon framework to call when it needs a command handler, for handling commands (represented as buttons, combos and the other usual controls).
-
Call IUIFramework.LoadUI which loads the pre-compiled resource and shows the actual ribbon.
What have I done, up until now?
In order to facilitate the use of the ribbon within .NET applications we will create a class that will be used as a façade for the Windows Ribbon Framework. RibbonStrip class is able to support applications with one or more ribbons on different forms. This class, named RibbonStrip, will be in charge of initialization and communication with the Windows Ribbon Framework.
The RibbonStrip class will provide an implementation of IUIApplication and handle all the COM details. The RibbonStrip class is derived from the System.Windows.Forms.Control class and handle the steps 4 to 7 written before. The RibbonStrip must be placed to a Windows Form directly with Top docking. The binary markup must be set to Embedded Resource and a reference must be set to RibbonStrip property MarkupResource.
The idea is to have your application provide only the minimal required details for the ribbon to work.
The RibbonStrip class currently exposes 2 methods, which are handled internally:
-
InitFramework – receives the markup resource that will be used to load the ribbon configuration.
-
DestroyFramework – cleanup code, free Windows Ribbon Framework resources.
These methods are called by the RibbonStrip class when the handle is created and destroyed, respectively.
Summary
I’ve put the library code RibbonFramework on Github along with some sample applications that uses the code to create a simple WinForms application with Ribbon support.
On my next post I’ll provide simple details on how to build your first WinForms Ribbon application using what we’ve developed so far.
-
Basics
- Introduction, Background on the windows ribbon framework
- Basic Ribbon Wrapper ; Basic .NET wrappers for windows ribbon framework.
- Quickstart Tutorial
- First WinForms Ribbon Application ; How to create an empty WinForms application with ribbon support.
-
RibbonFramework Controls
- RibbonStrip ; Main class, derived from System.Windows.Forms.Control
- RibbonApplicationMenu
- RibbonButton
- RibbonCheckBox
- RibbonComboBox
- RibbonDropDownButton
- RibbonDropDownColorPicker
- RibbonDropDownGallery
- RibbonFontControl
- RibbonGroup
- RibbonHelpButton
- RibbonInRibbonGallery
- RibbonMenuGroup
- RibbonQuickAccessToolbar
- RibbonRecentItems
- RibbonSpinner
- RibbonSplitButton
- RibbonSplitButtonGallery
- RibbonTab
- RibbonTabGroup
- RibbonToggleButton
-
RibbonFramework EventArgs classes
-
RibbonFramework PropertySet classes
-
RibbonFramework classes, interfaces, enums
-
RibbonFramework features
-
RibbonFramework Samples
- ApplicationMenu with Buttons ; How to use the ribbon application menu.
- ApplicationMenu with SplitButton and DropDownButton ; How to use the ribbon application menu with ribbon split button and ribbon dropdown button controls.
- Tabs, Groups and HelpButton ; How to use ribbon tabs, groups and the ribbon help button control.
- Spinner ; How to use the ribbon spinner control.
- ComboBox ; How to use the ribbon combo box control.
- Changing Ribbon Colors ; How to change the ribbon colors.
- Working with Images ; How to work with images in the ribbon.
- DropDownGallery, SplitButtonGallery and InRibbonGallery ; How to use the ribbon drop down gallery, split button gallery and in ribbon gallery controls.
- CheckBox and ToggleButton ; How to use the ribbon check box and toggle button controls.
- DropDownColorPicker ; How to use the ribbon drop down color picker control.
- FontControl ; How to use the ribbon font control.
- ApplicationModes ; How to work with ribbon application modes.
- ContextualTabs ; How to work with ribbon contextual tabs.
- ContextPopup ; How to work with ribbon context popup.
- RecentItems ; How to work with ribbon recent items control.
- QuickAccessToolbar ; How to work with the ribbon quick access toolbar.
- SizeDefinition ; How to define custom size definitions for ribbon group elements.
- Localization ; How to localize a ribbon.
-
RibbonTools
- RibbonTools64 ; Development support for creating markup files for the Ribbon framework.
- Create a new project ; Create a WordPad sample project
- Specifying Ribbon Commands
- Designing Ribbon Views
- Preview the Ribbon
- Wrapper class RibbonItems ; An auto generated wrapper class from the ribbon markup.
- Convert Image to ARGB Bitmap
-
How to ...