rt
GetSafeHwnd 是状态判断函数,具体是什么作用啊,小弟看了msdn还是不明白
在线等回复!
CWnd::GetSafeHwnd
HWND GetSafeHwnd( ) const;Return ValueReturns the window handle for a window. Returns NULL if the CWnd is not attached to a window or if it is used with a NULL CWnd pointer.
GetSafeHwnd 是状态判断函数,具体是什么作用啊,小弟看了msdn还是不明白
在线等回复!
CWnd::GetSafeHwnd
HWND GetSafeHwnd( ) const;Return ValueReturns the window handle for a window. Returns NULL if the CWnd is not attached to a window or if it is used with a NULL CWnd pointer.
CWnd类的m_hWnd
HWnd hWnd = (HWND) pWnd;
class CTest1
{
public:
HWND GetSafeHwnd()
{
return this == NULL ? NULL : m_hWnd;
}
HWND m_hWnd;
};
----
然后看下面的调用
CTest1 *pt = NULL;
afxDump << pt->GetSafeHwnd();
afxDump << pt->m_hWnd;
第二行正常执行,第三行就发生异常了。
类似CWnd::GetDlgItem()的函数有可能返回NULL的CWnd指针,此时用GetSafeHwnd就比较好。