If I call CDialog::SetWindow
on a dialog constructed as follows: CDialog *tmp=new CDialog(IDD_TEST, theParent);
, then it crashes. If I call, CDialog *tmp=new CDialog(); tmp->Create(IDD_TEST, theParent);
, then it doesn't. How开发者_如何学运维 come?
MFC is kind of funny that way. Creating a C++ object doesn't create a corresponding window; it's a two step process. Your second example does it exactly the way Microsoft intended, creating the C++ class and then creating the window it's supposed to control. If you try to call a window controlling function before the window exists, bad things will happen.
精彩评论