开发者

`CDialog::SetWindowPos` crashing

开发者 https://www.devze.com 2023-02-19 07:19 出处:网络
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, thePar

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消