在childfrm里调用getwindowrect和movewindow,view是scrollview。1. getwindowrect(rect);
2. movewindow(rect);
3. getwindowrect(rect);然后对比1和3中的rect,就发现已经不在通一个位置上了。在我印象中,这两个函数应该对应的都是屏幕坐标阿,怎么会产生这种差异呢?请高手指教。谢谢

解决方案 »

  1.   

    是屏幕坐標沒錯 但是參數表示的意義不同
    GetWindowRect獲得的是left top right bottom坐標
    而傳給MoveWindow的矩形left top意義沒變 right bottom則分別是你要設定窗口為多寬、多高
    如果你確信需要這樣的操作

    CRect rect;
    GetWindowRect(rect);
    rect.right =  rect.Width();
    rect.bottom = rect.Height();
    MoveWindow(rect);
    GetWindowRect(rect);
      

  2.   

    好像并非像你说的那样阿,下面是我的实验结果:trace出来的:
    src rcWindow at the beginning: left:45, right:722, top:126, bottom:483 //step 1
    src rcWindow before MoveWindow: left:45, right:677, top:126, bottom:357 //step 2
    dest rcWindow after MoveWindow: left:73, right:705, top:231, bottom:462 //step 3
    最终窗口的upleft位置变了,而且窗口变小了。。
      

  3.   

    MoveWindow:
    For a top-level CWnd object, the x and y parameters are relative to the upper-left corner of the screen. For a child CWnd object, they are relative to the upper-left corner of the parent window's client area.
      

  4.   

    估計你從來不看msdn的
    那我也引一段:
    CWnd::MoveWindow
    void MoveWindow( int x, int y, int nWidth, int nHeight, BOOL bRepaint = TRUE );void MoveWindow( LPCRECT lpRect, BOOL bRepaint = TRUE );ParametersxSpecifies the new position of the left side of the CWnd.ySpecifies the new position of the top of the CWnd.nWidthSpecifies the new width of the CWnd.nHeightSpecifies the new height of the CWnd.
    lpRectThe CRect object or RECT structure that specifies the new size and position.顯然 lpRect的參數對應于int x, int y, int nWidth, int nHeight,