Annotation of mstools/samples/select/select.c, revision 1.1

1.1     ! root        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, DWORD, LPVOID)
        !            21: 
        !            22:    PURPOSE:  LibMain is called by Windows when
        !            23:              the DLL is initialized, Thread Attached, and other times.
        !            24:              Refer to SDK documentation, as to the different ways this
        !            25:              may be called.
        !            26:              
        !            27:              The LibMain function should perform additional initialization
        !            28:              tasks required by the DLL.  In this example, no initialization
        !            29:              tasks are required.  LibMain should return a value of 1 if
        !            30:              the initialization is successful.
        !            31:            
        !            32: *******************************************************************************/
        !            33: INT  APIENTRY LibMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved)
        !            34: {
        !            35:     return 1;
        !            36:        UNREFERENCED_PARAMETER(hInst);
        !            37:        UNREFERENCED_PARAMETER(ul_reason_being_called);
        !            38:        UNREFERENCED_PARAMETER(lpReserved);
        !            39: }
        !            40: 
        !            41: 
        !            42: /****************************************************************************
        !            43: 
        !            44:     FUNCTION: StartSelection(HWND, POINT, LPRECT, int)
        !            45: 
        !            46:     PURPOSE: Begin selection of region
        !            47: 
        !            48: ****************************************************************************/
        !            49: 
        !            50: INT APIENTRY StartSelection(
        !            51:     HWND hWnd,
        !            52:     MPOINT ptCurrent,
        !            53:     LPRECT lpSelectRect,
        !            54:     INT fFlags)
        !            55: {
        !            56:     if (lpSelectRect->left != lpSelectRect->right ||
        !            57:            lpSelectRect->top != lpSelectRect->bottom)
        !            58:        ClearSelection(hWnd, lpSelectRect, fFlags);
        !            59: 
        !            60:     lpSelectRect->right = ptCurrent.x;
        !            61:     lpSelectRect->bottom = ptCurrent.y;
        !            62: 
        !            63:     /* If you are extending the box, then invert the current rectangle */
        !            64: 
        !            65:     if ((fFlags & SL_SPECIAL) == SL_EXTEND)
        !            66:        ClearSelection(hWnd, lpSelectRect, fFlags);
        !            67: 
        !            68:     /* Otherwise, set origin to current location */
        !            69: 
        !            70:     else {
        !            71:        lpSelectRect->left = ptCurrent.x;
        !            72:        lpSelectRect->top = ptCurrent.y;
        !            73:     }
        !            74:     SetCapture(hWnd);
        !            75:     return 1;
        !            76: }
        !            77: 
        !            78: /****************************************************************************
        !            79: 
        !            80:     FUNCTION: UpdateSelection(HWND, POINT, LPRECT, int) - update selection area
        !            81: 
        !            82:     PURPOSE: Update selection
        !            83: 
        !            84: ****************************************************************************/
        !            85: 
        !            86: INT APIENTRY UpdateSelection(
        !            87:     HWND hWnd,
        !            88:     MPOINT ptCurrent,
        !            89:     LPRECT lpSelectRect,
        !            90:     INT fFlags)
        !            91: {
        !            92:     HDC hDC;
        !            93:     SHORT OldROP;
        !            94: 
        !            95:     hDC = GetDC(hWnd);
        !            96: 
        !            97:     switch (fFlags & SL_TYPE) {
        !            98: 
        !            99:        case SL_BOX:
        !           100:            OldROP = (SHORT)SetROP2(hDC, R2_NOTXORPEN);
        !           101:            MoveToEx(hDC, lpSelectRect->left, lpSelectRect->top, NULL);
        !           102:            LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
        !           103:            LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
        !           104:            LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
        !           105:            LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
        !           106:            LineTo(hDC, ptCurrent.x, lpSelectRect->top);
        !           107:            LineTo(hDC, ptCurrent.x, ptCurrent.y);
        !           108:            LineTo(hDC, lpSelectRect->left, ptCurrent.y);
        !           109:            LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
        !           110:            SetROP2(hDC, OldROP);
        !           111:            break;
        !           112:     
        !           113:        case SL_BLOCK:
        !           114:            PatBlt(hDC,
        !           115:                lpSelectRect->left,
        !           116:                lpSelectRect->bottom,
        !           117:                lpSelectRect->right - lpSelectRect->left,
        !           118:                ptCurrent.y - lpSelectRect->bottom,
        !           119:                DSTINVERT);
        !           120:            PatBlt(hDC,
        !           121:                lpSelectRect->right,
        !           122:                lpSelectRect->top,
        !           123:                ptCurrent.x - lpSelectRect->right,
        !           124:                ptCurrent.y - lpSelectRect->top,
        !           125:                DSTINVERT);
        !           126:            break;
        !           127:     }
        !           128:     lpSelectRect->right = ptCurrent.x;
        !           129:     lpSelectRect->bottom = ptCurrent.y;
        !           130:     ReleaseDC(hWnd, hDC);
        !           131:     return 1;
        !           132: }
        !           133: 
        !           134: /****************************************************************************
        !           135: 
        !           136:     FUNCTION: EndSelection(POINT, LPRECT)
        !           137: 
        !           138:     PURPOSE: End selection of region, release capture of mouse movement
        !           139: 
        !           140: ****************************************************************************/
        !           141: 
        !           142: INT APIENTRY EndSelection(
        !           143:     MPOINT ptCurrent,
        !           144:     LPRECT lpSelectRect)
        !           145: {
        !           146:     lpSelectRect->right = ptCurrent.x;
        !           147:     lpSelectRect->bottom = ptCurrent.y;
        !           148:     ReleaseCapture();
        !           149:     return 1;
        !           150: }
        !           151: 
        !           152: /****************************************************************************
        !           153: 
        !           154:     FUNCTION: ClearSelection(HWND, LPRECT, int) - clear selection area
        !           155: 
        !           156:     PURPOSE: Clear the current selection
        !           157: 
        !           158: ****************************************************************************/
        !           159: 
        !           160: INT APIENTRY ClearSelection(
        !           161:     HWND hWnd,
        !           162:     LPRECT lpSelectRect,
        !           163:     INT fFlags)
        !           164: {
        !           165:     HDC hDC;
        !           166:     INT2DWORD OldROP;
        !           167: 
        !           168:     hDC = GetDC(hWnd);
        !           169:     switch (fFlags & SL_TYPE) {
        !           170: 
        !           171:        case SL_BOX:
        !           172:            OldROP = SetROP2(hDC, R2_NOTXORPEN);
        !           173:            MoveToEx(hDC, lpSelectRect->left, lpSelectRect->top, NULL);
        !           174:            LineTo(hDC, lpSelectRect->right, lpSelectRect->top);
        !           175:            LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom);
        !           176:            LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom);
        !           177:            LineTo(hDC, lpSelectRect->left, lpSelectRect->top);
        !           178:            SetROP2(hDC, OldROP);
        !           179:            break;
        !           180: 
        !           181:        case SL_BLOCK:
        !           182:            PatBlt(hDC,
        !           183:                lpSelectRect->left,
        !           184:                lpSelectRect->top,
        !           185:                lpSelectRect->right - lpSelectRect->left,
        !           186:                lpSelectRect->bottom - lpSelectRect->top,
        !           187:                DSTINVERT);
        !           188:            break;
        !           189:     }
        !           190:     ReleaseDC(hWnd, hDC);
        !           191:     return 1;
        !           192: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.