Article ID: 155918
Article Last Modified on 11/21/2006
/* Compile options needed: none
The class 'CScrollFormView' is derived from CFormView
*/
HBRUSH CScrollFormView::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
HBRUSH hbr = CFormView::OnCtlColor(pDC, pWnd, nCtlColor);
if (GetFocus()->m_hWnd == pWnd->m_hWnd)
{
CRect rcChild, rcParent, rcTemp;
pWnd->GetWindowRect(&rcChild);
GetWindowRect(&rcParent);
//Get document size. Assume mapping mode is MM_TEXT and ViewPort
//and Window origins have not been set so we can also assume LP==DP.
CSize size = GetTotalSize();
// Determine if scroll bars are visible
// and subtract their size from the view.
if (size.cx > rcParent.right - rcParent.left)
rcParent.bottom -= GetSystemMetrics(SM_CYHSCROLL);
if (size.cy > rcParent.bottom - rcParent.top)
rcParent.right -= GetSystemMetrics(SM_CXVSCROLL);
// Succeed only if no part of the child appears in the parent.
rcTemp.IntersectRect(rcChild, rcParent);
if (rcTemp != rcChild)
{
POINT pt;
pt.x = GetDeviceScrollPosition().x;
pt.y = GetDeviceScrollPosition().y;
if (rcChild.top < rcParent.top)
{
TRACE("control is above the client area\n");
pt.y -= rcParent.top - rcChild.top +
GetSystemMetrics(SM_CXEDGE);
}
else if (rcChild.bottom > rcParent.bottom)
{
TRACE("control is below the client area\n");
// If the control is taller than the current view
// scroll up, sacrificing the bottom of the control.
pt.y += min(rcChild.top - rcParent.top,
rcChild.bottom - rcParent.bottom +
GetSystemMetrics(SM_CYHSCROLL) +
GetSystemMetrics(SM_CXEDGE));
}
if (rcChild.left < rcParent.left)
{
TRACE("control is left of the client area\n");
pt.x -= rcParent.left - rcChild.left +
GetSystemMetrics(SM_CYEDGE);
}
else if (rcChild.right > rcParent.right)
{
TRACE("control is right of the client area\n");
// If the control is wider than the current view
// scroll right, sacrificing the right edge of the control.
pt.x += min(rcChild.left - rcParent.left,
rcChild.right - rcParent.right +
GetSystemMetrics(SM_CXVSCROLL) +
GetSystemMetrics(SM_CYEDGE));
}
ScrollToPosition(pt); //Assume mapping mode is MM_TEXT.
}
}
// TODO: Return a different brush if the default is not desired.
return hbr;
}
Additional query words: 4.00 4.10 4.20 kbdsi
Keywords: kbcode kbdocview kbhowto kbscrollbar kbuidesign KB155918