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;

放哪里?

好吧,......构造函数

你可能感兴趣的:(MFC学习之路,wizard,structure,struct,manager,basic,access)