home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / VISUAL_B / ARQS_ZIP / IKE.ZIP / SELECT.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-01-08  |  4.4 KB  |  158 lines

  1. /*===========================================================================*/
  2. /*                                                                           */
  3. /* File    : SELECT.C                                                        */
  4. /*                                                                           */
  5. /* Purpose : Routines to implement an outline for dragging and stretching a  */
  6. /*           graphical object.                                               */
  7. /*                                                                           */
  8. /* History : Most of this is from the SELECT example in the MS Win 3.0 SDK.  */
  9. /*                                                                           */
  10. /*===========================================================================*/
  11.  
  12. #include <windows.h>
  13. #include "ico.h"
  14.  
  15.  
  16. VOID PASCAL StartSelection(hWnd, ptCurrent, lpSelectRect, idTool)
  17.   HWND   hWnd;
  18.   POINT  ptCurrent;
  19.   LPRECT lpSelectRect;
  20.   int    idTool;
  21. {
  22.   if (lpSelectRect->left != lpSelectRect->right ||
  23.       lpSelectRect->top  != lpSelectRect->bottom)
  24.     ClearSelection(hWnd, lpSelectRect, idTool);
  25.  
  26.   lpSelectRect->left   = ptCurrent.x;
  27.   lpSelectRect->top    = ptCurrent.y;
  28.   lpSelectRect->right  = ptCurrent.x;
  29.   lpSelectRect->bottom = ptCurrent.y;
  30.   SetCapture(hWnd);
  31. }
  32.  
  33.  
  34. VOID PASCAL UpdateSelection(hWnd, ptCurrent, lpSelectRect, idTool)
  35.   HWND   hWnd;
  36.   POINT  ptCurrent;
  37.   LPRECT lpSelectRect;
  38.   int    idTool;
  39. {
  40.   HDC hDC;
  41.   short OldROP;
  42.  
  43.   hDC = GetDC(hWnd);
  44.  
  45.   OldROP = SetROP2(hDC, R2_NOTXORPEN);
  46.  
  47.  
  48.   switch (idTool)
  49.   {
  50.     case ID_OPENRECT :
  51.     case ID_FILLRECT :
  52.     case ID_SELECT   :
  53.       MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  54.       LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  55.       LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  56.       LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
  57.       LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  58.  
  59.       LineTo(hDC, ptCurrent.x, lpSelectRect->top);
  60.       LineTo(hDC, ptCurrent.x, ptCurrent.y);
  61.       LineTo(hDC, lpSelectRect->left, ptCurrent.y);
  62.       LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
  63.       break;
  64.  
  65.     case ID_LINE     :
  66.       MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  67.       LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  68.       MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  69.       LineTo(hDC, ptCurrent.x, ptCurrent.y);
  70.       break;
  71.  
  72.     case ID_CIRCLE   :
  73.     case ID_FILLCIRC :
  74.       MoveTo(hDC, lpSelectRect->left, lpSelectRect->top);
  75.       Ellipse(hDC, lpSelectRect->left, lpSelectRect->top,
  76.                    lpSelectRect->right, lpSelectRect->bottom);
  77.       Ellipse(hDC, lpSelectRect->left, lpSelectRect->top,
  78.                    ptCurrent.x, ptCurrent.y);
  79.       break;
  80.   }
  81.  
  82.   SetROP2(hDC, OldROP);
  83.   lpSelectRect->right = ptCurrent.x;
  84.   lpSelectRect->bottom = ptCurrent.y;
  85.   ReleaseDC(hWnd, hDC);
  86. }
  87.  
  88.  
  89. VOID PASCAL EndSelection(ptCurrent, lpSelectRect)
  90.   POINT  ptCurrent;
  91.   LPRECT lpSelectRect;
  92. {
  93.   lpSelectRect->right  = ptCurrent.x;
  94.   lpSelectRect->bottom = ptCurrent.y;
  95.   ReleaseCapture();
  96. }
  97.  
  98.  
  99. VOID PASCAL ClearSelection(hWnd, lpSelectRect, idTool)
  100.   HWND   hWnd;
  101.   LPRECT lpSelectRect;
  102.   int    idTool;
  103. {
  104.   HDC hDC;
  105.   short OldROP;
  106.  
  107.   hDC = GetDC(hWnd);
  108.  
  109.   OldROP = SetROP2(hDC, R2_NOTXORPEN);
  110.  
  111.   switch (idTool)
  112.   {
  113.     case ID_OPENRECT :
  114.     case ID_FILLRECT :
  115.     case ID_SELECT   :
  116.       MoveTo(hDC, lpSelectRect->left,  lpSelectRect->top);
  117.       LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
  118.       LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  119.       LineTo(hDC, lpSelectRect->left,  lpSelectRect->bottom);
  120.       LineTo(hDC, lpSelectRect->left,  lpSelectRect->top);
  121.       break;
  122.  
  123.     case ID_LINE     :
  124.       MoveTo(hDC, lpSelectRect->left,  lpSelectRect->top);
  125.       LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
  126.       break;
  127.  
  128.     case ID_CIRCLE   :
  129.     case ID_FILLCIRC :
  130.       Ellipse(hDC, lpSelectRect->left, lpSelectRect->top,
  131.                    lpSelectRect->right, lpSelectRect->bottom);
  132.       break;
  133.   }
  134.  
  135.   SetROP2(hDC, OldROP);
  136.   ReleaseDC(hWnd, hDC);
  137. }
  138.  
  139.  
  140. VOID PASCAL SortRect(LPRECT lpRect)
  141. {
  142.   int t;
  143.   
  144.   if (lpRect->top > lpRect->bottom)
  145.   {
  146.     t = lpRect->top;
  147.     lpRect->top = lpRect->bottom;
  148.     lpRect->bottom = t;
  149.   }
  150.  
  151.   if (lpRect->left > lpRect->right)
  152.   {
  153.     t = lpRect->left;
  154.     lpRect->left = lpRect->right;
  155.     lpRect->right = t;
  156.   }
  157. }
  158.