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

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