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