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

  1. /*
  2.  *
  3.  *  GetScrollRange
  4.  *
  5.  *  This program demonstrates the use of the function GetScrollRange.
  6.  *  It retrieves the current minimum and maximum scroll bar range
  7.  *  for the given scroll bar. 
  8.  *
  9.  *  Windows Version 2.0 function demonstration application
  10.  *
  11.  */
  12.  
  13. #include "windows.h"
  14. #include "stdio.h"
  15.  
  16. /* Procedure called when the application is loaded for the first time */
  17. BOOL WinInit( hInstance )
  18. HANDLE hInstance;
  19. {
  20.     WNDCLASS   wcClass;
  21.  
  22.     /* registering the parent window class */
  23.     wcClass.hCursor        = LoadCursor( NULL, IDC_ARROW );
  24.     wcClass.hIcon          = LoadIcon (hInstance, (LPSTR)"WindowIcon");
  25.     wcClass.lpszMenuName   = (LPSTR)NULL;
  26.     wcClass.lpszClassName  = (LPSTR)"Getscrng";
  27.     wcClass.hbrBackground  = (HBRUSH)GetStockObject( WHITE_BRUSH );
  28.     wcClass.hInstance      = hInstance;
  29.     wcClass.style          = CS_HREDRAW | CS_VREDRAW;
  30.     wcClass.lpfnWndProc    = DefWindowProc;
  31.     wcClass.cbClsExtra     = 0;
  32.     wcClass.cbWndExtra     = 0;
  33.  
  34.     RegisterClass( (LPWNDCLASS)&wcClass );
  35.     return TRUE;        /* Initialization succeeded */
  36. }
  37.  
  38.  
  39. int PASCAL WinMain( hInstance, hPrevInstance, lpszCmdLine, cmdShow )
  40. HANDLE hInstance, hPrevInstance;
  41. LPSTR lpszCmdLine;
  42. int cmdShow;
  43. {
  44.     HWND  hWnd;                /* Handle to the parent window    */
  45.     short nMinPos, nMaxPos;    /* The range of the scroll bar    */
  46.     char  szBuffer[50];        /* string buffer for the message  
  47.                                 * box                            */
  48.  
  49.     WinInit (hInstance);
  50.  
  51.     hWnd = CreateWindow((LPSTR)"Getscrng",
  52.                         (LPSTR)"GetScrollRange",
  53.                         WS_OVERLAPPEDWINDOW|WS_VSCROLL,
  54.                         50,                /* x         */
  55.                         50,                /* y         */
  56.                         600,               /* width     */
  57.                         250,               /* height    */
  58.                         (HWND)NULL,        /* no parent */
  59.                         (HMENU)NULL,       /* use class menu */
  60.                         (HANDLE)hInstance, /* handle to window instance */
  61.                         (LPSTR)NULL        /* no params to pass on */
  62.                        );
  63.  
  64.     /* Make window visible according to the way the app is activated */
  65.     ShowWindow( hWnd, cmdShow );
  66.     UpdateWindow( hWnd );
  67.  
  68.     /* Setting up the vertical scroll bar range and use GETSCROLLRANGE
  69.      * to retrieve the range
  70.      */
  71.     SetScrollRange (hWnd, SB_VERT, 1, 10, (BOOL)TRUE);
  72.     GetScrollRange (hWnd, SB_VERT, (LPINT) &nMinPos, (LPINT) &nMaxPos);
  73.     sprintf (szBuffer, "The range of the scroll bar is between %d and %d", 
  74.              nMinPos, nMaxPos);
  75.     MessageBox (hWnd, (LPSTR)szBuffer, (LPSTR)"GetScrollRange", MB_OK);
  76.  
  77.     return 0;
  78. }
  79.  
  80.