![]() |
Transparent CXTButton? |
Post Reply ![]() |
Author | |
yenjonat ![]() Newbie ![]() Joined: 10 April 2009 Status: Offline Points: 2 |
![]() ![]() ![]() ![]() ![]() Posted: 10 April 2009 at 1:25pm |
Hi,
I am trying to create a CXTButton that uses an icon with a transparent background. Is there an easy way to do this? I feel like there should be, but that I'm just missing something really simple. |
|
![]() |
|
rdhd ![]() Senior Member ![]() ![]() Joined: 13 August 2007 Location: United States Status: Offline Points: 931 |
![]() ![]() ![]() ![]() ![]() |
Icon or bitmap (HBITMAP)? I have a button subclassed from CXTButton that loads an HBITMAP from a resource file. f you have an HBITMAP, you can do the following:
BITMAP bm = {0}; ::GetObject( m_hbmImage, sizeof(bm), &bm );
CBitmap bmpIcon; bmpIcon.Attach(m_hbmImage); CSize iconSize(bm.bmWidth, bm.bmHeight); // convert the bitmap to a transparent icon.HICON hIcon = CXTPTransparentBitmap(bmpIcon).ConvertToIcon(); CXTPImageManagerIconHandle hIconHandle; // do not set equal to hIcon here or it will NOT destrory the iconhIconHandle = hIcon; // Will call DestoyIcon;SetIcon(iconSize, hIconHandle, CXTPImageManagerIconHandle(), FALSE); m_hbmImage = NULL; // consumed and then deleted by bmpIcon in the CBitmap dtor that runs when this block of code goes out of scope.By default, pixel(0,0) is considered the background color that drives transparency. I once posted a question as to whether there was a way to specifically set the background color so the first pixel is not used and Oleg said there was. Unfortunately I don't recall what the member or method is but you can probably search the forum to find his answer (probably just find all my posts and his replies). If you actually have an icon, you should be able to use one of the SetIcon overloads (perhaps the one that takes in a CXTPImageManagerIcon, which has various member methods for loading your image). For instance I have some code that loads a bitmap from a file on disk and I do this: BOOL bAlphaBitmap = FALSE; HBITMAP hbmMenuItem = CXTPImageManagerIcon::LoadBitmapFromFile( lpszImageFileName, &bAlphaBitmap ); |
|
![]() |
Post Reply ![]() |
|
Tweet
|
Forum Jump | Forum Permissions ![]() You cannot post new topics in this forum You cannot reply to topics in this forum You cannot delete your posts in this forum You cannot edit your posts in this forum You cannot create polls in this forum You cannot vote in polls in this forum |