I have a dialog window with a CTabCtrl. The following code is successful in showing an icon along with the text name on each of 16 tabs. The icons are 16x16 pixel squares, 4-bit, that I made with Visual Studio 2008's resource editor.

The icons to have transparent pixels (the first pixel of the color map), so that I can "shape" them to be circles, etc., instead of squares.

However, the transparency works ONLY IF I use ILC_COLOR8 instead of ILC_COLOR4, and use LR_LOADMAP3DCOLORS. (Neither of these are documented as being related.) If I don't have LR_LOADMAP3DCOLORS, or if I use ILC_COLOR4, the "transparent" parts of the icon are colored white instead.

Although my code now works, can anyone explain why? I'm really a Unix guy and would love to understand Windows better than I do.



// Configure the Tab control.

CTabCtrl* ptab = (CTabCtrl*) GetDlgItem( IDC_TAB1 );

static CImageList* pil = NULL;

if ( ! pil ) {
pil = new CImageList;

// There's no documentation on the entire internet of this, but if I specify
// ILC_COLOR4, the first color in the icon is turned to white, not the actual
// COLOR_WINDOW.

pil->Create( 16, 16, ILC_COLOR8, 4, 4 );

// The help for CImageList doesn't explain what this background color is for.
// I've tried the following to see if it controls the color used for transparency
// of the images in the image list (with LOADTRANSPARENT) but it doesn't
// seem to be used for that.
// pil->SetBkColor( CLR_NONE );
// pil->SetBkColor( GetSysColor( COLOR_WINDOW ) );

// This worked fine, except it doesn't support transparencies.

// HICON hiMyIcon = LoadIcon( AfxGetInstanceHandle(), MAKEINTRESOURCE( IDI_OK ) );

// LR_LOADTRANSPARENT is documented to turn "the first color" in the icon to the
// window background color, in effect making it transparent. However, without
// LR_LOADMAP3DCOLORS it instead is just turning that portion of the icon to white.

HICON hiMyIcon = (HICON) LoadImage( AfxGetInstanceHandle(),
MAKEINTRESOURCE( IDI_PATCH_STATUS_OK ),
IMAGE_ICON, 16, 16,
LR_LOADTRANSPARENT | LR_LOADMAP3DCOLORS );

pil->Add( hiMyIcon );

// The discussion of OverlayImage mentions transparency, but I can't figure out
// how to try this. But not needed once I start using LR_LOADMAP3DCOLORS.

// pil->SetOverlayImage( iIndex, 1 );
}

ptab->SetImageList( pil );



// Make 16 tabs. Label each tab with the OK icon and the tab number.

for ( int i = 0; i < 16; i++ ) {
char szBuf[ 200 ];

AKsnprintf( szBuf, sizeof( szBuf ), "%d", i + 1 );
ptab->InsertItem( i, szBuf, 0 );
}