Print Page | Close Window

How to change button image?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Command Bars
Forum Description: Topics Related to Codejock Command Bars
URL: http://forum.codejock.com/forum_posts.asp?TID=909
Printed Date: 04 March 2025 at 11:19am
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: How to change button image?
Posted By: brianh
Subject: How to change button image?
Date Posted: 02 July 2004 at 10:00am

I have a command bar button that can be toggled on/off and I want to change the button image depending on whether it's checked or not.

Does anyone know the best way to do this?

Thanks.




Replies:
Posted By: brianh
Date Posted: 02 July 2004 at 10:24am

I have managed to solve the problem by using the following update handler for the button:

HICON m_hIconSingleProd ;
HICON m_hIconMultipleProd ;
bool m_bSingleProduct ;

...

void CMyClass::OnUpdateSingleProduct(CCmdUI* pCmdUI)
{
    pCmdUI->SetCheck(m_bSingleProduct ? 1 : 0) ;

 CXTPControl* pCtl = CXTPControl::FromUI( pCmdUI ) ;
 if ( pCtl )
 {
  CXTPImageManagerIcon* pImgIcon = pCtl->GetParent()->GetImageManager()->GetImage( ID_SINGLE_PRODUCT ) ;
  ASSERT( pImgIcon ) ;
  if( m_bSingleProduct )
  {
   pImgIcon->SetIcon( m_hIconSingleProd ) ;
  }
  else
  {
   pImgIcon->SetIcon( m_hIconMultipleProd ) ;
  }
 }
}

Although this works it doesn't seem very efficient, is there a better way?

Also the image for this command in the menu is now offset upwards from where it should be, any ideas why?



Posted By: brianh
Date Posted: 02 July 2004 at 11:30am
I know why the icon in the menu was offset, I was using LoadIcon() to load it and this only loads icons of the default system size so it was enlarging the icon thus causing the alignment problem.  I changed this to use LoadImage() and the icon in the menu is now correctly positioned - what's more it changes with the toolbar icon. :)


Posted By: Oleg
Date Posted: 05 July 2004 at 3:47am

Easer way to change IconId of control:

pCtl->SetIconId(m_bSingleProduct? ID_SINGLE_PRODUCT: ID_MULTI_PRODUCT)

 



-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: brianh
Date Posted: 05 July 2004 at 4:39am

I had seen this function but I couldn't see how to add the icons and get their ids in the first place.  Can you explain how this is done?

Thanks



Posted By: clintsinger
Date Posted: 27 January 2005 at 5:37pm

I too would like to see how an icon is accessed.  I have tried to add icon resources and then point the SetIconId to the corresponding resource id but all that happens is that the area on toolbar where the icon should appear is blank

I am doing the call from an OnUpdate(CCmdUI* pCmdUI) method and calling CXTPControl* pCtl = CXTPControl::FromUI( pCmdUI ) ; to get the control.

Anyone have any ideas?



Posted By: Oleg
Date Posted: 31 January 2005 at 5:55am
List all your code related this problem.

-------------
Oleg, Support Team
CODEJOCK SOFTWARE SOLUTIONS


Posted By: bluesaphire
Date Posted: 10 August 2006 at 6:37am

 Try this

depending upon the flag checked or unchecked call the setcustomicon function accordingly
if( m_bSingleProduct )
  {
   pControl->SetIconId(ID_SINGLE_PRODUCT);
HICON hIcon;

 hIcon = AfxGetApp()->LoadIcon(ID_SINGLE_PRODUCT);

  pControl->SetCustomIcon(hIcon);
}
else
{
  pControl->SetIconId(ID_MULTIPLE_PRODUCT);
HICON hIcon;

 hIcon = AfxGetApp()->LoadIcon(ID_MULTIPLE_PRODUCT);

  pControl->SetCustomIcon(hIcon);
 
}

I guess this is what you looking for?




Print Page | Close Window

Forum Software by Web Wiz Forums® version 12.04 - http://www.webwizforums.com
Copyright ©2001-2021 Web Wiz Ltd. - https://www.webwiz.net