title: how to control scrollbar in vc++ win32 api
body: <p>basically i have a custom window which can carry other controls, let's say buttons, bitmaps, text boxes and etc, now the thing is that if the items went out of window, i mean if i tried to create like 20 button obviously it will go out of window, so i thought i should create a scroll bar to make the window scroll able. obviously you can't add WS_VSCROLL or WS_HSCROLL cause the up and down arrow of it won't be even clickable but if you tried to drag the thumb it will jump just back to the top. so i thought i better create a scroll bar with createwindow() function and control the rest of stuff.</p>
  
  <p>Here is the code how i create the window itself and the scroll bar:
  Code:</p>
  
  <pre><code>BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
  {
  hInst = hInstance; // Store instance handle in our global variable
  
  hWnd = CreateWindow(szWindowClass, "Name", WS_OVERLAPPEDWINDOW/*WS_OVERLAPPED | WS_MINIMIZEBOX | WS_SYSMENU*/,
    CW_USEDEFAULT, 0, 1014, 585, NULL, NULL, hInstance, NULL);
  
   if (!hWnd)
  {
    return FALSE;
  }
  
  WNDCLASSEX wcs;
  
  wcs.cbSize          = sizeof(wcs);
  wcs.lpszClassName   = szClassName;
  wcs.hInstance       = GetModuleHandle(0);
  wcs.lpfnWndProc     = CustWndProc;
  wcs.hCursor         = LoadCursor(NULL, IDC_ARROW);
  wcs.hIcon           = 0;
  wcs.lpszMenuName        = 0;
  wcs.hbrBackground   = (HBRUSH)(COLOR_WINDOW+1);
  wcs.style           = 0;
  wcs.cbClsExtra      = 0;
  wcs.cbWndExtra      = 0;
  wcs.hIconSm         = 0;
  
  if(!RegisterClassEx(&amp;wcs))
  {
      MessageBox(NULL, "Window Registration Failed!", "Error!",
          MB_ICONEXCLAMATION | MB_OK);
      return 0;
  }
  
  hwndCtrl = CreateWindowEx(
                       0L, // give it a standard border
                       szClassName,
                       _T("A custom control"),
                       WS_VISIBLE|WS_CHILD|WS_BORDER,
                       0, 0, 0, 0,
                       hWnd,
                       NULL, GetModuleHandle(0), CustWndProc
                     );
  ShowWindow (hwndCtrl, SW_SHOW);
  ShowWindow(hWnd, nCmdShow);
  UpdateWindow(hWnd);
  
  return TRUE;
  }
  </code></pre>
  
  <p>here is the code for handling its messages:</p>
  
  <pre><code>LRESULT CALLBACK CustWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
  {
  UNREFERENCED_PARAMETER(lParam);
  RECT rc = {};
  GetClientRect(hwnd, &amp;rc);
  const SIZE sz = { rc.right - rc.left, rc.bottom - rc.top };
  SCROLLINFO si;
  
  switch(msg)
  {
      case WM_MOUSEHOVER: 
          ::MessageBox(hwnd, "Enter", "Info", MB_OK); 
  
          return 0; 
  case WM_CREATE:
      int w , h;
      w = 10;
      h = 10;
      HWND buttons;
      for(h=10;h&lt;500; h+=35){
          buttons = CreateWindow("BUTTON", "How", WS_VISIBLE|WS_CHILD, w, h, 50, 30, hwnd, (HMENU)1231,NULL, NULL);
      }
      int width, height;
      width           = LOWORD(lParam);                                                   // Width Size of hWnd
      height          = HIWORD(lParam);
      Scrollbar  = CreateWindowEx(0L,
                     "SCROLLBAR",
                     NULL, // There is no text to display
                     WS_CHILD | WS_VISIBLE | SBS_VERT,
                     980,
                     47,
                     18,
                     405,
                     hWnd,
                     NULL,
                     hInst,
                     NULL
                  );
      return 0;
  case WM_INITDIALOG:
      ZeroMemory(&amp;si, sizeof(si));
      si.cbSize = sizeof(si);
      si.fMask  = SIF_RANGE | SIF_PAGE | SIF_POS;
      si.nMin   = 0;
      si.nMax   = 1000;
      si.nPage  = 10;
      si.nPos   = 54;
      SetScrollInfo(Scrollbar, SB_CTL, &amp;si, TRUE);
      return TRUE;
  
  
  default:
      return DefWindowProc(hwnd, msg, wParam, lParam);
  }
  return FALSE;
  }
  </code></pre>
  
  <p>as you can see there are some buttons which is automatically being created with for loop and after that the scroll bar itself is being created, now i don't know how to make it scroll down and up and so and so forth. 
  All replies are welcomed</p>