How to add images to toolbar buttons for activex control mscomctl.ocx
//#import "c:\windows\SysWow64\mscomctl.ocx" raw_interfaces_only //in window7
using namespace MSComctlLib;
CComPtr<IButtons> pButtons;
CComPtr<IButton> pButton;
CComPtr<IImages> pImages;
CComPtr<IImage> pImage;
CComPtr<IDispatch> pDisp;
HRESULT hr = m_pToolbar->get_Buttons(&pButtons);
hr = pButtons->Add(NULL,NULL,NULL,NULL,NULL,&pButton);
hr = m_pImageList->get_ListImages(&pImages);
CComVariant vrIndex(1),vrImage;
hr = pImages->get_Item(&vrIndex,&pImage);//I added 3 images to imagelist
hr = pImage->QueryInterface(&pDisp);
vrImage = pDisp;
hr = pButton->put_Image(vrImage);//hr = 0x800a8b1d, why?!
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
Why don"t you want to use try/catch blocks to handle the possible exceptions and then obtain the error info?
See example in http://msdn.microsoft.com/en-us/libr...(v=vs.85).aspx
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
I got the error description like this
"ImageList must be initialized before it can be used"
But how to correct?
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
I have no idea what all these interfaces are but I guess there is some documentation about how to use them...
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
Quote:
Originally Posted by
shjdr7
CComVariant vrIndex(1),vrImage;
hr = pImages->get_Item(&vrIndex,&pImage);//I added 3 images to imagelist
hr = pImage->QueryInterface(&pDisp);
vrImage = pDisp;
hr = pButton->put_Image(vrImage);//hr = 0x800a8b1d, why?!
I believe it's quite obvious:
Quote:
System.Runtime.InteropServices.COMException (0x800A8B1D): ImageList must be initialized before it can be used
So, somewhere it fails, but you never check where it happens.
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
I changed my code and then error message also changed
hr = m_pToolbar->put_ImageList(m_pImageList);// Added this line this time
hr = m_pButton->put_Image(vrImage);//I am getting error message "Invalid Key"
//I tried pImage->put_Key() also
Any idea?
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
Quote:
Originally Posted by
shjdr7
I changed my code and then error message also changed
...
Any idea?
Well, trial and error method may be sometimes very useful. But not in your case!
Please, read the documentation and search for the code examples!
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
Quote:
Originally Posted by
VictorN
Well, trial and error method may be sometimes very useful. But not in your case!
Please, read the documentation and search for the code examples!
Well, I got the answer.The correct code is as below
CComVariant vrIndex = 1;
m_pButton->put_Image(vrIndex );
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
Quote:
Originally Posted by
shjdr7
Well, I got the answer.The correct code is as below
CComVariant vrIndex = 1;
m_pButton->put_Image(vrIndex );
Hmm...
Why is it 1, not 11 or 100?
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
To add the first image to a button that is the code
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
Do you check somewhere that imagelist contains an image with the index 1?
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
Images can be added to imagelist during design time or run time. Adding during design time is very easy.Please verify
yourself.
If you want code to add images run time, I can help it. First image has index 1(not 0)