/** * @param bIgnoreScrollPos - pass true to disregard any existing scrollbar styles. */ void CTextView::ResizeTextView(BOOL bIgnoreScrollPos) { TEXTMETRIC tmetr; GetTextMetrics(&tmetr); SCROLLINFO sinfo; RECT rcClient; GetClientRect(m_hwnd, &rcClient); ZeroMemory(&sinfo, sizeof(sinfo)); sinfo.cbSize = sizeof(sinfo); sinfo.fMask = SIF_POS | SIF_RANGE; GetScrollInfo(m_hwnd, SB_HORZ, &sinfo); int nOldHorPos = ! bIgnoreScrollPos ? sinfo.nPos : 0; sinfo.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; sinfo.nMin = 0; if (sinfo.nMax < m_nMaxLineWidth - 1) sinfo.nMax = m_nMaxLineWidth - 1; sinfo.nPage = rcClient.right; ValidateScrollInfo(&sinfo); int nHorOffset = nOldHorPos - sinfo.nPos; SetScrollInfo(m_hwnd, SB_HORZ, &sinfo, TRUE); GetClientRect(m_hwnd, &rcClient); ZeroMemory(&sinfo, sizeof(sinfo)); sinfo.cbSize = sizeof(sinfo); int nOldVertPos; if (! bIgnoreScrollPos) { sinfo.fMask = SIF_POS; GetScrollInfo(m_hwnd, SB_VERT, &sinfo); nOldVertPos = sinfo.nPos; } else nOldVertPos = sinfo.nPos = 0; int nNumLines = m_arrLines.GetCount(); sinfo.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; sinfo.nMin = 0; sinfo.nMax = nNumLines > 0 ? nNumLines - 1 : 0; sinfo.nPage = rcClient.bottom / tmetr.tmHeight; ValidateScrollInfo(&sinfo); int nVertOffset = (nOldVertPos - sinfo.nPos) * tmetr.tmHeight; SetScrollInfo(m_hwnd, SB_VERT, &sinfo, TRUE); GetClientRect(m_hwnd, &rcClient); // Explicitly clip output to override style CS_PARENTDC. ScrollWindowEx(m_hwnd, nHorOffset, nVertOffset, &rcClient, &rcClient, NULL, NULL, SW_INVALIDATE); UpdateWindow(m_hwnd); }
/** * @param bIgnoreScrollPos - pass true to disregard any existing scrollbar styles. */ void CImageView::ResizeImageView(BOOL bIgnoreScrollPos) { SCROLLINFO sinfo; RECT rcClient; GetClientRect(m_hwnd, &rcClient); ZeroMemory(&sinfo, sizeof(sinfo)); sinfo.cbSize = sizeof(sinfo); if (! bIgnoreScrollPos) { sinfo.fMask = SIF_POS; GetScrollInfo(m_hwnd, SB_HORZ, &sinfo); } else sinfo.nPos = 0; sinfo.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; sinfo.nMin = 0; sinfo.nMax = m_szAjustedBitmapSize.cx > 0 ? m_szAjustedBitmapSize.cx - 1 : 0; sinfo.nPage = rcClient.right; ValidateScrollInfo(&sinfo); SetScrollInfo(m_hwnd, SB_HORZ, &sinfo, TRUE); GetClientRect(m_hwnd, &rcClient); ZeroMemory(&sinfo, sizeof(sinfo)); sinfo.cbSize = sizeof(sinfo); if (! bIgnoreScrollPos) { sinfo.fMask = SIF_POS; GetScrollInfo(m_hwnd, SB_VERT, &sinfo); } else sinfo.nPos = 0; sinfo.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; sinfo.nMin = 0; sinfo.nMax = m_szAjustedBitmapSize.cy > 0 ? m_szAjustedBitmapSize.cy - 1 : 0; sinfo.nPage = rcClient.bottom; ValidateScrollInfo(&sinfo); SetScrollInfo(m_hwnd, SB_VERT, &sinfo, TRUE); InvalidateRect(m_hwnd, NULL, FALSE); }
/** * @param nScrollBarType - scrollbar type. * @param nScrollCode - scroll code. */ void CTextView::ScrollTextView(int nScrollBarType, int nScrollCode) { _ASSERTE(nScrollBarType == SB_HORZ || nScrollBarType == SB_VERT); SCROLLINFO sinfo; ZeroMemory(&sinfo, sizeof(sinfo)); sinfo.cbSize = sizeof(sinfo); sinfo.fMask = SIF_POS | SIF_PAGE | SIF_RANGE; if (nScrollCode == SB_THUMBTRACK) sinfo.fMask |= SIF_TRACKPOS; GetScrollInfo(m_hwnd, nScrollBarType, &sinfo); int nOldPos = sinfo.nPos; TEXTMETRIC tmetr; GetTextMetrics(&tmetr); int nLineOffset = nScrollBarType == SB_HORZ ? tmetr.tmAveCharWidth : 1; switch (nScrollCode) { case SB_LINEUP: //case SB_LINELEFT: sinfo.nPos -= nLineOffset; break; case SB_LINEDOWN: //case SB_LINERIGHT: sinfo.nPos += nLineOffset; break; case SB_PAGEUP: //case SB_PAGELEFT: sinfo.nPos -= sinfo.nPage; break; case SB_PAGEDOWN: //case SB_PAGERIGHT: sinfo.nPos += sinfo.nPage; break; case SB_THUMBTRACK: sinfo.nPos = sinfo.nTrackPos; break; case SB_TOP: //case SB_LEFT: sinfo.nPos = 0; break; case SB_BOTTOM: //case SB_RIGHT: sinfo.nPos = sinfo.nMax; break; default: return; } ValidateScrollInfo(&sinfo); sinfo.fMask = SIF_POS; SetScrollInfo(m_hwnd, nScrollBarType, &sinfo, TRUE); if (sinfo.nPos != nOldPos) { int nHorOffset, nVertOffset; if (nScrollBarType == SB_HORZ) { nHorOffset = nOldPos - sinfo.nPos; nVertOffset = 0; } else { nHorOffset = 0; nVertOffset = (nOldPos - sinfo.nPos) * tmetr.tmHeight; } RECT rcClient; GetClientRect(m_hwnd, &rcClient); // Explicitly clip output to override style CS_PARENTDC. ScrollWindowEx(m_hwnd, nHorOffset, nVertOffset, &rcClient, &rcClient, NULL, NULL, SW_INVALIDATE); UpdateWindow(m_hwnd); } }