Slider control

Slider
Slider

This is a sample of a window with a slider control. Download the solution(MS Visual Studio.NET)
#define   STRICT

#pragma comment(lib, "comctl32.lib")

#define  ID_SPLITTER    1

#include  <windows.h>
#include  <commctrl.h>

LRESULT CALLBACK WndProc(HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
{
   CREATESTRUCT            *cs;
   static   HWND           hWndSlider;
   static   DWORD          dwPos;

   switch (iMsg)
   {
   case WM_CREATE :
      cs = (LPCREATESTRUCT)lParam;
      hWndSlider = CreateWindow (TRACKBAR_CLASS, "",
         WS_CHILD | WS_VISIBLE | TBS_AUTOTICKS,
         10, 50, 200, 20,
         hwnd, (HMENU)ID_SPLITTER, cs->hInstance, NULL);
      break;

   case WM_HSCROLL :
      switch(wParam)
      {
      case TB_THUMBTRACK :
         dwPos = SendMessage(hWndSlider, TBM_GETPOS, 0, 0);
         break;
      }
      break;
   case WM_CLOSE :
      DestroyWindow(hwnd);
      break;
   case WM_DESTROY :
      PostQuitMessage(0);
      break;
   }
   return DefWindowProc(hwnd, iMsg, wParam, lParam);
}

int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)
{
   HWND        hwnd;
   MSG         msg;
   WNDCLASS    wndclass;
   char        szAppName[] = "Applicatie";

   wndclass.style         = 0;
   wndclass.lpfnWndProc   = WndProc;
   wndclass.cbClsExtra    = 0;
   wndclass.cbWndExtra    = 0;
   wndclass.hInstance     = hInstance;
   wndclass.hIcon         = LoadIcon(hInstance, szAppName);
   wndclass.hCursor       = LoadCursor(NULL, IDC_ARROW);
   wndclass.hbrBackground = (HBRUSH)(COLOR_BTNFACE + 1);
   wndclass.lpszMenuName  = szAppName;
   wndclass.lpszClassName = szAppName;
   RegisterClass(&wndclass);

   InitCommonControls();

   hwnd = CreateWindow(szAppName,
      szAppName,
      WS_OVERLAPPEDWINDOW | WS_VISIBLE,
      0, 0, 400, 400,
      NULL, NULL, hInstance, szCmdLine);

   while (GetMessage(&msg, NULL, 0, 0))
   {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
   }
   return (int)msg.wParam;
}
Articles
info@win32apicode.com