::SetWindowPos(GetDlgItem(IDC_LIST1)->GetSafeHwnd(), wndTop, rectList.left+5, rectList.top+64,rectList.Width()-9, rectList.Height()-69, SWP_NOMOVE);
GetDlgItem(IDC_LIST1)->SetWindowPos( &wndTop, rectList.left+5, rectList.top+64,rectList.Width()-9, rectList.Height()-69, SWP_NOMOVE);
这两条的运行结果怎么不一样,上面这条显示正常,下面这条一运行就告诉你“某某内存不能读”,MFC不是这样用的吗?

解决方案 »

  1.   

    还有一点,我用到的是List Control控件,不知道有没有关系
      

  2.   

    这样试一下,看行不行
    GetDlgItem(IDC_LIST1)->SetWindowPos( &CWnd::wndTop, rectList.left+5, rectList.top+64,rectList.Width()-9, rectList.Height()-69, SWP_NOMOVE);
      

  3.   

    毛病找出来了,代码
    GetDlgItem(IDC_LIST1)->SetWindowPos( &wndTop, rectList.left+5, rectList.top+64,rectList.Width()-9, rectList.Height()-69, SWP_NOMOVE);
    不能在重载的OnSize( UINT nType, int cx, int cy )函数中执行,在此函数中运行GetDlgItem(IDC_LIST1)->GetClientRect(rect);和
    GetDlgItem(IDC_LIST1)->GetWindowRect(rect);也会出错,在其他函数中运行就没有问题,OnSize( UINT nType, int cx, int cy )函数有什么不一样吗?
      

  4.   

    我试了一下,发现调用SetWindowPos()和系统会自动调用OnSize(), 所以会出问题 :)
      

  5.   

    毛病找出来了,代码
    GetDlgItem(IDC_LIST1)->SetWindowPos( &wndTop, rectList.left+5, rectList.top+64,rectList.Width()-9, rectList.Height()-69, SWP_NOMOVE);
    不能在重载的OnSize( UINT nType, int cx, int cy )函数中执行,在此函数中运行GetDlgItem(IDC_LIST1)->GetClientRect(rect);和
    GetDlgItem(IDC_LIST1)->GetWindowRect(rect);也会出错,在其他函数中运行就没有问题,OnSize( UINT nType, int cx, int cy )函数有什么不一样吗?