子窗口没有收到 WM_DESTROY? [英] Child windows does not receive WM_DESTROY?

查看:53
本文介绍了子窗口没有收到 WM_DESTROY?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我把winapi CreateWindowEx 打包成一个简单的类.由于每个窗口共享同一个wndProc(hwnd,msg,wparam,lparam),我把CreateWindowEx创建的每个窗口放到一个map中分发msg,如下:

I packaged the winapi CreateWindowEx into a simple class. Since every window sharing a same wndProc(hwnd,msg,wparam,lparam), I put every window created by CreateWindowEx into a map to distribute msg, like this:

wndProc(hwnd, msg, wparam, lparam){
    if(map[hwnd]!=nil){
        switch(msg){
            map[hwnd].wndProc(...)
        }
    }
}

并且每次窗口或其父窗口被销毁时,将其从地图中删除:

And each time a window or its parent window being destroyed, remove it from the map:

case WM_DESTROY: delete(map, hwnd)

但是按钮之类的东西不会收到 WM_DESTROY.我在 WM_NOTIFY 和 WM_COMMAND 中打印了所有消息,但我注意到了.

But things like buttons do not receive WM_DESTROY. I printed all msg in WM_NOTIFY and WM_COMMAND but i got noting.

那么我怎样才能在正确的时间从地图上移除这些子窗口呢?或者一种无需创建 hwnd 映射即可分发 msg 的方法?

So how can I remove those child windows form the map at the right time? Or a way distribute the msg without creating a hwnd map?

推荐答案

他们当然确实得到了这个消息.但是它们的窗口过程在 Windows 内部,而不是在您的程序内部.所以你永远不会看到它.您可以在 MSDN 文档,注意 WM_DESTROY 没有得到任何特殊处理.也不生成您的父窗口可以看到的通知.

They certainly do get that message. But their window procedure is inside Windows, not inside your program. So you never see it. Something you can read in the MSDN documentation, note how WM_DESTROY doesn't get any special treatment. Nor generate a notification that your parent window can see.

当您看到父窗口被破坏时,自动删除所有子窗口,子类化控件 是 C++ 类库包装器的标准要求.顺便说一句,最好不要自己发明,这已经做过很多次了.

Short from automatically removing all the child windows when you see the parent window destroyed, subclassing controls is a pretty standard requirement for C++ class library wrappers. Best to not invent your own btw, this has been done many times already.

这篇关于子窗口没有收到 WM_DESTROY?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