Windows Ribbon for WinForms, Part 3 – First WinForms Ribbon Application

15 בספטמבר 2009

So let's see how to use the Ribbon class to add ribbon support to an empty WinForms application.

Step 0 – Download Windows Ribbon for WinForms
As I’ve mentioned in previous posts, you can download the code for my ribbon wrapper library along with numerous samples (currently one..) from windowsribbon.codeplex.com
Also, I remind you to download the helper library, Windows API Code Pack.
Update (18.11.2009): The project doesn’t depends anymore on Windows API Code Pack.

In this post I'll review how to create your first, ribbon-enabled WinForms application, the result is the sample application “01-AddingRibbonSupport”, included on the site.

Step 1 – Reference Windows Ribbon for WinForms
Create a new C# WinForms application and add a reference to our developed library, Ribbon.dll

Also, add to your main form (form1.cs) the following lines:

using RibbonLib;
using RibbonLib.Interop;

 
public partial class Form1 : Form, IRibbonForm
{
    private Ribbon _ribbon = new Ribbon();
    …

Step 2 – Add ribbon markup XML file
Add an empty file named RibbonMarkup.xml to the project
Set the file text to the following:

<?xml version='1.0' encoding='utf-8'?>
<Application xmlns='http://schemas.microsoft.com/windows/2009/Ribbon'>
  <Application.Commands>
  </Application.Commands>

  <Application.Views>
    <Ribbon>
    </Ribbon>
  </Application.Views>
</Application>

Right click on the editor where RibbonMarkup.xml is opened and click properties, now set the Schemas property to: C:\Program Files\Microsoft SDKs\Windows\v7.0\Bin\UICC.xsd
This will [visual] assist you in the future while editing the ribbon markup file (try Ctrl+Space on the xml editor to see the ribbon markup syntax).

Note: this is the moment where some of you will discover they didn’t install Windows 7 SDK, so go ahead and fix it, I'll wait.

Step 3 – Set UI compiler to compile markup during build

Step 3.1 – Set pre-build events

Go to: Project Properties -> Build Events -> Pre-build event command line
Add the following 3 lines:

"%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\UICC.exe" "$(ProjectDir)RibbonMarkup.xml" "$(ProjectDir)RibbonMarkup.bml" /res:"$(ProjectDir)RibbonMarkup.rc"

"%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\rc.exe" /v "$(ProjectDir)RibbonMarkup.rc"

cmd /c "("$(DevEnvDir)..\..\VC\bin\vcvars32.bat") && ("$(DevEnvDir)..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"$(ProjectDir)$(OutDir)$(TargetName).ribbon.dll" "$(ProjectDir)RibbonMarkup.res")"

image

Explanation:
The first line compiles the ribbon markup file to a binary compressed format, along with a small RC file that describes it.
The second line creates a native win32 resource file to be attached to the project native resources.
The third line creates a resource dll from the native win32 resource file.

Step 3.2 – Compile

Compile, in order to invoke the pre-build events.

Update (18.11.2009): Step 3.3 is no longer needed since the resource is loaded from the resource dll.

Step 3.3 – Add native resource

Go to: Project Properties -> Application -> Resources -> Resource File
Set Resource file to point to:
RibbonMarkup.res
When it says it can’t find the file, close the properties window anyway. It will save and find the file.
If you wish to be on the safe side, just set the Resource file to the full path of the file (which is dependent on your project location).

image

Step 4 – Implement IRibbonForm
Have your main form implement IRibbonForm interface, which is defined in Ribbon.dll, you can follow the following guidelines:

  • The Ribbon framework needs the main form window handle for initialization, hence:
public IntPtr WindowHandle
{
    get
    {
        return this.Handle;
    }
}

  • The Ribbon framework will partly hide your form, unless you write some code that repositions your controls according to the ribbon current height. A simple way of doing this is adding a SplitContainer control to the main form and setting the following properties: (you should change them using the GUI properties, not by code):
this.splitContainer1.Dock = System.Windows.Forms.DockStyle.Fill;
this.splitContainer1.FixedPanel = System.Windows.Forms.FixedPanel.Panel1;
this.splitContainer1.IsSplitterFixed = true;
this.splitContainer1.Orientation = System.Windows.Forms.Orientation.Horizontal;
this.splitContainer1.SplitterWidth = 1;

