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. 

解决方案 »

  1.   

    有句柄返回句柄
    CWnd类的m_hWnd
      

  2.   

    CWnd * pWnd;
    HWnd hWnd = (HWND) pWnd;
      

  3.   

    看下面的类似CWnd的一个简单类:
    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就比较好。