I am working with the C++ API for ArcObjects (Linux, QT), and I am running into problems with when creating a custom button on a toolbar. I have read up on the C++ specific implementation of creating a custom command (inheriting from AoCommandBase
and adding the button with AoToolbarAddCommand
).
After many hours of fiddling around, I have come to the conclusion that AoToolbarAddCommand
simply isn't doing its job. I can add ESRI predefined commands with no problem, but my custom command shows up as a useless grey square (my icon doesn't even display). My debug output suggests that none of the functions defined in my command are being called during setup (or ever for that matter), and they definitely should be. If it helps, excerpts from my code are below:
From the add_toolbar_items function:
CComVariant varTool;
long itemindex;
varTool = L"esriControlCommands.ControlsOpenDocCommand";
ipToolbar->AddItem(varTool, 0, -1, VARIANT_FALSE, 0,
esriCommandStyleIconOnly, &itemindex);
panRight = new PanRight(); /*panRight is global, PanRight is my command class*/
AoToolbarAddCommand(ipToolbar, panRight, esriCommandStyleIconOnly);
The PanRight class (my custom button) is stolen from a sample, but I changed the code for loading bitmaps because the provided code did not work. All the other functions remain unchanged, except for a cout statement letting me know if the function were ever to run.
PanRight::PanRight()
{
m_ipHookHelper.CrreateInstance(CLSID_HookHelper);
std::cout<<"panright constructor\n";
//load bitmap
IPictureElement3Ptr ipPict(CLSID_PictureElement);
HRESULT hr = ipPict->ImportPictureFromFile(CComBSTR(L"<pathToPic>"));
if(SUCCEEDED(hr))
{
OLE_HANDLE hBitmap;
hr = ipPict->get_Handle(&hBitmap);
if(SUCCEEDED(hr))
{m_hBitmap = hBitmap;}
}
}
Does anyone have any ideas as to why AoToolbarAddCommand
might not be doing its job? Has anyone successfully added a custom command using the C++ API?
add_toolbar_items
function.