#242 CScrollImpl<T>::ScrollToView() works incorrectly

v1.0 (example)
closed-fixed
GDI (17)
5
2014-03-20
2010-11-21
Anonymous
No

The CScrollImpl<T>::ScrollToView(HWND hWnd) method does not take into account the offset of currently displayed portion of the window.

In the current implementation this method gets the coordinates of hWnd window relative to the upper left corner of currently displayed portion of the m_hWnd window. However, if the m_hWnd window has been already scrolled, the upper left corner of currently displayed area is not the point (0;0). This leads to strange behavior.

Current implementation:
void ScrollToView(HWND hWnd)
{
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));

RECT rect = { 0 };
::GetWindowRect(hWnd, &rect);
::MapWindowPoints(NULL, pT->m_hWnd, (LPPOINT)&rect, 2);
ScrollToView(rect);
}

Suggested fix:
void ScrollToView(HWND hWnd)
{
T* pT = static_cast<T*>(this);
ATLASSERT(::IsWindow(pT->m_hWnd));

RECT rect = { 0 };
::GetWindowRect(hWnd, &rect);
::MapWindowPoints(NULL, pT->m_hWnd, (LPPOINT)&rect, 2);
rect.left += m_ptOffset.x;
rect.right += m_ptOffset.x;
rect.top += m_ptOffset.y;
rect.bottom += m_ptOffset.y;
ScrollToView(rect);
}

In my case this fix made the scrolling behavior normal. Tested on XP, Vista, Win7.

Discussion


Anonymous


Cancel   Add attachments