void InvertGrid( HWND hWindow, HDC hDC, LPRECT lpGridRect, int x, int y ) /***********************************************************************/ { RECT rRect1, rRect2; rRect1 = *lpGridRect; Image2Control( (LPINT)&rRect1.left, (LPINT)&rRect1.top ); Image2Control( (LPINT)&rRect1.right, (LPINT)&rRect1.bottom ); if ( x == 0 && y == 0 ) { InvertSelection( hWindow, hDC, &rRect1, SL_BLOCK ); return; } NewGridFromPoint( lpGridRect, x, y ); rRect2 = *lpGridRect; Image2Control( (LPINT)&rRect2.left, (LPINT)&rRect2.top ); Image2Control( (LPINT)&rRect2.right, (LPINT)&rRect2.bottom ); if ( !EqualRect( &rRect1, &rRect2 ) ) { InvertSelection( hWindow, hDC, &rRect1, SL_BLOCK ); InvertSelection( hWindow, hDC, &rRect2, SL_BLOCK ); } }
void DrawGrid( HWND hWindow, HDC hDC, LPRECT lpGridRect, int iType ) /***********************************************************************/ { RECT rRect; rRect = *lpGridRect; Image2Control( (LPINT)&rRect.left, (LPINT)&rRect.top ); Image2Control( (LPINT)&rRect.right, (LPINT)&rRect.bottom ); InvertSelection( hWindow, hDC, &rRect, iType ); }
void CSelection::InvertSelection(HWND hWnd, HDC hDC, RECT* pRect, int fFlags) { short OldROP; bool fNeedDC; RECT SelectRect; static RECT LastSelectRect; static int LastFlags; bool fDoc = false; int type; if (pRect->right - pRect->left > 50) int i = 0; if (fFlags && pRect) { // Saved for the display hook LastSelectRect = *pRect; LastFlags = fFlags; } else { // Called from the display hook fFlags = LastFlags; } type = fFlags & SL_TYPE; SelectRect = LastSelectRect; if (fDoc) { //j if (type == SL_LINE) //j { //j File2DisplayEx(hWnd, (LPINT)&SelectRect.left, (LPINT)&SelectRect.top, true); //j File2DisplayEx(hWnd, (LPINT)&SelectRect.right, (LPINT)&SelectRect.bottom, true); //j } //j else //j { //j OrderRect(&SelectRect, &SelectRect); //j File2DispRectExact(hWnd, &SelectRect, &SelectRect); //j } } if (fNeedDC = (!hDC)) hDC = GetDC(hWnd); switch (type) { case SL_BOX: { OldROP = SetROP2(hDC, R2_NOT); MoveToEx(hDC, SelectRect.left, SelectRect.top, NULL); LineTo(hDC, SelectRect.right, SelectRect.top); LineTo(hDC, SelectRect.right, SelectRect.bottom); LineTo(hDC, SelectRect.left, SelectRect.bottom); LineTo(hDC, SelectRect.left, SelectRect.top); SetROP2(hDC, OldROP); break; } case SL_BOXHANDLES: { OldROP = SetROP2(hDC, R2_NOT); MoveToEx(hDC, SelectRect.left, SelectRect.top, NULL); LineTo(hDC, SelectRect.right, SelectRect.top); LineTo(hDC, SelectRect.right, SelectRect.bottom); LineTo(hDC, SelectRect.left, SelectRect.bottom); LineTo(hDC, SelectRect.left, SelectRect.top); SetROP2(hDC, OldROP); DrawHandles(hDC, &SelectRect); break; } #ifdef NOTUSED //j case SL_GRID: { RECT ClientRect; int x, y, dx, dy, cx, cy; OldROP = SetROP2(hDC, R2_NOT); GetClientRect(hWnd, &ClientRect); dx = abs(RectWidth(&SelectRect)); dy = abs(RectHeight(&SelectRect)); if (dx > CLOSENESS && dy > CLOSENESS) { x = min(SelectRect.left, SelectRect.right); cx = x; Image2Control(&cx, &cy); while (cx >= ClientRect.left) { MoveToEx(hDC, cx, ClientRect.top, NULL); LineTo(hDC, cx, ClientRect.bottom); x -= dx; cx = x; Image2Control(&cx, &cy); } x = max(SelectRect.left, SelectRect.right); cx = x; Image2Control(&cx, &cy); while (cx <= ClientRect.right) { MoveToEx(hDC, cx, ClientRect.top, NULL); LineTo(hDC, cx, ClientRect.bottom); x += dx; cx = x; Image2Control(&cx, &cy); } y = min(SelectRect.top, SelectRect.bottom); cy = y; Image2Control(&cx, &cy); while (cy >= ClientRect.top) { MoveToEx(hDC, ClientRect.left, cy, NULL); LineTo(hDC, ClientRect.right, cy); y -= dy; cy = y; Image2Control(&cx, &cy); } y = max(SelectRect.top, SelectRect.bottom); cy = y; Image2Control(&cx, &cy); while (cy <= ClientRect.bottom) { MoveToEx(hDC, ClientRect.left, cy, NULL); LineTo(hDC, ClientRect.right, cy); y += dy; cy = y; Image2Control(&cx, &cy); } } else { Image2Control((LPINT)&SelectRect.left, (LPINT)&SelectRect.top); Image2Control((LPINT)&SelectRect.right, (LPINT)&SelectRect.bottom); MoveToEx(hDC, SelectRect.left, SelectRect.top, NULL); LineTo(hDC, SelectRect.right, SelectRect.top); LineTo(hDC, SelectRect.right, SelectRect.bottom); LineTo(hDC, SelectRect.left, SelectRect.bottom); LineTo(hDC, SelectRect.left, SelectRect.top); } SetROP2(hDC, OldROP); break; } #endif NOTUSED //j case SL_LINE: { OldROP = SetROP2(hDC, R2_NOT); MoveToEx(hDC, SelectRect.left, SelectRect.top, NULL); LineTo(hDC, SelectRect.right, SelectRect.bottom); SetROP2(hDC, OldROP); break; } case SL_ELLIPSE: { OldROP = SetROP2(hDC, R2_NOT); HBRUSH hOldBrush = (HBRUSH)SelectObject(hDC, GetStockObject(NULL_BRUSH)); Ellipse(hDC, SelectRect.left, SelectRect.top, SelectRect.right, SelectRect.bottom); SetROP2(hDC, OldROP); SelectObject(hDC, hOldBrush); break; } case SL_BLOCK: { PatBlt(hDC, SelectRect.left, SelectRect.top, SelectRect.right - SelectRect.left, SelectRect.bottom - SelectRect.top, DSTINVERT); break; } } if (fNeedDC) ReleaseDC(hWnd, hDC); }