It is generally the same as with C# or VB.NET, but image creation has to find its own way in C++ as its compiler does not support Embedded Resource build type.
So, a resource file (with extension .resx) is created and two images are imported into it, and a Resourcemanager is used instead to read them out from the resource file. Here is the code:
RibbonPanel^ CreateRibbonPanel()
{
RibbonPanel^ panel = _cachedUiCtrApp->CreateRibbonPanel("RevitAddinVCTest");
////Default button:
PushButtonData^ pbDataExtCmd = gcnew PushButtonData("ExtCmd", "ExtCmd", Assembly::GetExecutingAssembly()->Location, "RevitAddinVCTest.ExtCmd");
PushButton^ pbExtCmd = static_cast<PushButton^>(panel->AddItem(pbDataExtCmd));
pbExtCmd->ToolTip = "ExtCmd";
pbExtCmd->LargeImage = BmpImageSource("ExtCmd32x32");
pbExtCmd->Image = BmpImageSource("ExtCmd16x16");
////More buttons:
return panel;
}
System::Windows::Media::ImageSource^ BmpImageSource(String^ embeddedPath)
{
ResourceManager^ resources = gcnew ResourceManager("RevitAddinVCTest.Resources", Assembly::GetExecutingAssembly());
System::Drawing::Bitmap^ img = (cli::safe_cast<System::Drawing::Bitmap^>(resources->GetObject(embeddedPath)));
IntPtr hBitmap = img->GetHbitmap();
return System::Windows::Interop::Imaging::CreateBitmapSourceFromHBitmap(hBitmap, IntPtr::Zero, Int32Rect::Empty, BitmapSizeOptions::FromEmptyOptions());
}
In case some details about resource files, ResourceManager, and Images are necessary, a lot of information is there on MSDN or can be found by googling.
All these can be done automatically by the RevitAddinWizard.
Recent Comments