Links to the original text: http://www.cnblogs.com/leaf-w/archive/2011/04/21/2023759.html
This paper is only suitable for window background rolling with the foreground, not for fixed background.
First, add the style WS_VSCROLL (vertical scrollbar) to the window.
Then process OnSize:
void CUserRegisterDlg::OnSize(UINT nType, int cx, int cy) { CDialogBase::OnSize(nType, cx, cy); // TODO: Add your message handler code here OnVScroll(SB_TOP,0,NULL); SetScrollRange(SB_VERT, 0, THEME->GetScreenPortraitSize().cy/*Screen height*/ - TORP(52)/*Title bar menu bar*/ - cy); }
To process OnVScroll:
#define SW_STYLE SW_SCROLLCHILDREN|SW_INVALIDATE|SW_ERASE void CUserRegisterDlg::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* pScrollBar) { // TODO: Add your message handler code here and/or call default SCROLLINFO scrollinfo; GetScrollInfo(SB_VERT,&scrollinfo); int& nPosFrom = scrollinfo.nPos; int nPosTo = nPos; switch (nSBCode) { case SB_BOTTOM: nPosTo = scrollinfo.nMax; goto label; case SB_TOP: nPosTo = scrollinfo.nMin; goto label; case SB_LINEUP: nPosTo = scrollinfo.nPos - TORP(5); if (scrollinfo.nPos == scrollinfo.nMin) break; else if (nPosTo < scrollinfo.nMin) nPosTo = scrollinfo.nMin; goto label; case SB_LINEDOWN: nPosTo = scrollinfo.nPos + TORP(5); if (scrollinfo.nPos == scrollinfo.nMax) break; else if (nPosTo > scrollinfo.nMax) nPosTo = scrollinfo.nMax; goto label; case SB_PAGEUP: nPosTo = scrollinfo.nPos - TORP(130); if (scrollinfo.nPos == scrollinfo.nMin) break; else if (nPosTo < scrollinfo.nMin) nPosTo = scrollinfo.nMin; goto label; case SB_PAGEDOWN: nPosTo = scrollinfo.nPos + TORP(130); if (scrollinfo.nPos == scrollinfo.nMax) break; else if (nPosTo > scrollinfo.nMax) nPosTo = scrollinfo.nMax; goto label; case SB_THUMBPOSITION: if(scrollinfo.nPos==scrollinfo.nMax && (nPos>scrollinfo.nMax) ) break; goto label; case SB_THUMBTRACK: if(scrollinfo.nPos==scrollinfo.nMax && (nPos>scrollinfo.nMax) ) break; goto label; label: SetScrollPos(SB_VERT, nPosTo); ScrollWindowEx(0, nPosFrom - nPosTo, NULL, NULL, NULL, NULL, SW_STYLE); UpdateWindow(); break; case SB_ENDSCROLL: break; } CDialogBase::OnVScroll(nSBCode, nPos, pScrollBar); }
Running time found that when the input method was open when the dialog box was just opened, the window rect did not automatically adjust according to the position of the input method, so the scroll bar did not appear. It can be solved with the following code:
#include <Sipapi.h> BOOL CUserRegisterDlg::OnInitDialog() { CDialogBase::OnInitDialog(); // TODO: Add extra initialization here SIPINFO si = {0}; si.cbSize = sizeof(si); SHSipInfo(SPI_GETSIPINFO, 0, &si, 0); BOOL bShow = si.fdwFlags&SIPF_ON; if (bShow) { MoveWindow(&si.rcVisibleDesktop); } return FALSE; // return TRUE unless you set the focus to a control // EXCEPTION: OCX Property Pages should return FALSE }
Reprinted at: https://w w w.cnblogs.com/leaf-w/archive/2011/04/21/2023759.html