ObjectARX
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Bitmap in Toolbar button

7 REPLIES 7
SOLVED
Reply
Message 1 of 8
rgppp
1166 Views, 7 Replies

Bitmap in Toolbar button

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)

7 REPLIES 7
Message 2 of 8
owenwengerd
in reply to: rgppp

I'm pretty sure that method expects a filename, not a resource name.

--
Owen Wengerd
ManuSoft
Message 3 of 8
Matti72
in reply to: rgppp

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.

 

Message 4 of 8
rgppp
in reply to: owenwengerd

I'm passing the file name. I've tested with the resource name, wouldn't harm since it is the default while working with resources in win apis. But it's clear now the autocad expects the file name.
Message 5 of 8
rgppp
in reply to: Matti72


@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?

Message 6 of 8
Balaji_Ram
in reply to: rgppp

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
Developer Technical Services
Autodesk Developer Network

Message 7 of 8
rgppp
in reply to: Balaji_Ram


@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?

Message 8 of 8
Balaji_Ram
in reply to: rgppp

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. 



Balaji
Developer Technical Services
Autodesk Developer Network

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report

”Boost