Reputation: 723
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?
Upvotes: 2
Views: 1617
Reputation: 5132
The comments to the question above cleared up the actual intent of the question:
...when I tab to one that is not shown by the current client rect I want to scroll
to display that `CEdit`...
I found two articles searching MSDN for CFormView scroll tab key
:
OnCtlColor()
to check if a sub-window has the focus and is not in view; it uses ScrollToPosition()
ScrollToPosition()
does not work in Windows CE (both the articles are quite old!), checks for WM_KEYUP
of the tab key in PreTranslateMessage()
and uses it's own ScrollToPos()
function to scroll the control into view (this article was meant for Windows CE and you will need to replace wce_GetNextWindow
by GetNextWindow
Upvotes: 2