home *** CD-ROM | disk | FTP | other *** search
/ Microsoft Programmer's Library 1.3 / Microsoft-Programers-Library-v1.3.iso / sampcode / progwin / chap04 / blowup1.c next >
Encoding:
C/C++ Source or Header  |  1990-11-12  |  3.9 KB  |  121 lines

  1. /*------------------------------------------------
  2.    BLOWUP1.C -- Screen Capture Mouse Demo Program
  3.                (c) Charles Petzold, 1990
  4.   ------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. long FAR PASCAL WndProc (HWND, WORD, WORD, LONG) ;
  9.  
  10. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  11.                     LPSTR lpszCmdLine, int nCmdShow)
  12.      {
  13.      static char szAppName[] = "BlowUp1" ;
  14.      HWND        hwnd ;
  15.      MSG         msg ;
  16.      WNDCLASS    wndclass ;
  17.  
  18.      if (!hPrevInstance) 
  19.           {
  20.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  21.           wndclass.lpfnWndProc   = WndProc ;
  22.           wndclass.cbClsExtra    = 0 ;
  23.           wndclass.cbWndExtra    = 0 ;
  24.           wndclass.hInstance     = hInstance ;
  25.           wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  26.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  27.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  28.           wndclass.lpszMenuName  = NULL ;
  29.           wndclass.lpszClassName = szAppName ;
  30.  
  31.           RegisterClass (&wndclass) ;
  32.           }
  33.  
  34.      hwnd = CreateWindow (szAppName, "Blow-Up Mouse Demo",
  35.                          WS_OVERLAPPEDWINDOW,
  36.                          CW_USEDEFAULT, CW_USEDEFAULT,
  37.                          CW_USEDEFAULT, CW_USEDEFAULT,
  38.                          NULL, NULL, hInstance, NULL) ;
  39.  
  40.      ShowWindow (hwnd, nCmdShow) ;
  41.      UpdateWindow (hwnd) ;
  42.  
  43.      while (GetMessage (&msg, NULL, 0, 0))
  44.           {
  45.           TranslateMessage (&msg) ;
  46.           DispatchMessage (&msg) ;
  47.           }
  48.      return msg.wParam ;
  49.      }
  50.  
  51. void InvertBlock (HWND hwnd, POINT ptBeg, POINT ptEnd)
  52.      {
  53.      HDC hdc ;
  54.  
  55.      hdc = CreateDC ("DISPLAY", NULL, NULL, NULL) ;
  56.      ClientToScreen (hwnd, &ptBeg) ;
  57.      ClientToScreen (hwnd, &ptEnd) ;
  58.      PatBlt (hdc, ptBeg.x, ptBeg.y, ptEnd.x - ptBeg.x, ptEnd.y - ptBeg.y,
  59.              DSTINVERT) ;
  60.      DeleteDC (hdc) ;
  61.      }
  62.  
  63. long FAR PASCAL WndProc (HWND hwnd, WORD message, WORD wParam, LONG lParam)
  64.      {
  65.      static BOOL  fCapturing, fBlocking ;
  66.      static POINT ptBeg, ptEnd ;
  67.      HDC          hdc ;
  68.      RECT         rect ;
  69.  
  70.      switch (message)
  71.           {
  72.           case WM_LBUTTONDOWN:
  73.                if (!fCapturing)
  74.                     {
  75.                     fCapturing = TRUE ;
  76.                     SetCapture (hwnd) ;
  77.                     SetCursor (LoadCursor (NULL, IDC_CROSS)) ;
  78.                     }
  79.                else if (!fBlocking)
  80.                     {
  81.                     fBlocking = TRUE ;
  82.                     ptBeg = MAKEPOINT (lParam) ;
  83.                     }
  84.                return 0 ;
  85.  
  86.           case WM_MOUSEMOVE:
  87.                if (fBlocking)
  88.                     {
  89.                     ptEnd = MAKEPOINT (lParam) ;
  90.                     InvertBlock (hwnd, ptBeg, ptEnd) ;
  91.                     InvertBlock (hwnd, ptBeg, ptEnd) ;
  92.                     }
  93.                return 0 ;
  94.  
  95.           case WM_LBUTTONUP:
  96.                if (fBlocking)
  97.                     {
  98.                     fCapturing = fBlocking = FALSE ;
  99.                     ptEnd = MAKEPOINT (lParam) ;
  100.                     SetCursor (LoadCursor (NULL, IDC_WAIT)) ;
  101.  
  102.                     hdc = GetDC (hwnd) ; 
  103.                     GetClientRect (hwnd, &rect) ;
  104.                     StretchBlt (hdc, 0, 0, rect.right, rect.bottom,
  105.                                 hdc, ptBeg.x, ptBeg.y,
  106.                                 ptEnd.x - ptBeg.x, ptEnd.y - ptBeg.y,
  107.                                 SRCCOPY) ;
  108.  
  109.                     ReleaseDC (hwnd, hdc) ;
  110.                     SetCursor (LoadCursor (NULL, IDC_ARROW)) ;
  111.                     ReleaseCapture () ;
  112.                     }
  113.                return 0 ;
  114.  
  115.           case WM_DESTROY:
  116.                PostQuitMessage (0) ;
  117.                return 0 ;
  118.           }
  119.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  120.      }
  121.