What is the lifetime of a CWnd obtained from CWnd::FromHandle?

后端 未结 4 1961
栀梦
栀梦 2020-12-15 23:21

According to msdn, when I get a CWnd* with CWnd::FromHandle,

The pointer may be temporary and should not be stored for later use.

<
4条回答
  •  被撕碎了的回忆
    2020-12-16 00:02

    MFC maintains a number of handle maps, from HWND to CWnd, HDC to CDC etc, which are stored in the thread state. Each handle map contains a permanent map and temporary map - permanent entries are added when you call a method such as CWnd::Create or CDC::Attach, while temporary entries are created when you call FromHandle on a handle that doesn't have a permanent entry.

    Temporary entries are cleaned up during idle processing (in CWinApp::OnIdle), so they can only safely be used while processing the current message. As soon as you return to the message loop, or enter another modal loop (e.g. by calling DoModal) then they may be deleted.

提交回复
热议问题