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

  1. /*
  2.  *  SetScrollPos
  3.  *  setscpos.c
  4.  *
  5.  *  This program demonstrates the use of the function SetScrollPos.
  6.  *  It sets the current position of a scroll bar elevator to a specified 
  7.  *  position and redraws the scroll bar to reflect the new position, if 
  8.  *  requested.
  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)"Setscpos";
  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. 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.  
  43.     WinInit (hInstance);
  44.  
  45.     hWnd = CreateWindow((LPSTR)"Setscpos",
  46.                         (LPSTR)"Setting Scroll Position",
  47.                         WS_OVERLAPPEDWINDOW|WS_VSCROLL|WS_HSCROLL,
  48.                         50,                /* x         */
  49.                         50,                /* y         */
  50.                         600,               /* width     */
  51.                         250,               /* height    */
  52.                         (HWND)NULL,        /* no parent */
  53.                         (HMENU)NULL,       /* use class menu */
  54.                         (HANDLE)hInstance, /* handle to window instance */
  55.                         (LPSTR)NULL        /* no params to pass on */
  56.                        );
  57.  
  58.     /* Make window visible according to the way the app is activated */
  59.     ShowWindow( hWnd, cmdShow );
  60.     UpdateWindow( hWnd );
  61.  
  62.     /* Setting up the vertical and horizontal scroll bars range */
  63.     SetScrollRange (hWnd, SB_VERT, 1, 10, (BOOL)TRUE);
  64.     SetScrollRange (hWnd, SB_HORZ, 1, 10, (BOOL)TRUE);
  65.  
  66.     /* initial position on a vertical scroll bar */
  67.     SetScrollPos   (hWnd, SB_VERT, 2, (BOOL)TRUE);
  68.     MessageBox (hWnd, (LPSTR)"The scroll bar elevator is near the top", 
  69.                 (LPSTR)"Vertical", MB_OK);
  70.  
  71.     /* moved to a new location */
  72.     SetScrollPos (hWnd, SB_VERT, 9, (BOOL)TRUE);
  73.     MessageBox (hWnd, (LPSTR)"Now the scroll bar elevator is set to another location",
  74.                 (LPSTR)"Vertical", MB_OK);
  75.  
  76.     /* initial position on a vertical scroll bar */
  77.     SetScrollPos   (hWnd, SB_HORZ, 2, (BOOL)TRUE);
  78.     MessageBox (hWnd, (LPSTR)"The scroll bar elevator is near the left", 
  79.                 (LPSTR)"Horizontal", MB_OK);
  80.  
  81.     /* moved to a new location */
  82.     SetScrollPos (hWnd, SB_HORZ, 9, (BOOL)TRUE);
  83.     MessageBox (hWnd, (LPSTR)"Now the scroll bar elevator is set to another location",
  84.                 (LPSTR)"Horizontal", MB_OK);
  85.  
  86.     return 0;
  87. }
  88.