home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / d / d020_1_4 / 6.ddi / SELECT / SELECT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-01  |  6.4 KB  |  211 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.    FUNCTION: LibMain(HANDLE, WORD, WORD, LPSTR)
  21.  
  22.    PURPOSE:  Is called by LibEntry.  LibEntry is called by Windows when
  23.              the DLL is loaded.  The LibEntry routine is provided in
  24.              the LIBENTRY.OBJ in the SDK Link Libraries disk.  (The
  25.              source LIBENTRY.ASM is also provided.)  
  26.  
  27.              LibEntry initializes the DLL's heap, if a HEAPSIZE value is
  28.              specified in the DLL's DEF file.  Then LibEntry calls
  29.              LibMain.  The LibMain function below satisfies that call.
  30.              
  31.              The LibMain function should perform additional initialization
  32.              tasks required by the DLL.  In this example, no initialization
  33.              tasks are required.  LibMain should return a value of 1 if
  34.              the initialization is successful.
  35.            
  36. *******************************************************************************/
  37. int FAR PASCAL LibMain(hModule, wDataSeg, cbHeapSize, lpszCmdLine)
  38. HANDLE    hModule;
  39. WORD    wDataSeg;
  40. WORD    cbHeapSize;
  41. LPSTR   lpszCmdLine;
  42. {
  43.     return 1;
  44. }
  45.  
  46.  
  47. /****************************************************************************
  48.     FUNCTION:  WEP(int)
  49.  
  50.     PURPOSE:  Performs cleanup tasks when the DLL is unloaded.  WEP() is
  51.               called automatically by Windows when the DLL is unloaded (no
  52.               remaining tasks still have the DLL loaded).  It is strongly
  53.               recommended that a DLL have a WEP() function, even if it does
  54.               nothing but returns success (1), as in this example.
  55.  
  56. *******************************************************************************/
  57. int FAR PASCAL WEP (bSystemExit)
  58. int  bSystemExit;
  59. {
  60.     return(1);
  61. }
  62.  
  63.  
  64. /****************************************************************************
  65.  
  66.     FUNCTION: StartSelection(HWND, POINT, LPRECT, int)
  67.  
  68.     PURPOSE: Begin selection of region
  69.  
  70. ****************************************************************************/
  71.  
  72. int FAR PASCAL StartSelection(hWnd, ptCurrent, lpSelectRect, fFlags)
  73. HWND hWnd;
  74. POINT ptCurrent;
  75. LPRECT lpSelectRect;
  76. int fFlags;
  77. {
  78.     if (lpSelectRect->left != lpSelectRect->right ||
  79.         lpSelectRect->top != lpSelectRect->bottom)
  80.     ClearSelection(hWnd, lpSelectRect, fFlags);
  81.  
  82.     lpSelectRect->right = ptCurrent.x;
  83.     lpSelectRect->bottom = ptCurrent.y;
  84.  
  85.     /* If you are extending the box, then invert the current rectangle */
  86.  
  87.     if ((fFlags & SL_SPECIAL) == SL_EXTEND)
  88.     ClearSelection(hWnd, lpSelectRect, fFlags);
  89.  
  90.     /* Otherwise, set origin to current location */
  91.  
  92.     else {
  93.     lpSelectRect->left = ptCurrent.x;
  94.     lpSelectRect->top = ptCurrent.y;
  95.     }
  96.     SetCapture(hWnd);
  97. }
  98.  
  99. /****************************************************************************
  100.  
  101.     FUNCTION: UpdateSelection(HWND, POINT, LPRECT, int) - update selection area
  102.  
  103.     PURPOSE: Update selection
  104.  
  105. ****************************************************************************/
  106.  
  107. int FAR PASCAL UpdateSelection(hWnd, ptCurrent, lpSelectRect, fFlags)
  108. HWND hWnd;
  109. POINT ptCurrent;
  110. LPRECT lpSelectRect;
  111. int fFlags;
  112. {
  113.     HDC hDC;
  114.     short OldROP;
  115.  
  116.     hDC = GetDC(hWnd);
  117.  
  118.     switch (fFlags & SL_TYPE) {
  119.  
  120.     case SL_BOX:
  121.         OldROP = SetROP2(hDC, R2_NOTXORPEN);
  122.         MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  123.         LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  124.         LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  125.         LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  126.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  127.         LineTo(hDC, ptCurrent.x, lpSelectRect->top);
  128.         LineTo(hDC, ptCurrent.x, ptCurrent.y);
  129.         LineTo(hDC, lpSelectRect->left, ptCurrent.y);
  130.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  131.         SetROP2(hDC, OldROP);
  132.         break;
  133.     
  134.     case SL_BLOCK:
  135.         PatBlt(hDC,
  136.         lpSelectRect->left,
  137.         lpSelectRect->bottom,
  138.         lpSelectRect->right - lpSelectRect->left,
  139.         ptCurrent.y - lpSelectRect->bottom,
  140.         DSTINVERT);
  141.         PatBlt(hDC,
  142.         lpSelectRect->right,
  143.         lpSelectRect->top,
  144.         ptCurrent.x - lpSelectRect->right,
  145.         ptCurrent.y - lpSelectRect->top,
  146.         DSTINVERT);
  147.         break;
  148.     }
  149.     lpSelectRect->right = ptCurrent.x;
  150.     lpSelectRect->bottom = ptCurrent.y;
  151.     ReleaseDC(hWnd, hDC);
  152. }
  153.  
  154. /****************************************************************************
  155.  
  156.     FUNCTION: EndSelection(POINT, LPRECT)
  157.  
  158.     PURPOSE: End selection of region, release capture of mouse movement
  159.  
  160. ****************************************************************************/
  161.  
  162. int FAR PASCAL EndSelection(ptCurrent, lpSelectRect)
  163. POINT ptCurrent;
  164. LPRECT lpSelectRect;
  165. {
  166.     lpSelectRect->right = ptCurrent.x;
  167.     lpSelectRect->bottom = ptCurrent.y;
  168.     ReleaseCapture();
  169. }
  170.  
  171. /****************************************************************************
  172.  
  173.     FUNCTION: ClearSelection(HWND, LPRECT, int) - clear selection area
  174.  
  175.     PURPOSE: Clear the current selection
  176.  
  177. ****************************************************************************/
  178.  
  179. int FAR PASCAL ClearSelection(hWnd, lpSelectRect, fFlags)
  180. HWND hWnd;
  181. LPRECT lpSelectRect;
  182. int fFlags;
  183. {
  184.     HDC hDC;
  185.     short OldROP;
  186.  
  187.     hDC = GetDC(hWnd);
  188.     switch (fFlags & SL_TYPE) {
  189.  
  190.     case SL_BOX:
  191.         OldROP = SetROP2(hDC, R2_NOTXORPEN);
  192.         MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  193.         LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  194.         LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  195.         LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  196.         LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  197.         SetROP2(hDC, OldROP);
  198.         break;
  199.  
  200.     case SL_BLOCK:
  201.         PatBlt(hDC,
  202.         lpSelectRect->left,
  203.         lpSelectRect->top,
  204.         lpSelectRect->right - lpSelectRect->left,
  205.         lpSelectRect->bottom - lpSelectRect->top,
  206.         DSTINVERT);
  207.         break;
  208.     }
  209.     ReleaseDC(hWnd, hDC);
  210. }
  211.