Print Page | Close Window

Using CXTButton with CXTPGraphicBitmapPng

Printed From: Codejock Forums
Category: Codejock Products
Forum Name: General Discussion
Forum Description: Topics Related to Visual C++ MFC Development in General
URL: http://forum.codejock.com/forum_posts.asp?TID=7437
Printed Date: 30 January 2025 at 11:47pm
Software Version: Web Wiz Forums 12.04 - http://www.webwizforums.com


Topic: Using CXTButton with CXTPGraphicBitmapPng
Posted By: shobits1
Subject: Using CXTButton with CXTPGraphicBitmapPng
Date Posted: 24 June 2007 at 2:16pm
Hello very one,,
I tired in search for using CXTButton with CXTPGraphicBitmapPng so please help me if you can.
I know that there are many way to load CXTButton with icon or bitmap, but I want to use PNG image in my CXTButton.
 
Why should I use it: after the success help of oleg to how draw a PNG image (PNG with alpha layer) correctly  (see: http://forum.codejock.com/forum_posts.asp?TID=7402 - http://forum.codejock.com/forum_posts.asp?TID=7402 )
 I used it in my own controls, some of these PNG are like icons in size (48x48) so for reduce the size of my resource and help my program to execute rapidly (use the preloaded image in my CXTPGraphicBitmapPng objects), I decided to use these CXTPGraphicBitmapPng but when I try to add it in CXTButton, I fail, the two function used in CXTButton to set icon or image are:
BOOL SetBitmap( CSize size, UINT nID, BOOL bRedraw = TRUE);
And
BOOL SetIcon( CSize size, HICON hIcon, HICON hIconHot = NULL, BOOL bRedraw = TRUE);
BOOL SetIcon( CSize size, UINT nID, UINT nHotID = 0, BOOL bRedraw = TRUE);
BOOL SetIcon( CSize size, LPCTSTR lpszID, LPCTSTR lpszHotID = NULL, BOOL bRedraw = TRUE);
BOOL SetIcon( CSize size, CXTPImageManagerIconHandle hIconHandle, CXTPImageManagerIconHandle hIconHotHandle, BOOL bRedraw = TRUE);
 
I can't use the first one because my Images are stored externally, so I try with SetIcon (exactly  with the last one), I think to convert my CXTPGraphicBitmapPng to CXTPImageManagerIconHandle, or create CXTPImageManagerIconHandle object by using CXTPGraphicBitmapPng as HBITMAP but it can't be helped
What I want:
1-    If possible how I can set image for CXTButton using CXTPGraphicBitmapPng;
2-    How I can set CXTButton image (this image is PNG sorted externally in Dll file);
3-    How I can create a valid icon with alpha layer using CXTPGraphicBitmapPng;
4-    Is CXTButton support icons with alpha layer, if not how I can use it with these icons;
Note: all my PNG files are images with alpha layer and sorted in resource file externally this resource file is a Dll file.
 
Thanks to every one ...



Replies:
Posted By: Oleg
Date Posted: 25 June 2007 at 1:22am
Hi,
you need 4th method and load image using methods of CXTPImageManagerIconHandle/CXTPImageManagerIcon:
 
 
 
CXTPImageManagerIconHandle hIconHandle;
 BOOL bAlphaBitmap = FALSE;
 HBITMAP hBitmap = CXTPImageManagerIcon::LoadBitmapFromResource(MAKEINTRESOURCE(nID), &bAlphaBitmap);
 if (!hBitmap)
  return FALSE;
 if (bAlphaBitmap)
 {
  hIconHandle = hBitmap; // Will call DeleteObject;
 }
 else
 {
  CBitmap bmpIcon;
  bmpIcon.Attach(hBitmap);
  // convert the bitmap to a transparent icon.
  HICON hIcon = CXTPTransparentBitmap(bmpIcon).ConvertToIcon();
  hIconHandle = hIcon; // Will call DestoyIcon;
 }
 if (hIconHandle.IsEmpty())
  return FALSE;
 return CXTButton::SetIcon(size, hIconHandle, CXTPImageManagerIconHandle(), bRedraw);


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


Posted By: shobits1
Date Posted: 25 June 2007 at 5:28pm
It's ok and work fine, how ever some area of my PNG image are transparent and I want to make my button transparent  in this area too
is there any method that do it or I must use the BS_OWNERDRAW style then define my draw function


Posted By: Oleg
Date Posted: 26 June 2007 at 1:22am
Hello,
 
You can override virtual void DrawItem(LPDRAWITEMSTRUCT lpDrawItemStruct);
and draw tranparent part as you need.


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



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