GetWindowRect (AfxGetMainWnd()->GetSafeHwnd (),&ClientRect);是对的
GetWindowRect (AfxGetMainWnd()->m_hWnd,&ClientRect);是错的呢?第一个参数都是CWnd类型的参数啊,也都是获得句柄啊
我实在是想不明白,请各位解释一下?

解决方案 »

  1.   

    第二句也没错吧
    关于GetSafeHwnd与m_hWnd的区别,见
    http://expert.csdn.net/Expert/topic/2172/2172590.xml?temp=.6769678
      

  2.   

    CWnd::GetSafeHwnd  
    HWND GetSafeHwnd( ) const;Return Value
    Returns 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.
      

  3.   

    AfxGetMainWnd()->m_hWnd是私有变量,不能直接读取。
      

  4.   

    是私有变量好像有点说不通,如果我改成这样就是对的:
    GetWindowRect (m_hWnd,&ClientRect);但我试过,是可以通过的,也达到了我的要求
      

  5.   

    搞笑.两种方法编译都通过的.效果一样.但是当窗口还没创建的时候,AfxGetMainWnd()->m_hWnd有运行时错误.
    还有看调用的时机
    如果恰好在CXXXApp::InitInstance()
    {
    ...
    m_pMainWnd被初始化之前调用,则运行时出错,因为AfxGetMainFrame()得到的是空指针.
    }