开发者

Where to call DestroyWindow() of an MFC dialog?

开发者 https://www.devze.com 2023-03-18 12:26 出处:网络
I\'m curently working on dialogs in an M开发者_运维百科FC application and I\'m – admittedly – quite new to MFC.

I'm curently working on dialogs in an M开发者_运维百科FC application and I'm – admittedly – quite new to MFC.

Let's say I have class A (derived from CDialog) that uses class B (also derived from CDialog). Thus, A::OnInitDialog() calls the create(...) method of B.

I saw now that the destructor of class B contains

if ( GetSafeHwnd() )
{
    DestroyWindow();
}

Is this okay? In my understanding it would be better to call B's DestroyWindow()method in A::OnDestroy(). Is that right?

Thanks for your help!

Oliver


One thing you may have noticed as you've delved in to MFC is that it is a wrapper API and not strictly object-orientated. Whereas we would like to use RAII (Resource Acquisition Is Initialisation), MFC does not create windows in its constructor. It does it, as you rightly point out, through the Create() method.

Therefore it makes more sense to me, given the way MFC works, To destroy B when A is being destroy (A::OnDestroy), so I think you're going down the right path.

0

精彩评论

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

关注公众号