|
|
1.1.1.2 ! root 1: ! 2: /******************************************************************************\ ! 3: * This is a part of the Microsoft Source Code Samples. ! 4: * Copyright (C) 1993 Microsoft Corporation. ! 5: * All rights reserved. ! 6: * This source code is only intended as a supplement to ! 7: * Microsoft Development Tools and/or WinHelp documentation. ! 8: * See these sources for detailed information regarding the ! 9: * Microsoft samples programs. ! 10: \******************************************************************************/ ! 11: 1.1 root 12: /**************************************************************************** 13: 14: PROGRAM: Select.c 15: 16: PURPOSE: Contains library routines for selecting a region 17: 18: FUNCTIONS: 19: 1.1.1.2 ! root 20: StartSelection(HWND, POINT, LPRECT, int) - begin selection area ! 21: UpdateSelection(HWND, POINT, LPRECT, int) - update selection area ! 22: EndSelection(POINT, LPRECT) - end selection area ! 23: ClearSelection(HWND, LPRECT, int) - clear selection area 1.1 root 24: 25: *******************************************************************************/ 26: 27: #include "windows.h" 28: #include "select.h" 29: 30: /**************************************************************************** 1.1.1.2 ! root 31: FUNCTION: DllMain(HANDLE, DWORD, LPVOID) 1.1 root 32: 1.1.1.2 ! root 33: PURPOSE: DllMain is called by Windows when 1.1 root 34: the DLL is initialized, Thread Attached, and other times. 35: Refer to SDK documentation, as to the different ways this 36: may be called. 37: 1.1.1.2 ! root 38: The DllMain function should perform additional initialization 1.1 root 39: tasks required by the DLL. In this example, no initialization 1.1.1.2 ! root 40: tasks are required. DllMain should return a value of 1 if 1.1 root 41: the initialization is successful. 42: 43: *******************************************************************************/ 1.1.1.2 ! root 44: BOOL APIENTRY DllMain(HANDLE hInst, DWORD ul_reason_being_called, LPVOID lpReserved) 1.1 root 45: { 46: return 1; 1.1.1.2 ! root 47: UNREFERENCED_PARAMETER(hInst); ! 48: UNREFERENCED_PARAMETER(ul_reason_being_called); ! 49: UNREFERENCED_PARAMETER(lpReserved); 1.1 root 50: } 51: 52: 53: /**************************************************************************** 54: 55: FUNCTION: StartSelection(HWND, POINT, LPRECT, int) 56: 57: PURPOSE: Begin selection of region 58: 59: ****************************************************************************/ 60: 61: INT APIENTRY StartSelection( 62: HWND hWnd, 63: MPOINT ptCurrent, 64: LPRECT lpSelectRect, 65: INT fFlags) 66: { 67: if (lpSelectRect->left != lpSelectRect->right || 1.1.1.2 ! root 68: lpSelectRect->top != lpSelectRect->bottom) ! 69: ClearSelection(hWnd, lpSelectRect, fFlags); 1.1 root 70: 71: lpSelectRect->right = ptCurrent.x; 72: lpSelectRect->bottom = ptCurrent.y; 73: 74: /* If you are extending the box, then invert the current rectangle */ 75: 76: if ((fFlags & SL_SPECIAL) == SL_EXTEND) 1.1.1.2 ! root 77: ClearSelection(hWnd, lpSelectRect, fFlags); 1.1 root 78: 79: /* Otherwise, set origin to current location */ 80: 81: else { 1.1.1.2 ! root 82: lpSelectRect->left = ptCurrent.x; ! 83: lpSelectRect->top = ptCurrent.y; 1.1 root 84: } 85: SetCapture(hWnd); 86: return 1; 87: } 88: 89: /**************************************************************************** 90: 91: FUNCTION: UpdateSelection(HWND, POINT, LPRECT, int) - update selection area 92: 93: PURPOSE: Update selection 94: 95: ****************************************************************************/ 96: 97: INT APIENTRY UpdateSelection( 98: HWND hWnd, 99: MPOINT ptCurrent, 100: LPRECT lpSelectRect, 101: INT fFlags) 102: { 103: HDC hDC; 104: SHORT OldROP; 105: 106: hDC = GetDC(hWnd); 107: 108: switch (fFlags & SL_TYPE) { 109: 1.1.1.2 ! root 110: case SL_BOX: ! 111: OldROP = (SHORT)SetROP2(hDC, R2_NOTXORPEN); ! 112: MoveToEx(hDC, lpSelectRect->left, lpSelectRect->top, NULL); ! 113: LineTo(hDC, lpSelectRect->right, lpSelectRect->top); ! 114: LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom); ! 115: LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom); ! 116: LineTo(hDC, lpSelectRect->left, lpSelectRect->top); ! 117: LineTo(hDC, ptCurrent.x, lpSelectRect->top); ! 118: LineTo(hDC, ptCurrent.x, ptCurrent.y); ! 119: LineTo(hDC, lpSelectRect->left, ptCurrent.y); ! 120: LineTo(hDC, lpSelectRect->left, lpSelectRect->top); ! 121: SetROP2(hDC, OldROP); ! 122: break; 1.1 root 123: 1.1.1.2 ! root 124: case SL_BLOCK: ! 125: PatBlt(hDC, ! 126: lpSelectRect->left, ! 127: lpSelectRect->bottom, ! 128: lpSelectRect->right - lpSelectRect->left, ! 129: ptCurrent.y - lpSelectRect->bottom, ! 130: DSTINVERT); ! 131: PatBlt(hDC, ! 132: lpSelectRect->right, ! 133: lpSelectRect->top, ! 134: ptCurrent.x - lpSelectRect->right, ! 135: ptCurrent.y - lpSelectRect->top, ! 136: DSTINVERT); ! 137: break; 1.1 root 138: } 139: lpSelectRect->right = ptCurrent.x; 140: lpSelectRect->bottom = ptCurrent.y; 141: ReleaseDC(hWnd, hDC); 142: return 1; 143: } 144: 145: /**************************************************************************** 146: 147: FUNCTION: EndSelection(POINT, LPRECT) 148: 149: PURPOSE: End selection of region, release capture of mouse movement 150: 151: ****************************************************************************/ 152: 153: INT APIENTRY EndSelection( 154: MPOINT ptCurrent, 155: LPRECT lpSelectRect) 156: { 157: lpSelectRect->right = ptCurrent.x; 158: lpSelectRect->bottom = ptCurrent.y; 159: ReleaseCapture(); 160: return 1; 161: } 162: 163: /**************************************************************************** 164: 165: FUNCTION: ClearSelection(HWND, LPRECT, int) - clear selection area 166: 167: PURPOSE: Clear the current selection 168: 169: ****************************************************************************/ 170: 171: INT APIENTRY ClearSelection( 172: HWND hWnd, 173: LPRECT lpSelectRect, 174: INT fFlags) 175: { 176: HDC hDC; 177: INT2DWORD OldROP; 178: 179: hDC = GetDC(hWnd); 180: switch (fFlags & SL_TYPE) { 181: 1.1.1.2 ! root 182: case SL_BOX: ! 183: OldROP = SetROP2(hDC, R2_NOTXORPEN); ! 184: MoveToEx(hDC, lpSelectRect->left, lpSelectRect->top, NULL); ! 185: LineTo(hDC, lpSelectRect->right, lpSelectRect->top); ! 186: LineTo(hDC, lpSelectRect->right, lpSelectRect->bottom); ! 187: LineTo(hDC, lpSelectRect->left, lpSelectRect->bottom); ! 188: LineTo(hDC, lpSelectRect->left, lpSelectRect->top); ! 189: SetROP2(hDC, OldROP); ! 190: break; ! 191: ! 192: case SL_BLOCK: ! 193: PatBlt(hDC, ! 194: lpSelectRect->left, ! 195: lpSelectRect->top, ! 196: lpSelectRect->right - lpSelectRect->left, ! 197: lpSelectRect->bottom - lpSelectRect->top, ! 198: DSTINVERT); ! 199: break; 1.1 root 200: } 201: ReleaseDC(hWnd, hDC); 202: return 1; 203: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.