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

  1. /*
  2. Function(s) demonstrated in this program: ScrollDC
  3. Compiler version: C 5.1
  4. Description:
  5. */
  6.  
  7. #include <windows.h>
  8. #include "scrdc.h"
  9.  
  10. static char szFuncName [] = "ScrollDC";
  11. static char szAppName [] = "SCRDC";
  12.  
  13. int PASCAL WinMain ( hInstance, hPrevInstance, lpszCmdLine, nCmdShow )
  14. HANDLE      hInstance, hPrevInstance;
  15. LPSTR       lpszCmdLine;
  16. int         nCmdShow;
  17. {
  18.      HWND        hWnd;
  19.      WNDCLASS    wndclass;
  20.      MSG         msg;
  21.      HMENU       hMenu;
  22.  
  23.      if (!hPrevInstance) {
  24.           wndclass.style         = CS_HREDRAW | CS_VREDRAW;
  25.           wndclass.lpfnWndProc   = WndProc;
  26.           wndclass.cbClsExtra    = 0;
  27.           wndclass.cbWndExtra    = 0;
  28.           wndclass.hInstance     = hInstance;
  29.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION);
  30.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW);
  31.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH);
  32.           wndclass.lpszMenuName  = "SCR";
  33.           wndclass.lpszClassName = szFuncName;
  34.  
  35.           if (!RegisterClass (&wndclass))
  36.                return FALSE;
  37.           }
  38.  
  39.      hMenu = LoadMenu ( hInstance, "SCR" );
  40.  
  41.  
  42.      hWnd = CreateWindow (szFuncName,           /* window class name       */
  43.                     szAppName,                  /* window caption          */
  44.                     WS_OVERLAPPEDWINDOW,        /* window style            */
  45.                     CW_USEDEFAULT,              /* initial x position      */
  46.                     0,                          /* initial y position      */
  47.                     CW_USEDEFAULT,              /* initial x size          */
  48.                     0,                          /* initial y size          */
  49.                     NULL,                       /* parent window handle    */
  50.                     hMenu,                      /* window menu handle      */
  51.                     hInstance,                  /* program instance handle */
  52.                     NULL);                      /* create parameters       */
  53.  
  54.      ShowWindow (hWnd, nCmdShow);
  55.      UpdateWindow (hWnd);
  56.  
  57.      while (GetMessage(&msg, NULL, 0, 0))
  58.      {
  59.       TranslateMessage(&msg);
  60.       DispatchMessage(&msg);
  61.      } 
  62.      return (msg.wParam);     
  63. }
  64.  
  65. long FAR PASCAL WndProc (hWnd, iMessage, wParam, lParam)
  66. HWND     hWnd;
  67. unsigned iMessage;
  68. WORD     wParam;
  69. LONG     lParam;
  70. {
  71.    HDC         hDC;
  72.    PAINTSTRUCT ps;
  73.    RECT        strRectangle;
  74.    RECT        strClipRectangle;
  75.    RECT        strDirtyRectangle;
  76.    HBRUSH      hSolidBrush;
  77.    BOOL        bfScrolled;
  78.    int         nIndex;
  79.  
  80.    switch(iMessage)
  81.    {
  82.    case WM_INITMENU:
  83.       InvalidateRect ( hWnd, (LPRECT)NULL, TRUE );
  84.       break;
  85.     case WM_COMMAND:
  86.        switch ( wParam )
  87.           {
  88.           case IDM_BOX:
  89.              strRectangle.top = 0;
  90.              strRectangle.bottom = 100;
  91.              strRectangle.left = 0;
  92.              strRectangle.right = 100;
  93.              strClipRectangle.top = 0;
  94.              strClipRectangle.bottom = 100;
  95.              strClipRectangle.left = 0;
  96.              strClipRectangle.right = 250;
  97.      
  98.              hDC = GetDC ( hWnd );
  99.              hSolidBrush = CreateSolidBrush ( 0xFF0000 );
  100.              FillRect ( hDC, (LPRECT)&strRectangle, hSolidBrush );
  101.      
  102.              MessageBox ( hWnd, (LPSTR)"Going to scroll the DC.",
  103.                 (LPSTR)szFuncName, MB_OK );
  104.      
  105.              bfScrolled = ScrollDC ( hDC, 110, 0, (LPRECT)&strRectangle,
  106.                 (LPRECT)&strClipRectangle, NULL, (LPRECT)&strDirtyRectangle );
  107.      
  108.              if ( bfScrolled == TRUE )
  109.                 {
  110.                 MessageBox ( hWnd, (LPSTR)"Going to invalidate the box.",
  111.                    (LPSTR)szFuncName, MB_OK );
  112.                 InvalidateRect ( hWnd, (LPRECT)&strRectangle, TRUE );
  113.                 }
  114.              else
  115.                 MessageBox ( hWnd, (LPSTR)"Could not scroll the DC.",
  116.                    (LPSTR)szFuncName, MB_OK | MB_ICONHAND );
  117.      
  118.              ReleaseDC ( hWnd, hDC );
  119.      
  120.              break;
  121.           default :
  122.              break;
  123.           }
  124.        break;
  125.      case WM_DESTROY:
  126.        PostQuitMessage(0);
  127.        break;
  128.      default:
  129.        return DefWindowProc (hWnd, iMessage, wParam, lParam);
  130.      return (0L); 
  131.    }
  132. }
  133.