-
August 8th, 2013, 07:56 AM
#1
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?!
-
August 8th, 2013, 11:08 AM
#2
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
Victor Nijegorodov
-
August 9th, 2013, 12:39 AM
#3
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?
-
August 9th, 2013, 01:34 AM
#4
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...
Victor Nijegorodov
-
August 9th, 2013, 06:48 AM
#5
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
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:
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.
Last edited by Igor Vartanov; August 9th, 2013 at 06:50 AM.
Best regards,
Igor
-
August 10th, 2013, 06:22 AM
#6
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?
-
August 10th, 2013, 12:28 PM
#7
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
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!
Victor Nijegorodov
-
August 11th, 2013, 02:07 AM
#8
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
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 );
-
August 11th, 2013, 03:22 AM
#9
Re: How to add images to toolbar buttons for activex control mscomctl.ocx
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?
Victor Nijegorodov
-
August 12th, 2013, 10:35 AM
#10
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
-
August 12th, 2013, 10:38 AM
#11
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?
Victor Nijegorodov
-
August 15th, 2013, 09:28 AM
#12
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)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|