home *** CD-ROM | disk | FTP | other *** search
/ CICA 1992 November / CICA_MS_Windows_CD-ROM_Walnut_Creek_November_1992.iso / win3 / programr / listings / blx12 / wsbtest.cpp < prev   
Text File  |  1991-05-04  |  4KB  |  139 lines

  1. // wsbtest.cpp
  2. #include<windows.h>
  3. #include"winapp.h"
  4. #include"stdwin.h"
  5. #include<string.h>
  6. #include"winsb.h"
  7.  
  8. class WSBTest : public WinAppStdWindow
  9.     {
  10.     static WinClass wc;
  11.     WinScrollBar HScroll, VScroll;
  12.  
  13.     public:
  14.         static long FAR PASCAL WndProc(HWND hWnd,
  15.             unsigned iMsg, WORD wParam, LONG lParam);
  16.         WSBTest(WinApp *myApp, char *winname) :
  17.             WinAppStdWindow(myApp, &wc, winname)
  18.             {
  19.                 // insert calls to change window class info here
  20.             if(GetClassName() == NULL)
  21.                 {
  22.                 SetClassName("WSBTest");
  23.                 SetClassWinProc(WSBTest::WndProc);
  24.                 }
  25.             }
  26.  
  27.         void Paint(void)
  28.             {
  29.             PAINTSTRUCT ps;
  30.             HDC hdc = BeginPaint(GetHandle(), &ps);
  31.  
  32.             DispMessage(hdc);
  33.  
  34.             EndPaint(GetHandle(), &ps);
  35.             }
  36.  
  37.         void Display(void)
  38.             {
  39.             Window::Display();
  40.  
  41.             HScroll.Init(GetHandle(),SB_HORZ,0,512);
  42.             VScroll.Init(GetHandle(),SB_VERT,0L,20000);
  43.             HScroll.SetPageScroll(4);
  44.             VScroll.SetPageScroll(25);
  45.             HDC hdc = GetDC(GetHandle());
  46.             DispMessage(hdc);
  47.             ReleaseDC(GetHandle(),hdc);
  48.             }
  49.  
  50.         void WinScroll(unsigned msg, WORD wParam, LONG lParam);
  51.         void DispMessage(HDC hdc);
  52.     };
  53.  
  54. WinClass WSBTest::wc;
  55.  
  56. void WSBTest::WinScroll(unsigned msg, WORD wParam, LONG lParam)
  57.     {
  58.     HDC hDC = GetDC(GetHandle());
  59.  
  60.     switch(msg)
  61.         {
  62.         case WM_HSCROLL:
  63.             HScroll.ScrollUpdate(wParam, lParam);
  64.             break;
  65.         case WM_VSCROLL:
  66.             VScroll.ScrollUpdate(wParam, lParam);
  67.             break;
  68.         }
  69.     DispMessage(hDC);
  70.     ReleaseDC(GetHandle(),hDC);
  71.     }
  72.  
  73. void WSBTest::DispMessage(HDC hdc)
  74.     {
  75.     char buf[80];
  76.     char *fmt = "  %s: Current=%05d Minimum=%05d Maximum=%05d    ";
  77.  
  78.     wsprintf((LPSTR)buf,(LPSTR)fmt,(LPSTR)"    VERTICAL",
  79.         VScroll.GetCurPos(),
  80.         VScroll.GetMinPos(),
  81.         VScroll.GetMaxPos());
  82.     TextOut(hdc,0,0,(LPSTR)buf,strlen(buf));
  83.  
  84.     wsprintf((LPSTR)buf,(LPSTR)fmt,(LPSTR)"HORIZONTAL",
  85.         HScroll.GetCurPos(),
  86.         HScroll.GetMinPos(),
  87.         HScroll.GetMaxPos());
  88.     TextOut(hdc,0,40,(LPSTR)buf,strlen(buf));
  89.     }
  90.  
  91.  
  92. long FAR PASCAL _export WSBTest::WndProc(HWND hWnd, unsigned message,
  93.     WORD wParam, LONG lParam)
  94.     {
  95.     WSBTest *pWSBTest = (WSBTest *)GetPointer(hWnd);
  96.  
  97.     switch(message)
  98.         {
  99.         case WM_CREATE:                         // insert the pointer
  100.             pWSBTest = (WSBTest *)((LPCREATESTRUCT)lParam)->lpCreateParams;
  101.             SetPointer(hWnd, pWSBTest);
  102.             break;
  103.  
  104.         case WM_PAINT:
  105.             pWSBTest->Paint();                   // call Paint method
  106.             break;
  107.  
  108.         case WM_CLOSE:
  109.             DestroyWindow(hWnd);
  110.             break;
  111.  
  112.         case WM_DESTROY:
  113.             PostQuitMessage(0);
  114.             break;
  115.  
  116.         case WM_HSCROLL:
  117.         case WM_VSCROLL:
  118.             pWSBTest->WinScroll(message, wParam, lParam);
  119.             break;
  120.  
  121.         default:
  122.             return DefWindowProc(hWnd, message, wParam, lParam);
  123.         }
  124.     }
  125.  
  126. int PASCAL WinMain(HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine,
  127.                     int nCmdShow)
  128.     {
  129.         // create an instance of WinApp and initialize it
  130.     WinApp MyApp(hInstance, hPrevInstance, lpszCmdLine, nCmdShow);
  131.  
  132.         // create an instance of WSBTest for MyApp with winname, "Hello!"
  133.     WSBTest MyWin(&MyApp, "Scroll-Bar Test Window");
  134.     MyWin.Display();                    // open the window
  135.  
  136.     return MyApp.MessageLoop();         // process any messages
  137.     }
  138.  
  139.