修改默认构造函数,改变ProPage的ImageList资源
背景:BCGControlsPropSheet类是从CBCGPPropertySheet类继承来的,做了一些修
改,以满足项目的需求。
效果图:

但是将左侧的图标(ImageList)写死了,现在需要修改。经查看,该类的构造函数
定义为:
lass BCGControlsPropSheet : public CBCGPPropertySheet
{
DECLARE_DYNAMIC(BCGControlsPropSheet)
// Construction
public:
BCGControlsPropSheet(const CString strTitle=_T(""),CWnd* pParentWnd = NULL);
...
...
}
实现为:
BCGControlsPropSheet::BCGControlsPropSheet(const CString strTitle,CWnd* pParentWnd)
:CBCGPPropertySheet (strTitle, pParentWnd)
{
BOOL b32BitIcons = globalData.bIsOSAlphaBlendingSupport;
if (globalData.m_nBitsPerPixel == 16)
{
// 32-bit icons in 16 bpp display mode
// are correctly displayed in WinXP only
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx (&osvi);
b32BitIcons = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT &&
(osvi.dwMajorVersion > 5 ||
(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion >= 1)));
}
SetLook (CBCGPPropertySheet::PropSheetLook_OutlookBar);
SetIconsList (b32BitIcons ? IDB_SETTING_ICON32 : IDB_SETTING_ICONS, 32);
EnableVisualManagerStyle();
}
在构造函数里完成了对ImageList的指定(IDB_SETTING_ICON32),给该类增加一个修
改ImageList的接口,实验不能通过。推测是该类设定ImageList的操作只能在构造
函数里完成。因此决定给这个构造函数增加一个参数,将需要的ImageList的图标
的ID传进来。修改后定义:
class BCGControlsPropSheet : public CBCGPPropertySheet
{
DECLARE_DYNAMIC(BCGControlsPropSheet)
// Construction
BCGControlsPropSheet(UINT nImageListResID = 0,const CString strTitle=_T(""),CWnd* pParentWnd = NULL);
……
……
}
BCGControlsPropSheet::BCGControlsPropSheet(UINT nImageListResID,const CString strTitle,CWnd* pParentWnd)
:CBCGPPropertySheet (strTitle, pParentWnd)
{
BOOL b32BitIcons = globalData.bIsOSAlphaBlendingSupport;
if (globalData.m_nBitsPerPixel == 16)
{
// 32-bit icons in 16 bpp display mode
// are correctly displayed in WinXP only
OSVERSIONINFO osvi;
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
::GetVersionEx (&osvi);
b32BitIcons = (osvi.dwPlatformId == VER_PLATFORM_WIN32_NT &&
(osvi.dwMajorVersion > 5 ||
(osvi.dwMajorVersion == 5 && osvi.dwMinorVersion >= 1)));
}
SetLook (CBCGPPropertySheet::PropSheetLook_Tabs);
/*
PropSheetLook_Tabs,
PropSheetLook_OutlookBar,
PropSheetLook_Tree,
PropSheetLook_OneNoteTabs,
PropSheetLook_List,
PropSheetLook_Wizard,
PropSheetLook_AeroWizard,
*/
if (nImageListResID == 0)//为默认值,则使用原有的图像列表(ImageList)
{
SetIconsList (b32BitIcons ? IDB_SETTING_ICON32 : IDB_SETTING_ICONS, 32);
}
else//传了新值,则使用指定的图像列表(ImageList)
{
SetIconsList (b32BitIcons ? nImageListResID : IDB_SETTING_ICONS, 32);
}
EnableVisualManagerStyle();
}
区别在于倒数第三行,根据是是否传参数来设定ImageList.

图中的1~7是设定的图标。
细节考虑:
默认参数的问题,在这个构造函数里,原有的两个参数
a.const CString strTitle,
b.CWnd* pParentWnd
都是是默认参数。
默认参数的使用规则:只能出现在最右边,不能跳过一个参数(使用其默认值)后,
再重新开始指定新的参数。
即:最不需要手动指定值的参数,放在最右边。这里的ImageList是经常需要指定
值的,因此放在最左边,当成第一个参数。
浙公网安备 33010602011771号