HINSTANCE hin; //those two global variables are defined at the beginning
WNDPROC ScrollPR;
// and ... i omitted the WinMain function because that just is a normal WinMain with Message Loop, WndClass inside
LRESULT CALLBACK ScrollProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
MessageBeep(0);
TCHAR szBuffer[16];
wsprintf(szBuffer, TEXT("%d"), GetLastError());
MessageBox(hwnd, szBuffer, NULL, MB_OK);
switch (message)
{
case WM_KEYDOWN:
MessageBeep(0);
break;
default:
break;
}
return DefWindowProc(ScrollPR, hwnd, message, wParam, lParam);//CallWindowProc(ScrollPR, hwnd, message, wParam, lParam);
}
LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
static RECT rect;
static int cxChar, cyChar;
HDC hdc;
PAINTSTRUCT ps;
int i;
LPDRAWITEMSTRUCT pdis;
TCHAR szBuffer[16];
static HWND ScrollBar;
static int pos;
switch (message)
{
case WM_CREATE:
cxChar = LOWORD(GetDialogBaseUnits());
cyChar = HIWORD(GetDialogBaseUnits());
ScrollBar = CreateWindow(
TEXT("scrollbar"),
NULL,
WS_CHILD | WS_VISIBLE | SBS_VERT | WS_TABSTOP,
10, 10, 20, 200,
hwnd,
(HMENU)1,
hin,
NULL
);
SetScrollRange(ScrollBar, SB_CTL, 0, 100, FALSE);
ScrollPR = GetWindowLongPtr(ScrollBar, GWLP_WNDPROC);
SetWindowLongPtr(ScrollBar, GWLP_WNDPROC, (LONG)ScrollProc);
return 0;
case WM_VSCROLL:
//SetWindowLong(lParam, GWLP_WNDPROC,(LONG) ScrollProc);
switch (wParam)
{
case SB_LINEDOWN:
pos++;
break;
default:
break;
}
pos = pos % 101;
SetScrollPos(ScrollBar, SB_CTL, pos, TRUE);
return 0;
case WM_SIZE:
rect.left = 24 * cxChar;
rect.top = 2 * cyChar;
rect.right = LOWORD(lParam);
rect.bottom = HIWORD(lParam);
return 0;
case WM_SETFOCUS:
SetFocus(ScrollBar);
return 0;
case WM_CTLCOLORSCROLLBAR:
return CreateSolidBrush(RGB(0, 0xFF, 0));
case WM_COMMAND:
switch (HIWORD(wParam))
{
case BN_CLICKED:
if (LOWORD(wParam) == 1)
{
MessageBeep(0);
}
default:
break;
}
return 0;
case WM_PAINT:
hdc = BeginPaint(hwnd, &ps);
EndPaint(hwnd, &ps);
return 0;
case WM_DESTROY:
PostQuitMessage(0);
return 0;
}
return DefWindowProc(hwnd, message, wParam, lParam);
}