void MsgCrk_OnKey(HWND hWnd, UINT vk, BOOL fDown, int cRepeat, UINT flags)
{
switch (vk) {
case VK_UP:
SendMessage(hWnd, WM_VSCROLL, MAKELONG(SB_PAGEUP,0), 0);
break;
case VK_DOWN:
SendMessage(hWnd, WM_VSCROLL, MAKELONG(SB_PAGEDOWN,0), 0);
break;
case VK_LEFT:
SendMessage(hWnd, WM_HSCROLL, MAKELONG(SB_PAGELEFT,0), 0);
break;
case VK_RIGHT:
SendMessage(hWnd, WM_HSCROLL, MAKELONG(SB_PAGERIGHT,0), 0);
break;
}
}
void MsgCrk_OnHScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos)
{
// assert(hwndCtl == NULL)
int xInc;
xInc=0;
switch (code) {
case SB_LINELEFT:
xInc=-1;
break;
case SB_LINERIGHT:
xInc=1;
break;
case SB_PAGELEFT:
xInc=-20;
break;
case SB_PAGERIGHT:
xInc=20;
break;
case SB_THUMBTRACK:
xInc=pos-xPos;
break;
}
// 새로운 위치는 최소한 0 이상
if (xPos+xInc < 0)
xInc=-xPos;
// 새로운 위치는 최대한 xMax 이하
if (xPos+xInc > xMax)
xInc=xMax-xPos;
// 새로운 위치 계산
xPos=xPos+xInc;
// 스크롤시키고 썸 위치를 다시 계산한다. ScrollWindow(hWnd, -xInc, 0, NULL, NULL);
/*
or
InvalidateRect(hWnd, NULL, TRUE);
*/ SetScrollPos(hWnd, SB_HORZ, xPos, TRUE);
}
void MsgCrk_OnVScroll(HWND hWnd, HWND hwndCtl, UINT code, int pos)
{
int yInc;
yInc=0;
switch (code) {
case SB_LINEUP:
yInc=-1;
break;
case SB_LINEDOWN:
yInc=1;
break;
case SB_PAGEUP:
yInc=-20;
break;
case SB_PAGEDOWN:
yInc=20;
break;
case SB_THUMBTRACK:
//case SB_THUMBPOSITION:
yInc=pos-yPos;
break;
}
// 새로운 위치는 최소한 0 이상
if (yPos+yInc < 0)
yInc=-yPos;
// 새로운 위치는 최대한 yMax 이하
if (yPos+yInc > yMax)
yInc=yMax-yPos;
// yInc=max(-yPos, min(yInc, yMax-yPos));
// 새로운 위치 계산
yPos=yPos+yInc;
// 스크롤시키고 썸 위치를 다시 계산한다. ScrollWindow(hWnd, 0, -yInc, NULL, NULL); SetScrollPos(hWnd, SB_VERT, yPos, TRUE);
}
...
LRESULT CALLBACK WndProc(HWND hWnd,UINT iMessage,WPARAM wParam,LPARAM lParam)
{
switch (iMessage) {
HANDLE_MSG(hWnd, WM_CREATE, MsgCrk_OnCreate);
HANDLE_MSG(hWnd, WM_DESTROY, MsgCrk_OnDestroy);
HANDLE_MSG(hWnd, WM_SIZE, MsgCrk_OnSize);
HANDLE_MSG(hWnd, WM_KEYDOWN, MsgCrk_OnKey);
HANDLE_MSG (hWnd, WM_HSCROLL, MsgCrk_OnHScroll);
HANDLE_MSG (hWnd, WM_VSCROLL, MsgCrk_OnVScroll);
...
}