Tuesday, 10 September 2013

CScrollView Offset Client Rect with Scroll Position

CScrollView Offset Client Rect with Scroll Position

I am trying to write a function that will work out if the window that
currently has focus is entirely shown in the client rect of my CScrollView
but I am struggling to work out what I am doing wrong. This is what I have
thus far:
CWnd * pWnd = pView->GetFocus();
if(pWnd)
{
CRect winRect;
pWnd->GetWindowRect(&winRect);
pView->ScreenToClient(&winRect); //pView is a pointer the CScrollView
CRect viewRect;
pView->GetClientRect(&viewRect);
CPoint currentScrollPoint = pView->GetScrollPosition();
viewRect.OffsetRect(currentScrollPoint);
if(!(viewRect.PtInRect(winRect.BottomRight()) &&
viewRect.PtInRect(winRect.TopLeft())))
{
//Not shown fully
}
}
Can anyone see what I am doing wrong here or suggest a better way of doing
this?

No comments:

Post a Comment