Now, all you need to do is put your form controls inside panel2 of the SplitContainer and update panel1 height when the ribbon height changes (panel1 act as a placeholder for the ribbon). The SplitContainer will automatically reposition your controls accordingly. The actual update is done in the IRibbonForm implementation:

public void RibbonHeightUpdated(int newHeight)
{
    this.splitContainer1.SplitterDistance = newHeight;
}

  • The major part of the communication between the ribbon framework and your application is done by implementing the two following methods, which we’ll initially give a default implementation:
    Update (18.11.2009): These functions should not be implemented by the user anymore, since the Ribbon class now provides a general implementation, thus simplifying the use of the library.
public HRESULT Execute(uint commandId, ExecutionVerb verb, PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
{
    return HRESULT.S_OK;
}

public HRESULT UpdateProperty(uint commandId, ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
{
    return HRESULT.S_OK;
}

Step 5 – Initialize Ribbon Framework on application load

To initialize and destroy the ribbon framework, handle both form’s Load and FormClosed events, respectively:

private void Form1_Load(object sender, EventArgs e)
{
    _ribbon.InitFramework(this);
}

private void Form1_FormClosed(object sender, FormClosedEventArgs e)
{
    _ribbon.DestroyFramework();
}

Enjoy your first Ribbon WinForms application

image

Note: If you run your application and don’t see the ribbon, try to enlarge the window size. The windows ribbon has a feature that if the window size is too small, it doesn’t show. Unfortunately, Visual Studio default form size is too small.

That’s it for now,
Arik Poznanski.

kick it on DotNetKicks.com Shout it

הוסף תגובה
facebook linkedin twitter email

כתיבת תגובה

האימייל לא יוצג באתר. (*) שדות חובה מסומנים

31 תגובות

  1. [d3m0n]17 בנובמבר 2009 ב 1:02

    I'm using VS2010 and I had build errors with the sample projects, so I followed the steps on this page. I got it to work eventually but only after adding a declaration for _ribbon. You need to add this to your form's code:

    public partial class Form1 : Form, IRibbonForm
    {
    private Ribbon _ribbon = new Ribbon();

    להגיב
  2. arik17 בנובמבר 2009 ב 1:31

    I've updated step 1 to reflect you correct comment.

    The samples on the project site should compile without any problems. (provided that you installed Windows 7 SDK). If this is not he case, please let me know.

    להגיב
  3. [d3m0n]17 בנובמבר 2009 ב 2:00

    > If this is not he case, please let me know.
    They don't work for me. If I try to build sample project "01-AddingRibbonSupport", I get these two dialogs:

    "ResXtoResources.exe has stopped working"

    "Microsoft .NET Error Reporting Shim has stopped working"

    and then after a while, this one:

    ResGen.exe – Application Error
    —————————
    Application has generated an exception that could not be handled.
    Process ID=0×1138 (4408), Thread ID=0×1168 (4456).

    Here's the build log:

    —— Build started: Project: Ribbon, Configuration: Debug Any CPU ——
    Build started 16/11/2009 23:49:27.
    CopyFilesToOutputDirectory:
    Ribbon -> D:\Visual Studio 2010\Projects\RibbonComponent\Ribbon\bin\Debug\Ribbon.dll

    Build succeeded.

    Time Elapsed 00:00:00.07
    —— Build started: Project: 01-AddingRibbonSupport, Configuration: Debug Any CPU ——
    Build started 16/11/2009 23:49:27.
    PreBuildEvent:
    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\UICC.exe" "D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.xml" "D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.bml" /header:"D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkupIds.h" /res:"D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.rc"
    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\rc.exe" /r "D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.rc"

    D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.xml(8): warning SC2002: Undefined property: 'ApplicationMenu'. Using default value.
    D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.xml(8): warning SC2002: Undefined property: 'Tab'. Using default value.
    D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.xml(8): warning SC2002: Undefined property: 'QuickAccessToolbar'. Using default value.
    D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.xml : warning SC2001 at /Application/Application.Views/Ribbon/Ribbon.ApplicationMenu/ApplicationMenu: Undefined Command on element.
    D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.xml : warning SC2001 at /Application/Application.Views/Ribbon/Ribbon.Tabs/Tab: Undefined Command on element.
    Header file generation successful: 'D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkupIds.h'.
    Ribbon markup file validation successful: 'D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.xml'.
    Ribbon resource file generation successful: 'D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\RibbonMarkup.rc'.
    Microsoft (R) Windows (R) Resource Compiler Version 6.1.7600.16385

    Copyright (C) Microsoft Corporation. All rights reserved.

    CoreResGen:
    C:\Windows\Microsoft.NET\Framework64\v4.0.21006\Tracker.exe /i "D:\Visual Studio 2010\Projects\RibbonComponent\Samples\01-AddingRibbonSupport\obj\Debug" /r "D:\VISUAL STUDIO 2010\PROJECTS\RIBBONCOMPONENT\SAMPLES\01-ADDINGRIBBONSUPPORT\FORM1.RESX|D:\VISUAL STUDIO 2010\PROJECTS\RIBBONCOMPONENT\SAMPLES\01-ADDINGRIBBONSUPPORT\PROPERTIES\RESOURCES.RESX" /c "C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin\ResGen.exe" /useSourcePath /r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\mscorlib.dll /r:"D:\Visual Studio 2010\Projects\RibbonComponent\Ribbon\bin\Debug\Ribbon.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Deployment.dll /r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Drawing.dll /r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Windows.Forms.dll /r:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /r:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /compile Form1.resx,obj\Debug\_01_AddingRibbonSupport.Form1.resources Properties\Resources.resx,obj\Debug\_01_AddingRibbonSupport.Properties.Resources.resources
    C:\Windows\Microsoft.NET\Framework\v4.0.21006\Microsoft.Common.targets(1754,9): error MSB6006: "ResGen.exe" exited with code -1073741819.

    Build FAILED.

    Time Elapsed 00:02:33.66
    ========== Build: 1 succeeded or up-to-date, 1 failed, 0 skipped ==========

    This is on Win7 Home Premium 64-bit, with VS2010 Ultimate Beta 2, and the AMD64 version of Win7 SDK. BTW Win7SDK is installed to C:\Program Files (x86)\Microsoft SDKs\Windows\….

    I have tried reinstalling VS and the SDK and getting a fresh copy of the RibbonLib but it still happens.

    Weirdly the project I created myself using this page worked fine :)

    If you could shed any light I would be grateful. I have already logged a connect ticket here: http://www.connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=510837

    Thanks.

    להגיב
  4. arik17 בנובמבר 2009 ב 10:12

    Probably it is related to your environment, 64bit with .NET 4.0.
    Unfortunately I can't test this scenario.
    Let me know if you managed to understand what the difference between the projects you have created and the ones in the samples folder.

    להגיב
  5. [d3m0n]18 בנובמבר 2009 ב 0:38

    I finally figured out what was different – the sample targets .NET framework 3.5, and my new project targets ".NET Framework 4 Client Profile".

    I changed the sample to target .NET 4 Client Profile and it works! Now I can play :D

    Cheers

    להגיב
  6. arik18 בנובמבר 2009 ב 1:12

    Glad to hear that.

    Note that I just released an important update to the ribbon library.
    Check this post for more details: http://blogs.microsoft.co.il/blogs/arik/archive/2009/11/18/windows-ribbon-for-winforms-part-15-use-ribbon-as-external-dll.aspx

    להגיב
  7. Rogelio31 בדצמבר 2009 ב 1:38

    I did try to use the sample but i get this error when compiling:

    The command ""%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\UICC.exe" "C:\RogelioRR\Personal\Development\CNET\Samples\EjemploRibbon\RibbonSample\RibbonSample\RibbonMarkup.xml" "C:\RogelioRR\Personal\Development\CNET\Samples\EjemploRibbon\RibbonSample\RibbonSample\RibbonMarkup.bml" /res:"C:\RogelioRR\Personal\Development\CNET\Samples\EjemploRibbon\RibbonSample\RibbonSample\RibbonMarkup.rc"
    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\rc.exe" /v "C:\RogelioRR\Personal\Development\CNET\Samples\EjemploRibbon\RibbonSample\RibbonSample\RibbonMarkup.rc"
    cmd /c "("C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\..\..\VC\bin\vcvars32.bat") && ("C:\Program Files\Microsoft Visual Studio 10.0\Common7\IDE\..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"C:\RogelioRR\Personal\Development\CNET\Samples\EjemploRibbon\RibbonSample\RibbonSample\bin\Debug\RibbonSample.ribbon.dll" "C:\RogelioRR\Personal\Development\CNET\Samples\EjemploRibbon\RibbonSample\RibbonSample\RibbonMarkup.res")"" exited with code 1.

    What am i doing wrong?

    להגיב
  8. arik31 בדצמבר 2009 ב 9:07

    Try to run the pre build commands from cmd. You often get more information there on the exact problem.

    You don't happen to run on a 64bit system?
    If so, let me know, this may be related to the use of "%PROGRAMFILES%" environment variable.

    להגיב
  9. Rogelio5 בינואר 2010 ב 17:42

    Thank you arik, i solved the problem. The problem was that i didn't install Visual C++, so, the compiler wasn't able to find the "vcvars32.bat" file. Now, it works fine. Thank you again and congratulations for this cool control :)

    להגיב
  10. Fullmetal9901226 בינואר 2010 ב 4:23

    I cannot get the ribbon to show up on the form. I have the form size set to full screen resolution which is 1280×800, and yet it still doesnt show, whats wrong with my app

    the code is as follows

    public partial class Form1 : Form, IRibbonForm
    {
    private Ribbon _ribbon = new Ribbon();
    public IntPtr WindowHandle
    {
    get
    {
    return this.Handle;
    }
    }

    public Form1()
    {
    InitializeComponent();
    }

    public void RibbonHeightUpdated(int newHeight)
    {

    }
    private void Form1_Load(object sender, EventArgs e)
    {
    _ribbon.InitFramework(this);
    _ribbon.Viewable = true;
    if (UserConfig.Default.FirstRun == true)
    {
    if (File.Exists(Environment.CurrentDirectory + "/Backup/Windows 7 Features 2.exe.config"))
    {
    File.Copy(Environment.CurrentDirectory + "/Backup/Windows 7 Features 2.exe.config", Environment.CurrentDirectory + "/Windows 7 Features 2.exe.config",true);
    MessageBox.Show("Settings have been restored", "Settings Restored");
    UserConfig.Default.FirstRun = false;
    UserConfig.Default.Save();
    }
    else
    {
    UserConfig.Default.FirstRun = false;
    UserConfig.Default.Save();
    }
    }
    }
    Updater updateform = null;
    private void checkForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
    {
    updateform = new Updater();
    updateform.UpdateCheck();
    }

    private void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
    _ribbon.DestroyFramework();
    }
    }
    }

    להגיב
  11. arik31 בינואר 2010 ב 0:47

    Fullmetal99012, the code seems OK.
    For further investigation, you will have to supply more details than that.
    If you want, you can send me a small project and I'll check it.
    Otherwise, you can check the samples on the project site and try to figure out what the differences. The samples should work without a change.

    להגיב
  12. Yahav28 בפברואר 2010 ב 13:24

    im also having some problems.. :

    Error 1 cannot open input file 'C:\Users\Yahav\Documents\Visual Studio 10\Projects\ribbontest\ribbontest\RibbonMarkup.res' C:\Users\Yahav\Documents\Visual Studio 10\Projects\ribbontest\ribbontest\LINK ribbontest
    Error 2 The command ""%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\UICC.exe" "C:\Users\Yahav\Documents\Visual Studio 10\Projects\ribbontest\ribbontest\RibbonMarkup.xml" "C:\Users\Yahav\Documents\Visual Studio 10\Projects\ribbontest\ribbontest\RibbonMarkup.bml" /res:"C:\Users\Yahav\Documents\Visual Studio 10\Projects\ribbontest\ribbontest\RibbonMarkup.rc"
    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\rc.exe" /v "C:\Users\Yahav\Documents\Visual Studio 10\Projects\ribbontest\ribbontest\RibbonMarkup.rc"
    cmd /c "("D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\..\..\VC\bin\vcvars32.bat") && ("D:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE\..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"C:\Users\Yahav\Documents\Visual Studio 10\Projects\ribbontest\ribbontest\bin\Debug\ribbontest.ribbon.dll" "C:\Users\Yahav\Documents\Visual Studio 10\Projects\ribbontest\ribbontest\RibbonMarkup.res")"" exited with code 1181. ribbontest

    i do use a X64 system but i moved the whole sdk directory from Program File x86 to program files..

    להגיב
  13. arik1 במרץ 2010 ב 0:44

    Check the discussion board on windowsribbon.codeplex.com
    You need to update the build commands when working on a 64bit system.

    להגיב
  14. Jody30 באפריל 2010 ב 7:23

    I would like to impliment the ribbon not only in my main midi application, but also in newly opened windows forms, such a manager or accounting piece. These elements are distinctly separate from the main application and should be independent midi apps with their own ribbon interface.

    As the ribbon is generated in the pre-build sequence, with no reference to the RibbonMarkup.xml in the code-behind, I can't seem to figure out how to initiate the new midi form with its own xml markup file (ie. ManagerRibbonMarkup.xml and/or AccountingRibbonMarkup.xml)

    Your direction is greatly appreciated.

    להגיב
  15. Jody3 במאי 2010 ב 6:37

    I should add, this is the code I would assume is needed:

    _ribbon.InitFramework(this, "ribbonmarkup.res", "Ribbon.dll");

    But I just get the following error:

    Error HRESULT E_FAIL has been returned froma call to a COM component.

    I set this up as a test. The following works fine.

    _ribbon.InitFramework(this);

    I need clarification on exactly what strings I'm supposed to be placing in the second and third arguments.

    להגיב
  16. arik5 במאי 2010 ב 18:38

    You need to create two ribbon DLLs.
    This means you need to ribbon xml files, let's call them ribbon1.xml, ribbon2.xml

    Now in the pre-build event of the project you need to change the 3 lines there to compile ribbon1.xml instead of ribbonmarkup.xml

    Also add another 3 lines (the same lines) but change them to compile the second xml into a second DLL.

    Now in each form use _formRibbon.InitFramework(theForm, resourceName, ribbonDllName);

    resourceName should be "APPLICATION_RIBBON".
    this is the default value generated by UICC, it can be changed but I don't see why you should since you create 2 different DLLs.

    Hope this helps,
    Arik Poznanski.

    להגיב
  17. Jody6 במאי 2010 ב 7:32

    All that is done, but I'm still unclear what the "ribbonDLLName" is. I guessed at about 15 different possibilities, but I always get the same error:

    ((System.Exception)(_ribbon.Minimized)).Message
    "Object reference not set to an instance of an object."

    COMException was unhandled
    The handle is invalid. (Exception from HRESULT: 0×800700006 (E_HANDLE))

    Of course if I remove the parameters:

    _ribbon.InitFramework(this);

    it works fine. So I would guess the issue is with the third parameter at this point:

    _ribbon.InitFramework(this, "APPLICATION_RIBBON", "ribbon.dll");

    I also tried "LORibbon.res" and "LOCaseRibbon.res" for the third parameter. Do you know what that that third parameter value should be?

    Here's the entire method:

    private void LawOffice_Load(object sender, EventArgs e)
    {
    login.LawOffice = this;
    ShowScreen("login");
    this.Focus();

    string Username = Login.User;
    string FormResult = login.Result;
    if ((FormResult == "OK"))
    {
    _ribbon.InitFramework(this, "APPLICATION_RIBBON", "ribbon.dll");
    LoadRecords();
    }
    else
    {
    Application.Exit();
    }
    }

    Here's the build event script:

    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\UICC.exe" "$(ProjectDir)LORibbon.xml" "$(ProjectDir)LORibbon.bml" /res:"$(ProjectDir)LORibbon.rc"
    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\rc.exe" /v "$(ProjectDir)LORibbon.rc"
    cmd /c "("$(DevEnvDir)..\..\VC\bin\vcvars32.bat") && ("$(DevEnvDir)..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"$(ProjectDir)$(OutDir)$(TargetName).ribbon.dll" "$(ProjectDir)LORibbon.res")"

    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\UICC.exe" "$(ProjectDir)LOCaseRibbon.xml" "$(ProjectDir)LOCaseRibbon.bml" /res:"$(ProjectDir)LOCaseRibbon.rc"
    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\rc.exe" /v "$(ProjectDir)LOCaseRibbon.rc"
    cmd /c "("$(DevEnvDir)..\..\VC\bin\vcvars32.bat") && ("$(DevEnvDir)..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"$(ProjectDir)$(OutDir)$(TargetName).ribbon.dll" "$(ProjectDir)LOCaseRibbon.res")"

    להגיב
  18. arik6 במאי 2010 ב 12:52

    Change the pre buils steps to something like:

    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\UICC.exe" "$(ProjectDir)LORibbon.xml" "$(ProjectDir)LORibbon.bml" /res:"$(ProjectDir)LORibbon.rc"

    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\rc.exe" /v "$(ProjectDir)LORibbon.rc"

    cmd /c "("$(DevEnvDir)..\..\VC\bin\vcvars32.bat") && ("$(DevEnvDir)..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"$(ProjectDir)$(OutDir)LORibbon.ribbon.dll" "$(ProjectDir)LORibbon.res")"

    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\UICC.exe" "$(ProjectDir)LOCaseRibbon.xml" "$(ProjectDir)LOCaseRibbon.bml" /res:"$(ProjectDir)LOCaseRibbon.rc"

    "%PROGRAMFILES%\Microsoft SDKs\Windows\v7.0\Bin\rc.exe" /v "$(ProjectDir)LOCaseRibbon.rc"

    cmd /c "("$(DevEnvDir)..\..\VC\bin\vcvars32.bat") && ("$(DevEnvDir)..\..\VC\bin\link.exe" /VERBOSE /NOENTRY /DLL /OUT:"$(ProjectDir)$(OutDir)LOCaseRibbon.ribbon.dll" "$(ProjectDir)LOCaseRibbon.res")"

    Note that I changed $(TargetName) to an specific dll name.
    These DLL names are what you need to pass as the third to InitFramework.

    Every form should have its own ribbon class, and a call to InitFramework with the relevant DLL name.

    These DLLs comtains the ribbon resource (a compiled form of the ribbon xml)

    להגיב
  19. Jody7 במאי 2010 ב 16:04

    Most excellent! Worked great on the first try!

    להגיב
  20. Steve12 ביולי 2010 ב 23:07

    Hello Arik,

    First, thank you for your job, that's very well done.

    I make an application that uses the Ribbon.
    The application works fine when i start from VS (2010).
    But I have some problems to deploy my application with ClickOnce.

    I think it's the xml markup not a dll but i'm not sure…

    Here's the 2 errors depending of the initialization:

    _ribbon.InitFramework(this);
    I got this error when the application's starting:
    System.Runtime.InteropServices.COMException (0×80004005): Error HRESULT E_FAIL has been returned from a call to a COM component.
    at System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo)
    at RibbonLib.Ribbon.InitFramework(IRibbonForm form, String resourceName, IntPtr hInstance)…

    _ribbon.InitFramework(this, "APPLICATION_RIBBON", "MyApplication.ribbon.dll");
    I got this error when the application's starting:
    System.ApplicationException: Ribbon resource DLL exists but could not be loaded.
    at RibbonLib.Ribbon.InitFramework(IRibbonForm form, String resourceName, String ribbonDllName)
    at MyApplication.FormMain.OnFormLoad(Object sender, EventArgs e)
    at System.Windows.Forms.Form.OnLoad(EventArgs e)…

    Perhaps i missed something? Or is there a way to resolve that?
    thanks for your help,
    Steve

    להגיב
  21. arik13 ביולי 2010 ב 17:48

    Can you provide more information on what are you doing?
    On what systems are you tring to deploy the porject?
    Does it work normally without clickonce?
    etc.

    להגיב
  22. Steve13 ביולי 2010 ב 19:01

    I use Visual Studio 2010 Professional on Windows 7 Professional (32 bits).

    In the solution, i have 2 projects: MyApplication and Ribbon.
    The two are configured for .NET Framework 4 Client Profile.

    I implement a tab with some buttons, a list of recent items, the application menu and quickaccess.

    Everything works fine when i start the application from VS (debug or release). The ribbon's working and all the functionalities are ok.

    To test with Clickonce, I deploy the application on the same workstation.
    MyApplication is signed with test certificate and security is Full trust application.

    But when i start the application after publishing (from browser or directly dble click on the file) i have an error from Microsoft .NET Framework (2 differents depending of the InitFramework method used).

    להגיב
  23. arik16 ביולי 2010 ב 8:33

    Steve,

    I suspect the problem is deploying a native dll with clickonce.
    Try something like adding the native dll to the project, see:

    http://social.msdn.microsoft.com/Forums/en-US/vsto/thread/89694e02-7815-4f63-b1a6-14741525fe0b

    Hope it helps,
    Arik.

    להגיב
  24. Steve18 ביולי 2010 ב 17:08

    It works!
    (I add MyApplication.ribbon.dll from bin/debug folder to MyApplication project – with options Content/Copy Always).

    thanks for your help,
    Steve

    להגיב
  25. AlexL8 באוגוסט 2010 ב 9:49

    What abount implementing Ribbon in custom libraries? I would like to add control not in main module and always get HRESULT: 0×80070578 in InitFramework(). Here is my code (the ribbon.dll is compiled fine):

    public class MyUserControl : UserControl, IRibbonForm
    {
    private Ribbon ribbon = new Ribbon();

    private void MyUserControl_Load(object sender, EventArgs e)
    {
    this.ribbon.InitFramework(this); // exception is thrown!!!
    }

    private void MyUserControl_ControlRemoved(object sender, ControlEventArgs e)
    {
    this.ribbon.DestroyFramework();
    }

    public HRESULT Execute(uint commandId, ExecutionVerb verb, PropertyKeyRef key, PropVariantRef currentValue, IUISimplePropertySet commandExecutionProperties)
    {
    return HRESULT.S_OK;
    }

    public HRESULT UpdateProperty(uint commandId, ref PropertyKey key, PropVariantRef currentValue, ref PropVariant newValue)
    {
    return HRESULT.S_OK;
    }
    }

    Env: VS2010, w7sdk, WinForms app

    להגיב
  26. arik9 באוגוסט 2010 ב 23:36

    Error 0×80070578 means "Invalid window handle"
    I assume your problem is with your implementation of the handle property.
    The handle you return MUST be a handle to a main window, it can't be the handle of the user control, this is a limitation of the Windows Ribbon Framework.

    Hope it helps,
    Arik.

    להגיב
  27. alex12 ביוני 2011 ב 7:53

    no puedo seguir esta parte =(…
    no coincide lo que dice aqui con el codigo que hay que descargar

    להגיב
  28. arik12 ביוני 2011 ב 16:25

    Alex, this post was written when the project was being developed, since then the library got improved and now it's even easier to work with.

    check out the following post for a quick start tutorial:
    http://blogs.microsoft.co.il/blogs/arik/archive/2010/11/24/ribbon-for-winforms-quick-start-tutorial.aspx

    להגיב
  29. cyla6 בינואר 2012 ב 11:53

    the ribbon is transparent n the
    this.ribbon.DestroyFramework();
    this.ribbon.InitFramework(this);
    dont exist yes they are in the project but not accesed
    any help pliz ?????????????

    להגיב
  30. cyla6 בינואר 2012 ב 11:53

    the ribbon is transparent n the
    this.ribbon.DestroyFramework();
    this.ribbon.InitFramework(this);
    dont exist yes they are in the project but not accesed
    any help pliz ?????????????

    להגיב
  31. glennp26 ביוני 2012 ב 23:38

    In step 3, if you have VS 2010, I believe the corresponding ribbon schema is available to select (independent of Win 7 SDK) as customUI14.xsd

    להגיב