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

  1. /*
  2.  
  3. Function(s) demonstrated in this program: ShowScrollBar
  4.  
  5. Description:  This function displays or hides a scroll bar, depending on the
  6.    value of the the parameters. 
  7.  
  8. */
  9.  
  10. #include <windows.h>
  11. #include <stdio.h>
  12. #include "ShowSB.h"
  13. char     szOutputBuffer1 [70];
  14. char     szOutputBuffer2 [500];
  15.  
  16. /****************************************************************************/
  17. /************************    Message Structure      *************************/
  18. /****************************************************************************/
  19.  
  20. struct { char *szMessage; }
  21.        Messages [] = {
  22. "About",
  23. "     This is a sample  application to demonstrate\n\
  24. the use of the ShowScrollBar Windows function.",
  25.  
  26. "Help Message",
  27. "     This program uses the ShowScrollBar Windows\n\
  28. function to change status of the Scroll bars of the\n\
  29. window.  Use the menu to choose the status (show or\n\
  30. hide)."
  31.  
  32. };    
  33.  
  34. /****************************************************************************/
  35.  
  36. void ProcessMessage (HWND, int); 
  37.  
  38. void ProcessMessage (hWnd, MessageNumber) 
  39.      HWND     hWnd;
  40.      int      MessageNumber;
  41. {
  42.      sprintf (szOutputBuffer1, "%s", Messages [MessageNumber]);
  43.      sprintf (szOutputBuffer2, "%s", Messages [MessageNumber + 1]);
  44.      MessageBox (hWnd, szOutputBuffer2, szOutputBuffer1, MB_OK);
  45. }       
  46.  
  47. /****************************************************************************/
  48.  
  49. int PASCAL WinMain (hInstance, hPrevInstance, lpszCmdLine, nCmdShow)
  50.      HANDLE   hInstance, hPrevInstance ;
  51.      LPSTR    lpszCmdLine ;
  52.      int      nCmdShow ;
  53.      {
  54.      WNDCLASS wndclass ;
  55.      HWND     hWnd ;
  56.      MSG      msg ;
  57.      static   char szAppName [] = "ShowSB" ;
  58.  
  59.      if (!hPrevInstance) 
  60.           {
  61.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  62.           wndclass.lpfnWndProc   = WndProc ;
  63.           wndclass.cbClsExtra    = 0 ;
  64.           wndclass.cbWndExtra    = 0 ;
  65.           wndclass.hInstance     = hInstance ;
  66.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  67.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  68.           wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  69.           wndclass.lpszMenuName  = szAppName ;
  70.           wndclass.lpszClassName = szAppName ;
  71.  
  72.           if (!RegisterClass (&wndclass))
  73.                return FALSE ;
  74.           }
  75.  
  76.      hWnd = CreateWindow (szAppName, "Show Scroll Bar",
  77.                          WS_OVERLAPPEDWINDOW | WS_HSCROLL | WS_VSCROLL,
  78.                          CW_USEDEFAULT, 0,
  79.                          CW_USEDEFAULT, 0,
  80.                          NULL, NULL, hInstance, NULL) ;
  81.  
  82.      ShowWindow (hWnd, nCmdShow) ;
  83.      UpdateWindow (hWnd) ;
  84.  
  85.      while (GetMessage (&msg, NULL, 0, 0))
  86.           {
  87.           TranslateMessage (&msg) ;
  88.           DispatchMessage (&msg) ;
  89.           }
  90.      return msg.wParam ;
  91.      }
  92.  
  93. /****************************************************************************/
  94.  
  95.  
  96. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  97.      HWND         hWnd ;
  98.      unsigned     iMessage ;
  99.      WORD         wParam ;
  100.      LONG         lParam ;
  101.      {
  102.      PAINTSTRUCT  ps ;
  103.      HMENU        hMenu;
  104.  
  105.      switch (iMessage)
  106.           {
  107.           case WM_CREATE:
  108.                hMenu = GetSystemMenu (hWnd, FALSE);
  109.                ChangeMenu (hMenu, NULL, "&About", IDM_ABOUT, 
  110.                            MF_APPEND | MF_STRING);
  111.                break ;
  112.  
  113.           case WM_SYSCOMMAND:
  114.                switch (wParam) {
  115.                   case IDM_ABOUT:
  116.                        ProcessMessage (hWnd, 0);
  117.                        break;
  118.                   default:
  119.                        return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  120.                }
  121.                break;
  122.  
  123.           case WM_COMMAND:
  124.                switch (wParam) {
  125.                   case IDM_ABOUT:
  126.                        ProcessMessage (hWnd, 0);
  127.                        break;
  128.  
  129.                   case IDM_SHOW:
  130.                        ShowScrollBar (hWnd, SB_BOTH, TRUE);
  131.                        break;
  132.         
  133.                   case IDM_HIDE:
  134.                        ShowScrollBar (hWnd, SB_BOTH, FALSE);
  135.                        break;
  136.         
  137.                   case IDM_HELP:
  138.                        ProcessMessage (hWnd, 2);
  139.                        break;
  140.                }
  141.                break;
  142.  
  143.           case WM_PAINT:
  144.                BeginPaint (hWnd, &ps) ;
  145.                EndPaint (hWnd, &ps) ;
  146.                break ;
  147.  
  148.           case WM_DESTROY:
  149.                PostQuitMessage (0) ;
  150.                break ;
  151.  
  152.           default:
  153.                return DefWindowProc (hWnd, iMessage, wParam, lParam) ;
  154.           }
  155.      return 0L ;
  156.      }
  157. 
  158.