home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / win_lrn / scroll / setscrng.c < prev    next >
C/C++ Source or Header  |  1988-08-10  |  3KB  |  79 lines

  1. /*
  2.  *  SetScrollRange
  3.  *  setscpos.c
  4.  *
  5.  *  This program demonstrates the use of the function SetScrollRange.
  6.  *  It sets the minimum and maximum position values for the scroll bar
  7.  *  of a window. If the minimum position equals the maximum position, 
  8.  *  then the scroll bar is removed.
  9.  *
  10.  */
  11.  
  12. #include "windows.h"
  13.  
  14. /* Procedure called when the application is loaded for the first time */
  15. BOOL WinInit( hInstance )
  16. HANDLE hInstance;
  17. {
  18.     WNDCLASS   wcClass;
  19.  
  20.     /* registering the parent window class */
  21.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  22.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  23.     wcClass.lpszMenuName   = (LPSTR)NULL;
  24.     wcClass.lpszClassName  = (LPSTR)"Setscrng";
  25.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  26.     wcClass.hInstance      = hInstance;
  27.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  28.     wcClass.lpfnWndProc    = DefWindowProc;
  29.     wcClass.cbClsExtra     = 0;
  30.     wcClass.cbWndExtra     = 0;
  31.  
  32.     RegisterClass( (LPWNDCLASS)&wcClass );
  33.     return TRUE;        /* Initialization succeeded */
  34. }
  35.  
  36.  
  37. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  38. HANDLE hInstance, hPrevInstance;
  39. LPSTR lpszCmdLine;
  40. int cmdShow;
  41. {
  42.     HWND         hWnd;                /* Handle to the parent window    */
  43.  
  44.     WinInit (hInstance);
  45.  
  46.     hWnd = CreateWindow((LPSTR)"Setscrng",
  47.                         (LPSTR)"Setting Scroll Range",
  48.                         WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
  49.                         50,                /* x         */
  50.                         50,                /* y         */
  51.                         600,               /* width     */
  52.                         250,               /* height    */
  53.                         (HWND)NULL,        /* no parent */
  54.                         (HMENU)NULL,       /* use class menu */
  55.                         (HANDLE)hInstance, /* handle to window instance */
  56.                         (LPSTR)NULL        /* no params to pass on */
  57.                        );
  58.  
  59.     /* Make window visible according to the way the app is activated */
  60.     ShowWindow( hWnd, cmdShow );
  61.     UpdateWindow( hWnd );
  62.  
  63.     /* Setting up the vertical and horizontal scroll bars range */
  64.     SetScrollRange (hWnd, SB_VERT, 1, 10, (BOOL)TRUE);
  65.     MessageBox (hWnd, (LPSTR)"The new range is set for the vertical scroll bar",
  66.                 (LPSTR)"Vertical", MB_OK);
  67.     
  68.     SetScrollRange (hWnd, SB_HORZ, 1, 20, (BOOL)TRUE);
  69.     MessageBox (hWnd, (LPSTR)"The new range is set for the horizontal scroll bar",
  70.                 (LPSTR)"Horizontal", MB_OK);
  71.  
  72.     /* removing the vertical scroll bar */
  73.     SetScrollRange (hWnd, SB_VERT, 0, 0, (BOOL)TRUE);
  74.     MessageBox (hWnd, (LPSTR)"The vertical scroll bar is now removed",
  75.                 (LPSTR)"Vertical", MB_OK);
  76.     
  77.     return 0;
  78. }
  79.