在lbuttondown响应函数中
CRect rect;
GetDlgItem(IDD_CONTROL)->GetClientRect(&rect);
if(point.x>rect.left&&point.x<rect.right&&point.y<rect.bottom&&point.y>rect.top)
{
AfxMessageBox(test);
}
这样好像不行,为什么?

解决方案 »

  1.   

    你应该将得到的矩形转换成相对于对话框的坐标。GetClientRect得到的是相对于按钮的坐标。用ClientToScreen可以转换。
      

  2.   

    WINDOWPLACEMENT wp;
    RECT r;
    GetDlgItem(IDC_FR_REFLECTCOLOR)->GetWindowPlacement(&wp);
    r=wp.rcNormalPosition;
    if(point.x>r.left&&point.x<r.right
    point.y>r.top&&point.y<r.bottom)
    {.............}
      

  3.   

    有一个函数,好像是IsRect(point)不是rect的就是point,查查msdn
      

  4.   

    CRect::PtInRect 
    BOOL PtInRect( POINT point ) const;Return ValueNonzero if the point lies within CRect; otherwise 0.ParameterspointContains a POINT structure or CPoint object.ResDetermines whether the specified point lies within CRect. A point is within CRect if it lies on the left or top side or is within all four sides. A point on the right or bottom side is outside CRect.Note   The rectangle must be normalized or this function may fail. You can call NormalizeRect to normalize the rectangle before calling this function.
      

  5.   

    PtInRect
    是针对
    CRECT类或者其派生类的吧,我的是控件,例如picture控件
      

  6.   

    happyparrot(快乐鹦鹉) 能不能详细一点,什么叫相对于按钮的坐标???第一次听说
      

  7.   

    问题解决 zhucde(【風間苍月】)(MVP)的方法很管用
    还有一种方法是CRect rect;
    GetwindowRect(&rect);
    ScreenToClient(&rect);
    if(point.x>rect.left&&point.x<rect.right&&point.y<rect.bottom&&point.y>rect.top)
    {
    AfxMessageBox(test);
    }
    谢谢大家的热心帮助