[MFC] OnVScroll 의 nPos 파라미터의 사용제한

afx_msg void OnVScroll(
   UINT nSBCode,
   UINT nPos,
   CScrollBar* pScrollBar 
);

nPos
Contains the current scroll-box position if the scroll-bar code is SB_THUMBPOSITION or SB_THUMBTRACK; otherwise not used. Depending on the initial scroll range, nPos may be negative and should be cast to an int if necessary.


여기서 nPos 값이 32,767을 넘어버리면 음수로 들어오게 되어 난감할 때가 있습니다.
(int)로 type casing을 해도 음수이니..
왜 그런가 하고 찾아보니 아래와 같이 나와있더군요.

The difference between the values specified by nMinPos and nMaxPos must not be greater than 32,767. The default range for a scroll-bar control is empty (both nMinPos and nMaxPos are 0).



이럴 때는

SCROLLINFO scInfo;
scInfo.cbSize = sizeof(SCROLLINFO);
scInfo.fMask = SIF_RANGE;
GetScrollInfo(&scInfo);

이런식으로 스크롤바의 정보를 얻어와서
scInfo.nTrackPos를nPos 파라미터 대신 사용하시면 됩니다.

chaoskcuf
tags : ,
프로그래밍/TIP& Study 2007/01/15 22:14

트랙백 주소 : http://chaoskcuf.com/trackback/46

댓글을 달아 주세요

Powerd by Textcube, designed by criuce
rss