MFC学习之路(三)CPropertyPage调用UpdateData()的时候崩溃

在CPropertySheet的派生类里面有两个CPropertyPage变量分别为prop1和prop2。
class CPropD::CPropertySheet
{
CPropertyPage prop1;
CPropertyPage prop2;
}
我想使用prop1和prop2里面的值控件值变量,当然,要先更新

prop1.UpdateData;
prop2.UpdateData;


问题是执行第二条语句的时候出发了断言,发现是prop2的句柄为空。
上网一查,原来默认情况下属性页只有要被显示的时候才会被创建,怎么办,总不能要求用户
点确定之前一定要先点击一下第二个属性页吧。
当然,已经有解决方案了。
page1.m_psp.dwFlags |= PSP_PREMATURE;
page2.m_psp.dwFlags |= PSP_PREMATURE;

MSDN一下。
CPropertyPage有个成员:
m_psp
The Windows PROPSHEETPAGE structure. Provides access to basic property page parameters.




typedef struct {
DWORD dwSize;
DWORD dwFlags;
HINSTANCE hInstance;
union {
LPCSTR pszTemplate;
LPCDLGTEMPLATE pResource;
} ;
union {
HICON hIcon;
LPCSTR pszIcon;
} ;
LPCSTR pszTitle;
DLGPROC pfnDlgProc;
LPARAM lParam;
LPFNPSPCALLBACK pfnCallback;
UINT *pcRefParent;
#if (_WIN32_IE >= 0x0500)
LPCTSTR pszHeaderTitle;
LPCTSTR pszHeaderSubTitle;
#endif
#if (_WIN32_WINNT >= 0x0501)
HANDLE hActCtx;
#endif
} PROPSHEETPAGE, *LPPROPSHEETPAGE;typedef struct {
DWORD dwSize;
DWORD dwFlags;
HINSTANCE hInstance;
union {
LPCSTR pszTemplate;
LPCDLGTEMPLATE pResource;
} ;
union {
HICON hIcon;
LPCSTR pszIcon;
} ;
LPCSTR pszTitle;
DLGPROC pfnDlgProc;
LPARAM lParam;
LPFNPSPCALLBACK pfnCallback;
UINT *pcRefParent;
#if (_WIN32_IE >= 0x0500)
LPCTSTR pszHeaderTitle;
LPCTSTR pszHeaderSubTitle;
#endif
#if (_WIN32_WINNT >= 0x0501)
HANDLE hActCtx;
#endif
} PROPSHEETPAGE, *LPPROPSHEETPAGE;Members
dwSize
DWORD
Size, in bytes, of this structure. The property sheet manager uses this member to determine which version of thePROPSHEETHEADER structure you are using.

dwFlags
DWORD
Flags that indicate which options to use when creating the property sheet page. This member can be a combination of the following values.





标记那么多,只选一个我们需要的:



PSP_PREMATURE Version 4.71 or later. Causes the page to be created when the property sheet is created. If this flag is not specified, the page will not be created until it is selected the first time. This flag is not supported when using the Aero-style wizard (PSH_AEROWIZARD).






纳尼, prop1和prop2是构造函数。这个:

page1.m_psp.dwFlags |= PSP_PREMATURE;
page2.m_psp.dwFlags |= PSP_PREMATURE;

放哪里?

好吧,......构造函数
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值