Print Page | Close Window

Transparent CXTButton?

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: Toolkit Pro
Forum Description: Topics Related to Codejock Toolkit Pro
URL: http://forum.codejock.com/forum_posts.asp?TID=13975
Printed Date: 22 June 2025 at 2:50pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Transparent CXTButton?
Posted By: yenjonat
Subject: Transparent CXTButton?
Date 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. 



Replies:
Posted By: rdhd
Date Posted: 20 April 2009 at 4:05pm
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 icon

hIconHandle = 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 );




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