I've checked every post i could find in this forum. Some of them helped, but now I'm stucked.
I'm creating a Toolbar, and adding some buttons, everthing works fine. Then I'm setting the bitmaps for these buttons. And the bitmaps are in the resource, the are embeded with the plugin. When i launch the AutoCad from the Visual Studio the buttons has the bitmaps as icons, just as I expected. But runnig a release version of the plugin I get only the "Cloud with questin mark" icon for my buttons. I've got that during the debug AutoCad was geting the bitmaps in the path were all the sources and files are, and is set as working directory. Here is a piece of my code:
void defineToolbar() { //CAcModuleResourceOverride resOverride; AutoCAD::IAcadApplication *pAcad; AutoCAD::IAcadMenuGroups *pMenuGroups; AutoCAD::IAcadMenuGroup *pMenuGroup; AutoCAD::IAcadToolbars *pToolbars; AutoCAD::IAcadToolbar *pToolbar; AutoCAD::IAcadToolbarItem *pToolbarItem; HRESULT hr = NOERROR; LPUNKNOWN pUnk = NULL; LPDISPATCH pAcadDisp = acedGetIDispatch(TRUE); hr = pAcadDisp->QueryInterface(AutoCAD::IID_IAcadApplication, (void**)&pAcad); pAcadDisp->Release(); if (FAILED(hr)) return; pAcad->put_Visible(true); pAcad->get_MenuGroups(&pMenuGroups); pAcad->Release(); VARIANT index; VariantInit(&index); V_VT(&index) = VT_I4; V_I4(&index) = 0; VARIANT flyoutButton; VariantInit(&flyoutButton); V_VT(&flyoutButton) = VT_BOOL; V_BOOL(&flyoutButton) = 0; pMenuGroups->Item(index, &pMenuGroup); pMenuGroups->Release(); pMenuGroup->get_Toolbars(&pToolbars); pMenuGroup->Release(); CString toolbarNameTmp; toolbarNameTmp.Format(_T("%s Toolbar"), PLUGIN_NAME); BSTR toolbarName = SysAllocString(toolbarNameTmp.AllocSysString()); HRESULT resultToolbar = pToolbars->Add(toolbarNameTmp, &pToolbar); if (SUCCEEDED(resultToolbar)) { VariantInit(&index); V_VT(&index) = VT_I4; V_I4(&index) = 0; BSTR bstrMenuItemMacro = _T("dosomething"); BSTR bstrMenuItemName = _T("Do something"); BSTR iconName = _T("TEST.BMP"); pToolbar->AddToolbarButton(index, bstrMenuItemName, NULL, bstrMenuItemMacro, flyoutButton, &pToolbarItem); if(pToolbarItem != NULL) { pToolbarItem->SetBitmaps(iconName, iconName); pToolbarItem->Release(); } pToolbar->Release(); } pToolbars->Release(); SysFreeString(toolbarName); }
In the resource (.rc) I have
///////////////////////////////////////////////////////////////////////////// // // Bitmap // "TEST" BITMAP "TEST.bmp"
I read in some post that the ID from the Resource should be sorrunded with " so this is one of my attempts.
I tried:
BSTR iconName = _T("TEST"); // without the .bmp to match the resource ID
And I've confirmed that the resource is packed in the arx:
plugin.arx\.rsrc\1046\BITMAP\TEST.BMP
I think I tryied all that I found in the forums and the docs (including the VB documentation, as suggested on the posts)
Solved! Go to Solution.
Solved by Balaji_Ram. Go to Solution.
Solved by owenwengerd. Go to Solution.
I'm pretty sure that method expects a filename, not a resource name.
Why did you comment the Resource Override out? I mean this line:
//CAcModuleResourceOverride resOverride;
It seems to me, that you are in the ACAD Resources, where your Resource is not known. You have to switch to your dll Resources (with the ResourceOverride) in order to use them.
@Matti72 wrote:Why did you comment the Resource Override out? I mean this line:
//CAcModuleResourceOverride resOverride;It seems to me, that you are in the ACAD Resources, where your Resource is not known. You have to switch to your dll Resources (with the ResourceOverride) in order to use them.
Yep, I'm aware. I've commented just to check the impact of it. And nothing happened (with the line commented, and uncommented)...
So far what I learned was, the resource ID must have a name difined with quotations marks, so when the resource its packed inside the dll it will have that name, and not a constant (number defined in the resoure header).
Am I right? What else?
Hi,
The COM API is intended for use even from external applications. As you have already found, the "SetBitmaps" method only accepts full path. This is mentioned in the AutoCAD ActiveX API documentation.
Regards,
@Balaji_Ram wrote:Hi,
The COM API is intended for use even from external applications. As you have already found, the "SetBitmaps" method only accepts full path. This is mentioned in the AutoCAD ActiveX API documentation.
Regards,
So, in short, there is no way I can use the icons embeded into the dll as resources?
Yes, the only AutoCAD API to change the bitmap of a toolbar item is the ActiveX method SetBitmaps and it only accepts the full file path.
Can't find what you're looking for? Ask the community or share your knowledge.