I have an application with property sheet in outlook_bar style which I am using as a main dialog. I have created the property sheet with 3 pages on it. I have created 6 bitmaps each dimension(82,82) for displaying on the tabs.At a time 3 of the bitmaps will be used by the property sheet.
Whenever a user navigates to a new tab I would like to change the bitmap displayed on the selected tab. I have written a function ChangeImgList(int selno) below to do this.
The function is called from the OnSetActive function of the respective property pages.When I run the code I get an "Encountered an improper argument error" at the line SetIconsList(m_shtSelImages.m_hImageList).
I get this error when the second time this function is called.
The function is as below:
void AppPropSheet::ChangeImgList(int sel)
{
//m_shtSelImages is of type CImageList and m_bmpimgs[3] is an array of CBitmap
//both are members of AppPropSheet class
static bool firsttime = true;
int retval;
if(!firsttime)
for(int i=0;i<3;i++)
m_bmpimgs[i].~CBitmap();
if (sel == 0)
m_bmpimgs[0].LoadBitmapA(IDB_BITMAP86);
else
m_bmpimgs[0].LoadBitmapA(IDB_BITMAP77);
if (sel == 1)
m_bmpimgs[1].LoadBitmapA(IDB_BITMAP87);
else
m_bmpimgs[1].LoadBitmapA(IDB_BITMAP81);
if (sel == 2)
m_bmpimgs[2].LoadBitmapA(IDB_BITMAP88);
else
m_bmpimgs[2].LoadBitmapA(IDB_BITMAP79);
if (!firsttime)
m_shtSelImages.DeleteImageList();
retval = m_shtSelImages.Create(81, 81, ILC_COLOR24|ILC_MASK , 1, 1);
retval = m_shtSelImages.Add(&m_bmpimgs[0], RGB(128, 128, 128));
retval = m_shtSelImages.Add(&m_bmpimgs[1], RGB(128, 128, 128));
retval = m_shtSelImages.Add(&m_bmpimgs[2], RGB(128, 128, 128));
//SetIconsList(m_shtSelImages.m_hImageList);
firsttime = false;
}
//end of function
In the debugger I found the following : It asserts in the SetIconsList function at line ENSURE(m_Icons.GetSafeHandle()==NULL) in afxpropertysheet.cpp
Apparently the way I am trying to change the bitmap is not provided by the framework.Looking forward to your suggestions.