如题

解决方案 »

  1.   

    CRect rt ; 
    GetWindowRect(&rt) ;
      

  2.   

    比如在MDI的框架类中
    要得到视图指针
    CMDIFrameWnd *pFrame = 
                 (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;// Get the active MDI child window.
    CMDIChildWnd *pChild = 
                 (CMDIChildWnd *) pFrame->GetActiveFrame();// or CMDIChildWnd *pChild = pFrame->MDIGetActive();// Get the active view attached to the active MDI child
    // window.
    CMyView *pView = (CMyView *) pChild->GetActiveView();
      

  3.   

    然后就可以得到对应视图的尺寸了
    CRect rt ; 
    pView->GetWindowRect(&rt) ;
      

  4.   

    如果你用SDK,你创建CreateWindow(Ex)时可以保存句柄的
      

  5.   

    to SeainBlue(爱海) :
    -------------------------
    比如在MDI的框架类中
    要得到视图指针
    CMDIFrameWnd *pFrame = 
                 (CMDIFrameWnd*)AfxGetApp()->m_pMainWnd;// Get the active MDI child window.
    CMDIChildWnd *pChild = 
                 (CMDIChildWnd *) pFrame->GetActiveFrame();// or CMDIChildWnd *pChild = pFrame->MDIGetActive();// Get the active view attached to the active MDI child
    // window.
    CMyView *pView = (CMyView *) pChild->GetActiveView();
    -------------------------
    这段代码加在哪?
      

  6.   

    这段代码只是msdn上的例子
    你可以根据你自己的程序的特点增加到不同的位置
      

  7.   

    你的程序是基于MDI还是SDI的?你要在什么位置得到视图的大小位置
      

  8.   

    在视图中调用最简单了CRect rt ; 
    pView->GetWindowRect(&rt) ;返回得rt就保存了当前视图的位置坐标
      

  9.   

    我的程序是MDI窗体
    我现在已经获得了客户区的区域
    但是left和top总是0
    我想获得当前客户区的
    top left heigth width
    (相对于桌面来说)
      

  10.   

    还有
    为什么heigth 和width
    总是一个常数?
    不懂
      

  11.   

    我试验没错的
    比如在视图客户区鼠标左键单击,得到视图客户区范围void CLView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CRect rt ; 
    GetWindowRect(&rt) ;
    int height = rt.Height ;
    int width = rt.Width ; 
    CView::OnLButtonDown(nFlags, point);
    }
      

  12.   

    你跟踪一下,height和width都不是0而且,如果移动子窗口或者改变子窗口大小
    这两个值是改变的
      

  13.   

    int height = rt.Height ;
    int width = rt.Width ; 
    出错
    --------------------------
    C:\zhuatu\zhuatuView.cpp(119) : error C2664: 'CreateCompatibleBitmap' : cannot convert parameter 2 from 'int (void) const' to 'int'
            Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast
    C:\zhuatu\zhuatuView.cpp(123) : error C2664: 'BitBlt' : cannot convert parameter 3 from 'int (void) const' to 'int'
            Conversion is a valid standard conversion, which can be performed implicitly or by use of static_cast, C-style cast or function-style cast
    ---------------------------
      

  14.   

    void CLView::OnLButtonDown(UINT nFlags, CPoint point) 
    {
    // TODO: Add your message handler code here and/or call default
    CRect rt ; 
    GetWindowRect(&rt) ;
    CString left ;
    left.Format("%ld",rt.left) ;
    CString top;
    top.Format("%ld",rt.top ) ; 
    AfxMessageBox(left) ; 
    AfxMessageBox(top) ;  CView::OnLButtonDown(nFlags, point);
    }
      

  15.   

    RECT没有width和height
    有左上角和右下角坐标,可以通过这两点坐标算出高度和宽度
    试试我上面的做法,这回没错了
      

  16.   

    如果需要高度和宽度
    可以这样:
    long width  = rt.right - rt.left ; 
    long height = rt.bottom- rt.top ;