home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c480 / 19.ddi / SAMPLES / BITMAP / SELECT.C_ / SELECT.C
Encoding:
C/C++ Source or Header  |  1993-02-08  |  4.5 KB  |  155 lines

  1. /****************************************************************************
  2.  
  3.     PROGRAM: Select.c
  4.  
  5.     PURPOSE: Contains library routines for selecting a region
  6.  
  7.     FUNCTIONS:
  8.  
  9.     StartSelection(HWND, POINT, LPRECT, int) - begin selection area
  10.     UpdateSelection(HWND, POINT, LPRECT, int) - update selection area
  11.     EndSelection(POINT, LPRECT) - end selection area
  12.     ClearSelection(HWND, LPRECT, int) - clear selection area
  13.  
  14. *******************************************************************************/
  15.  
  16. #include "windows.h"
  17. #include "select.h"
  18.  
  19.  
  20.  
  21. /****************************************************************************
  22.  
  23.     FUNCTION: StartSelection(HWND, POINT, LPRECT, int)
  24.  
  25.     PURPOSE: Begin selection of region
  26.  
  27. ****************************************************************************/
  28.  
  29. void StartSelection(HWND hWnd, POINT ptCurrent, LPRECT lpSelectRect, int fFlags)
  30. {
  31.     if (lpSelectRect->left != lpSelectRect->right ||
  32.         lpSelectRect->top != lpSelectRect->bottom)
  33.     ClearSelection(hWnd, lpSelectRect, fFlags);
  34.  
  35.     lpSelectRect->right = ptCurrent.x;
  36.     lpSelectRect->bottom = ptCurrent.y;
  37.  
  38.     /* If you are extending the box, then invert the current rectangle */
  39.  
  40.     if ((fFlags & SL_SPECIAL) == SL_EXTEND)
  41.     ClearSelection(hWnd, lpSelectRect, fFlags);
  42.  
  43.     /* Otherwise, set origin to current location */
  44.  
  45.     else {
  46.     lpSelectRect->left = ptCurrent.x;
  47.     lpSelectRect->top = ptCurrent.y;
  48.     }
  49.     SetCapture(hWnd);
  50. }
  51.  
  52. /****************************************************************************
  53.  
  54.     FUNCTION: UpdateSelection(HWND, POINT, LPRECT, int) - update selection area
  55.  
  56.     PURPOSE: Update selection
  57.  
  58. ****************************************************************************/
  59.  
  60. void UpdateSelection(HWND hWnd, POINT ptCurrent, LPRECT lpSelectRect, int fFlags)
  61. {
  62.     HDC hDC;
  63.     short OldROP;
  64.  
  65.     hDC = GetDC(hWnd);
  66.  
  67.     switch (fFlags & SL_TYPE) {
  68.  
  69.     case SL_BOX:
  70.         OldROP = SetROP2(hDC, R2_NOTXORPEN);
  71.         MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  72.         LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  73.         LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  74.         LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  75.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  76.         LineTo(hDC, ptCurrent.x, lpSelectRect->top);
  77.         LineTo(hDC, ptCurrent.x, ptCurrent.y);
  78.         LineTo(hDC, lpSelectRect->left, ptCurrent.y);
  79.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  80.         SetROP2(hDC, OldROP);
  81.         break;
  82.     
  83.     case SL_BLOCK:
  84.         PatBlt(hDC,
  85.         lpSelectRect->left,
  86.         lpSelectRect->bottom,
  87.         lpSelectRect->right - lpSelectRect->left,
  88.         ptCurrent.y - lpSelectRect->bottom,
  89.         DSTINVERT);
  90.         PatBlt(hDC,
  91.         lpSelectRect->right,
  92.         lpSelectRect->top,
  93.         ptCurrent.x - lpSelectRect->right,
  94.         ptCurrent.y - lpSelectRect->top,
  95.         DSTINVERT);
  96.         break;
  97.     }
  98.     lpSelectRect->right = ptCurrent.x;
  99.     lpSelectRect->bottom = ptCurrent.y;
  100.     ReleaseDC(hWnd, hDC);
  101. }
  102.  
  103. /****************************************************************************
  104.  
  105.     FUNCTION: EndSelection(POINT, LPRECT)
  106.  
  107.     PURPOSE: End selection of region, release capture of mouse movement
  108.  
  109. ****************************************************************************/
  110.  
  111. void EndSelection(POINT ptCurrent, LPRECT lpSelectRect)
  112. {
  113.     lpSelectRect->right = ptCurrent.x;
  114.     lpSelectRect->bottom = ptCurrent.y;
  115.     ReleaseCapture();
  116. }
  117.  
  118. /****************************************************************************
  119.  
  120.     FUNCTION: ClearSelection(HWND, LPRECT, int) - clear selection area
  121.  
  122.     PURPOSE: Clear the current selection
  123.  
  124. ****************************************************************************/
  125.  
  126. void ClearSelection(HWND hWnd, LPRECT lpSelectRect, int fFlags)
  127. {
  128.     HDC hDC;
  129.     short OldROP;
  130.  
  131.     hDC = GetDC(hWnd);
  132.     switch (fFlags & SL_TYPE) {
  133.  
  134.     case SL_BOX:
  135.         OldROP = SetROP2(hDC, R2_NOTXORPEN);
  136.         MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  137.         LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  138.         LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  139.         LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  140.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  141.         SetROP2(hDC, OldROP);
  142.         break;
  143.  
  144.     case SL_BLOCK:
  145.         PatBlt(hDC,
  146.         lpSelectRect->left,
  147.         lpSelectRect->top,
  148.         lpSelectRect->right - lpSelectRect->left,
  149.         lpSelectRect->bottom - lpSelectRect->top,
  150.         DSTINVERT);
  151.         break;
  152.     }
  153.     ReleaseDC(hWnd, hDC);
  154. }
  155.