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

后端 未结 4 1962
栀梦
栀梦 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-15 23:56

    Based on the same MSDN description, I would assume that this means that if no CWnd is attached to the hWnd provided as an object, it will create a temporary CWnd which probably gets destroyed once something goes out of scope, or a destructor elsewhere is called, or a CWnd is explicitly created for the hWnd in question. So if you already have a CWnd created, you should be OK, otherwise you will probably need to be very careful with storing the pointer you receive.

提交回复
热议问题