怎么删除WTL动态创建出来的窗口

如何删除WTL动态创建出来的窗口
用new创建出来的窗口

在窗口被关闭的时候,这个窗口类不会自己析构。。

请问如何让窗口在被关闭的时候,自己析构。。

难道要用外部变量保存这个类的指针?

------解决方案--------------------
你点关闭不会有WM_DESTROY消息,只有WM_CLOSE,所以我说在WM_CLOSE里调用DestroyWindow
那你在WM_CLOSE试试这个
{
HWND hWnd = Detach();
::DestroyWindow(hWnd);
delete this;
}
这样在destroy之前先把对象和窗口分开
------解决方案--------------------
谢谢楼上的指点!我查了一下关于Detach()的用法,发现这段文章
use the Detach method:

{
CFont f;
f.CreateFont(...);
c_InputData.SetFont(&f);
f.Detach(); // VERY IMPORTANT!!!
}

The Detach operation dissociates the Windows object from its wrapper, and returns as its value the underlying Windows object handle. Since I don 't need it, I don 't bother to assign it to anything. But now, when the CFont is destroyed, the associated m_hObject handle is NULL and the underlying HFONT is not destroyed。
说的也就是楼上这位朋友说的意思。
原来,自己一直没有好好研究过这个问题,长见识了。再次感谢楼上朋友的指正!