How to add images to toolbar buttons for activex control mscomctl.ocx
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: How to add images to toolbar buttons for activex control mscomctl.ocx

  1. #1
    Join Date
    Aug 2013
    Posts
    35

    Unhappy 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?!

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,351

    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

  3. #3
    Join Date
    Aug 2013
    Posts
    35

    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?

  4. #4
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,351

    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

  5. #5
    Join Date
    Nov 2000
    Location
    Voronezh, Russia
    Posts
    5,957

    Re: How to add images to toolbar buttons for activex control mscomctl.ocx

    Quote Originally Posted by shjdr7 View Post
    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

  6. #6
    Join Date
    Aug 2013
    Posts
    35

    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?

  7. #7
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,351

    Re: How to add images to toolbar buttons for activex control mscomctl.ocx

    Quote Originally Posted by shjdr7 View Post
    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

  8. #8
    Join Date
    Aug 2013
    Posts
    35

    Talking Re: How to add images to toolbar buttons for activex control mscomctl.ocx

    Quote Originally Posted by VictorN View Post
    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 );

  9. #9
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,351

    Re: How to add images to toolbar buttons for activex control mscomctl.ocx

    Quote Originally Posted by shjdr7 View Post
    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

  10. #10
    Join Date
    Aug 2013
    Posts
    35

    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

  11. #11
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,351

    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

  12. #12
    Join Date
    Aug 2013
    Posts
    35

    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
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center