📄 scrlbar.c
字号:
pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
{
int max = pSBar->maxPos;
max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
if (pSBar->curPos > max)
pSBar->curPos = max;
}
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
if (dwStyle == SBS_VERT)
{
wndGetVScrollBarRect (pWin, &rcBar);
rcBar.left --;
rcBar.right --;
}
else
{
wndGetHScrollBarRect (pWin, &rcBar);
rcBar.top --;
rcBar.bottom --;
}
wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);
#if 0
SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
#endif
return TRUE;
}
BOOL SetScrollInfoEx (HWND hWnd, int iSBar,
LPCSCROLLINFO lpsi, BOOL fRedraw) /* jmt: iSBar not used */
{
PMWSCROLLBARINFO pSBar;
HWND pWin;
RECT rcBar;
DWORD dwStyle; /* jmt:2k0820 */
pWin = (HWND)hWnd;
if ( !(pSBar = wndGetScrollBar (pWin)) )
return FALSE;
if( lpsi->fMask & SIF_RANGE )
{
pSBar->minPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMin:lpsi->nMax;
pSBar->maxPos = (lpsi->nMin < lpsi->nMax)?lpsi->nMax:lpsi->nMin;
}
if( lpsi->fMask & SIF_POS )
pSBar->curPos = lpsi->nPos;
if( lpsi->fMask & SIF_PAGE )
pSBar->pageStep = lpsi->nPage;
/* validate parameters. */
if (pSBar->curPos < pSBar->minPos)
pSBar->curPos = pSBar->minPos;
if (pSBar->pageStep <= 0)
pSBar->pageStep = 0;
else if (pSBar->pageStep > (pSBar->maxPos - pSBar->minPos + 1))
pSBar->pageStep = pSBar->maxPos - pSBar->minPos + 1;
{
int max = pSBar->maxPos;
max -= ((pSBar->pageStep - 1) > 0)?(pSBar->pageStep - 1):0;
if (pSBar->curPos > max)
pSBar->curPos = max;
}
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
if(fRedraw)
{
if (dwStyle == SBS_VERT)
{
wndGetVScrollBarRect (pWin, &rcBar);
rcBar.left --;
rcBar.right --;
}
else
{
wndGetHScrollBarRect (pWin, &rcBar);
rcBar.top --;
rcBar.bottom --;
}
wndScrollBarPos (pWin, dwStyle == SBS_HORZ, &rcBar);
#if 0
SendMessage (hWnd, WM_NCPAINT, 0, (LPARAM)(&rcBar));
#else
MwPaintScrollbars(hWnd,NULL,dwStyle); /* a must */
#endif
}
return TRUE;
}
BOOL GetScrollInfoEx(HWND hWnd, int iSBar, LPSCROLLINFO lpsi) /* jmt: iSBar not used */
{
PMWSCROLLBARINFO pSBar;
HWND pWin;
pWin = (HWND)hWnd;
if ( !(pSBar = wndGetScrollBar (pWin)) )
return FALSE;
if( lpsi->fMask & SIF_RANGE )
{
lpsi->nMin = pSBar->minPos;
lpsi->nMax = pSBar->maxPos;
}
if( lpsi->fMask & SIF_POS )
{
lpsi->nPos = pSBar->curPos;
}
if( lpsi->fMask & SIF_PAGE )
lpsi->nPage = pSBar->pageStep;
return TRUE;
}
BOOL ShowScrollBarEx (HWND hWnd, int iSBar, BOOL bShow) /* jmt: iSBar not used */
{
PMWSCROLLBARINFO pSBar;
HWND pWin;
BOOL bPrevState;
RECT rcBar;
DWORD dwStyle; /* jmt:2k0820 */
pWin = (HWND)hWnd;
if ( !(pSBar = wndGetScrollBar (pWin)) )
return FALSE;
bPrevState = !(pSBar->status & SBS_HIDE);
if (bShow && !bPrevState)
pSBar->status &= ~SBS_HIDE;
else if (!bShow && bPrevState)
pSBar->status |= SBS_HIDE;
else
return FALSE;
#if 0 /* fix: no WM_CHANGESIZE */
SendMessage (hWnd, WM_CHANGESIZE, 0, 0);
#endif
dwStyle = (GetWindowStyle (hWnd) & SBS_TYPEMASK); /* jmt: 2k0820 */
if (dwStyle == SBS_VERT)
wndGetVScrollBarRect (pWin, &rcBar);
else
wndGetHScrollBarRect (pWin, &rcBar);
{
RECT rcWin, rcClient;
memcpy (&rcWin, &pWin->winrect.left, sizeof (RECT));
rcClient.left = 0;
rcClient.top = 0;
rcClient.right = pWin->clirect.right - pWin->clirect.left;
rcClient.bottom = pWin->clirect.bottom - pWin->clirect.top;
#if 0 /* fix: no WM_SIZECHANGED */
SendMessage (hWnd, WM_SIZECHANGED,
(WPARAM)&rcWin, (LPARAM)&rcClient);
#endif
}
if (bShow) {
SendMessage (hWnd, WM_NCPAINT, 0, 0);
}
else {
rcBar.left -= pWin->clirect.left;
rcBar.top -= pWin->clirect.top;
rcBar.right -= pWin->clirect.left;
rcBar.bottom -= pWin->clirect.top;
SendMessage (hWnd, WM_NCPAINT, 0, 0);
InvalidateRect (hWnd, &rcBar, TRUE);
}
return TRUE;
}
static void sbSetScrollInfo (HWND hwnd, PMWSCROLLBARINFO pData, BOOL fRedraw) /* jmt:2k0820 */
{
SCROLLINFO si;
int itemCount,itemVisibles;
itemCount = pData->maxPos - pData->minPos + 1;
itemVisibles = pData->pageStep;
if (itemVisibles >= itemCount)
{
SetScrollPosEx (hwnd, 0, 0); /* jmt: arg2 not used */
EnableScrollBarEx (hwnd, 0, FALSE); /* jmt: arg2 not used */
return;
}
si.fMask = SIF_RANGE | SIF_PAGE | SIF_POS;
si.nMax = itemCount - 1;
si.nMin = 0;
si.nPage = itemVisibles; /* jmt(2k0819): new algorithm for SB_THUMBTRACK */
si.nPos = pData->curPos;
SetScrollInfoEx (hwnd, 0, &si, fRedraw); /* jmt: arg2 not used */
EnableScrollBarEx (hwnd, 0, TRUE); /* jmt: arg2 not used */
}
static LRESULT CALLBACK
ScrollbarControlProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) /* jmt:2k0820 */
{
DWORD dwStyle;
MWSCROLLBARINFO* pData;
int moveRange;
RECT rcBar;
dwStyle = (GetWindowStyle (hwnd) & SBS_TYPEMASK);
switch (message)
{
case WM_CREATE:
if (!(pData = GdMalloc (sizeof (MWSCROLLBARINFO))))
{
fprintf(stderr, "Create scroll bar control failure!\n");
return -1;
}
pData->minPos=0; /* min value of scroll range.*/
/* max value of scroll range.*/
pData->maxPos=0;
if (dwStyle==SBS_VERT)
moveRange=((hwnd->winrect.bottom-hwnd->winrect.top)
-((hwnd->winrect.right-hwnd->winrect.left)<<1));
else
moveRange=((hwnd->winrect.right-hwnd->winrect.left)
-((hwnd->winrect.bottom-hwnd->winrect.top)<<1));
if (moveRange > MWM_MINBARLEN)
{
pData->maxPos=moveRange / MWM_MINBARLEN;
if( (moveRange % MWM_MINBARLEN) )
pData->maxPos++;
}
printf("maxPos=%d\n",pData->maxPos);
pData->curPos=0; /* current scroll pos.*/
/* steps per page.*/
pData->pageStep=1;
if ( (pData->maxPos - 2) > 1)
pData->pageStep = pData->maxPos - 2;
printf("pageStep=%d\n",pData->pageStep);
pData->barStart=0; /* start pixel of bar.*/
pData->barLen=MWM_MINBARLEN; /* length of bar.*/
pData->status=SBS_UNKNOWN; /* status of scroll bar.*/
#if 0 /* jmt: must handle WM_MOVE */
pData->rc=hwnd->winrect; /* screen coordinates position*/
#endif
hwnd->userdata = (DWORD)pData;
if (dwStyle == SBS_VERT)
{
wndGetVScrollBarRect (hwnd, &rcBar);
rcBar.left --;
rcBar.right --;
}
else
{
wndGetHScrollBarRect (hwnd, &rcBar);
rcBar.top --;
rcBar.bottom --;
}
/* adjust pData->barLen */
wndScrollBarPos (hwnd, dwStyle == SBS_HORZ, &rcBar);
break;
case WM_DESTROY:
free ((void *)(hwnd->userdata));
break;
case WM_PAINT:
MwPaintScrollbars(hwnd,NULL,dwStyle);
break;
case WM_NCLBUTTONDOWN:
case WM_NCLBUTTONDBLCLK:
case WM_NCMOUSEMOVE:
case WM_NCLBUTTONUP:
MwHandleMessageScrollbar(hwnd, wParam, lParam, message, dwStyle);
break;
case WM_HSCROLL:
case WM_VSCROLL:
{
int newTop,itemCount,itemVisibles;
pData = (MWSCROLLBARINFO *)hwnd->userdata;
newTop = pData->curPos;
itemCount = pData->maxPos - pData->minPos + 1;
itemVisibles = pData->pageStep;
switch(wParam)
{
case SB_LINEDOWN:
#define ITEM_BOTTOM(x) (x->curPos + itemVisibles - 1)
if (ITEM_BOTTOM (pData) < (itemCount - 1 ))
{
newTop ++;
}
break;
case SB_LINEUP:
if (pData->curPos > 0)
{
newTop --;
}
break;
case SB_PAGEDOWN:
if ((pData->curPos + (itemVisibles << 1)) <=
itemCount)
newTop += itemVisibles;
else
newTop = itemCount - itemVisibles;
if (newTop < 0)
return 0;
break;
case SB_PAGEUP:
if (pData->curPos >= itemVisibles)
newTop -= itemVisibles;
else
newTop = 0;
break;
case SB_THUMBTRACK:
newTop = (int)lParam;
break;
}
pData->curPos = newTop;
SendMessage (hwnd, WM_PAINT, 0, 0);
sbSetScrollInfo (hwnd, pData, TRUE);
return 0;
}
break;
default:
return DefWindowProc (hwnd, message, wParam, lParam);
}
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -