Professional UI Solutions
Site Map   /  Register
 
 

Forum

Please Log In to post a new message or reply to an existing one. If you are not registered, please register.

NOTE: Some forums may be read-only if you are not currently subscribed to our technical support services.

Forums » Prof-UIS Tech Support » Problems with transparent icons built from bitmaps Collapse All
Subject Author Date
Emil Pop Jun 12, 2006 - 7:38 PM

For consistency reasons, in my project I need to create icons from bitmaps found in toolbars. A couple of years ago, you helped me with the following function:

int
iGetIconFromToolbar( int iToolbarId, int iBitmapIx, CExtCmdIcon& rIcon)
{
// Recover the bitmap list
HBITMAP hBmp = CExtPaintManager::stat_LoadBitmapResource(
MAKEINTRESOURCE( iToolbarId ) );

ASSERT( hBmp != NULL );
BITMAP bmpInfo;
::memset( &bmpInfo, 0, sizeof(BITMAP) );
::GetObject( hBmp, sizeof(BITMAP), &bmpInfo );
ASSERT( bmpInfo.bmWidth > 0 && bmpInfo.bmHeight > 0 );

INT i = iBitmapIx;
CRect rcPart( 16*i, 0, 16*(i+1), bmpInfo.bmHeight );

// original version
// rIcon = CExtCmdIcon ( hBmp, RGB(0,255,0), &rcPart );

// new version

rIcon.AssignFromHBITMAP(
hBmp,
RGB(192,192,192), // COLORREF(-1L) - no force transparent pixels
&rcPart        );

ASSERT( !rIcon.IsEmpty() );
::DeleteObject( hBmp );
return 0;
}


While upgrading to Professional Studio 2.54 I noticed some interface changes in CExtCmdIcon (e.g. there was no constructor taking a bitmap as an argument; I used instead the member function CExtCmdIcon::AssignFromHBITMAP() ).
In the new implementation though, the background is transparent only if the color quality of the display is 32 bit. Whenever the color quality of the display is 16 bit, the icon’s background is no longer transparent. This is an issue if the application is run through Windows Remote Desktop where the color quality of the display is 16 bit.

I sent you a modified version of the file MainFrm.cpp belonging to the project PageNavigator. Rebuilt the project with it and run it twice:
- first set Display/Settings/Color quality to 32 bit everything; notice the question mark associated to the E-mail button has a transparent background (as it should)
- stop the application and change Display/Settings/Color quality to 16 bit.
- rerun PageNavigator: you’ll notice the background of the E-mail button is no longer transparent...


Thanks,
Emil

Technical Support Jun 13, 2006 - 12:09 PM

The function that loads icons works well. The problem is in the API of the page navigator which does not provide method overloads with CExtCmdIcon parameters instead of HICON’s (Of course, we will add these overloads). This can be fixed in the MainFrm.cpp file you sent us by adding two lines of code:

CExtPageNavigatorWnd::PAGE_ITEM_INFO * pPII = 
    m_wndPageNavigator.ItemInsert(
        -1,
        _T("Mail"),
        oIcon.ExtractHICON(),
        oIcon.ExtractHICON()
        );
    (*(pPII->IconGetPtr(true))) = oIcon; // ADDED
    (*(pPII->IconGetPtr(false))) = oIcon; // ADDED
The CExtCmdIcon class was not changed, it was actually re-writted from scratch :-). Now all the bitmap re-lated internals of Prof-UIS are 32-bit with alpha channel on any Windows OS even if it does not support alpha blended bitmap painting. The CExtCmdIcon class is now just a container for four CExtBitmap objects which represent normal (CExtCmdIcon::m_bmpNormal), hovered (CExtCmdIcon::m_bmpHover), pressed (CExtCmdIcon::m_bmpPressed) and disabled (CExtCmdIcon::m_bmpDisabled) states of the icon. It is enough to initialize only the CExtCmdIcon::m_bmpNormal bitmap inside a CExtCmdIcon object. All other bitmaps will be generated by the paint manager automatically when they are painted anywhere. Both CExtCmdIcon and CExtBitmap classes do not eat GDI handles at all.