Click here to Skip to main content
15,867,986 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I am using an outlookbar style property sheet with 3 property pages as the main window of my application.I am unable to change the bitmap icons displayed on the property sheet.I have given code here which isn't working. Please suggest any strategy to change the bitmap icons.You can ignore the code any other approach is welcome.

The following is the way the property sheet is initialized:


C++


//In iniinstance first time the property sheet is created
CBitmap bmpimgs[3];
int retval;

bmpimgs[0].LoadBitmapA(IDB_BITMAP77);
bmpimgs[1].LoadBitmapA(IDB_BITMAP81);
bmpimgs[2].LoadBitmapA(IDB_BITMAP79);

retval = m_PropSht.m_shtSelImages.Create(80, 80, ILC_COLOR24 | ILC_MASK, 1, 1);
retval = m_PropSht.m_shtSelImages.Add(&bmpimgs[0], RGB(128, 128, 128));
retval = m_PropSht.m_shtSelImages.Add(&bmpimgs[1], RGB(128, 128, 128));
retval = m_PropSht.m_shtSelImages.Add(&bmpimgs[2], RGB(128, 128, 128));

m_PropSht.SetIconsList(m_PropSht.m_shtSelImages.m_hImageList);

m_PropSht.SetLook(CMFCPropertySheet::PropSheetLook_OutlookBar, 80);


What I have tried:

I have created a function called ChangeImageList to change the image list associated with the property sheet. I get a failed assertion error when I try to call
SetIconsList function with the changed image list.

C++


//This is called after property sheet creation from OnSetActive function of the //property pages
void AppPropSheet::ChangeImgList(int sel)
{
//AppPropSheet is derived from CMFCPropertySheet
//m_shtSelImages is a member variable of AppPropertySheet of type CImageList

	
	static bool firsttime = true;
	CBitmap bmpimgs[3],bmpmask;
	int retval;



	if (sel == 0)
		bmpimgs[0].LoadBitmapA(IDB_BITMAP87);
	else
		bmpimgs[0].LoadBitmapA(IDB_BITMAP77);

	if (sel == 1)
		bmpimgs[1].LoadBitmapA(IDB_BITMAP86);
	else
		bmpimgs[1].LoadBitmapA(IDB_BITMAP81);

	if (sel == 2)
		bmpimgs[2].LoadBitmapA(IDB_BITMAP88);
	else
		bmpimgs[2].LoadBitmapA(IDB_BITMAP79);
	
	
	m_shtSelImages.Remove(2);
	m_shtSelImages.Remove(1);
	m_shtSelImages.Remove(0);
		
	ImageList_Destroy(m_shtSelImages.m_hImageList);
	retval = m_shtSelImages.Create(81, 81, ILC_COLOR24 | ILC_MASK, 1, 1);
		
	retval=m_shtSelImages.Add(&bmpimgs[0],RGB(128,128,128));
	retval=m_shtSelImages.Add(&bmpimgs[1], RGB(128, 128, 128));
	retval=m_shtSelImages.Add(&bmpimgs[2], RGB(255, 255, 255));
		
	SetIconsList(m_shtSelImages.m_hImageList);//I get an assertion here
 	                                          //ENSURE(GetSafeHwnd==NULL)
                                              // in function SetIconsList
                                              //inside afxpropertysheet.cpp
	GetTabControl()->Invalidate();
	RedrawWindow();
	
}
Posted
Updated 20-Oct-21 21:08pm
v4
Comments
Victor Nijegorodov 21-Oct-21 6:35am    
You wrote:
SetIconsList(m_shtSelImages.m_hImageList);//I get an assertion here
//ENSURE(GetSafeHwnd==NULL)
// in function SetIconsList
//inside afxpropertysheet.cpp
But there is not such a line:
ENSURE(GetSafeHwnd==NULL)
in the CMFCPropertySheet::SetIconsList method.
rdeekonda 21-Oct-21 8:27am    
Sorry for the typo. The line is ENSURE(m_Icons.GetSafeHandle()==NULL)

The MS controls are creating an own copy of the bitmaps. So when you want to change them, you need to destroy the control and recreate a new object with the new bitmaps.
 
Share this answer
 
Comments
rdeekonda 21-Oct-21 8:24am    
Sorry for the typo. The line is ENSURE(m_Icons.GetSafeHandle()==NULL)
Yes, KarstenK is correct. If I were you, I would preload all the bitmaps and maintain handles to them. Then when the selection changes building your list will be very fast because you don't have to load any of them. You can just assemble the current image list. You still need to delete the control's copy as KarstenK mentioned but you can keep your copy around until the containing object (property sheet) is destroyed.
 
Share this answer
 
Comments
rdeekonda 21-Oct-21 4:13am    
Thanks KarstenK,
I cannot destroy the property sheet as I am using it as the main window of my application.I need to change the bitmaps while the property sheet is alive. I can preload the bitmaps once and set them later as suggested and use the CImageList::Replace. How can I destroy the copy stored in the property sheet without destroying the property sheet itself. Any idea to change the bitmaps is welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900