RECT  r; 
SetRect(  &r,  20,  80,  150,  90  );
RedrawWindow(&r);
这样可以刷新指定区域了,可是这个坐标不能准确获得。
MSDN上这样说void SetRect(int x1,int y1,int x2,int y2 )x1
    Specifies the x-coordinate of the upper-left corner.
y1
    Specifies the y-coordinate of the upper-left corner.
x2
    Specifies the x-coordinate of the lower-right corner.
y2
    Specifies the y-coordinate of the lower-right corner.我这里Static控件左上角坐标是(20,80),长130,高10
按照VC里头显示的控件的坐标刷新,发现该刷新的区域没刷新,不该刷新的区域在刷新(闪烁)。
这个坐标究竟如何确定?难道VC里头现实的坐标不是真实坐标吗?

解决方案 »

  1.   

    RedrawWindow(&r);的前面用的是哪一个对象指针?正确的应该是CStatic的,否则,只是刷新窗口,而不是Static;另外,使用了CStatic对象指针后,刷新的坐标可以用GetClientRect获得,即起始点应该为(0,0)。
      

  2.   

    其实我刷新的不是Static控件,是它所在的区域。我移动了下对话框,发现刷新部分相对于对话框的位置没有变,似乎不用GetClientRect。
    只是这个坐标与预期位置不符,很奇怪。
    刷新窗口的目的是解决文本重叠的问题。
      

  3.   

    注意GetWindowRect和GetClientRect的区别
      

  4.   

    我做了个按钮做测试CWnd *pWnd=GetDlgItem(IDC_STATIC);
    if ( pWnd )
    {
    CRect rc; 
    pWnd->GetWindowRect( &rc );
    ScreenToClient( &rc );
    int a=rc.left;
    int b=rc.top;
    CString left,top;
    left.Format(_T("%d"),a);
    top.Format(_T("%d"),b);
    MessageBox(left,top);
    }点击后发现IDC_STATIC起点是(40,180)
    而资源文件显示是(20,80)
    证明了资源文件中的坐标不是我想要的坐标。这是怎么回事?
      

  5.   

    用GetWindowRect可以获得控件座标啊。还可以使用ScreenToClient将座标转换为窗体内的座标。