Codejock Forums Homepage
Forum Home Forum Home > Codejock Products > Visual C++ MFC > Toolkit Pro
  New Posts New Posts RSS Feed - Transparent CXTButton?
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Transparent CXTButton?

 Post Reply Post Reply
Author
Message
yenjonat View Drop Down
Newbie
Newbie


Joined: 10 April 2009
Status: Offline
Points: 2
Post Options Post Options   Thanks (0) Thanks(0)   Quote yenjonat Quote  Post ReplyReply Direct Link To This Post Topic: Transparent CXTButton?
    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. 
Back to Top
rdhd View Drop Down
Senior Member
Senior Member
Avatar

Joined: 13 August 2007
Location: United States
Status: Offline
Points: 931
Post Options Post Options   Thanks (0) Thanks(0)   Quote rdhd Quote  Post ReplyReply Direct Link To This Post 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 );

Back to Top
 Post Reply Post Reply
  Share Topic   

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.04
Copyright ©2001-2021 Web Wiz Ltd.

This page was generated in 0.031 seconds.