LRESULT OnLButtonUp (HWND hWnd, UINT nCtrl, UINT x, UINT y) { if (!isRubberBand) { return 0; } DrawRubberBand(hWnd); HMENU hMenu = ::GetMenu(hWnd); HMENU hShapeMenu = ::GetSubMenu(hMenu, 1); if (::GetMenuState(hShapeMenu, ID_SHAPE_RECTANGLE, MF_BYCOMMAND) & MF_CHECKED) { Shapes[nCurrentIndex].shapeID = ID_SHAPE_RECTANGLE; } else { Shapes[nCurrentIndex].shapeID = ID_SHAPE_ELLIPSE; } Shapes[nCurrentIndex].rect.left = ptStart.x; Shapes[nCurrentIndex].rect.top = ptStart.y; Shapes[nCurrentIndex].rect.right = ptCurrent.x; Shapes[nCurrentIndex].rect.bottom = ptCurrent.y; nCurrentIndex = (++nCurrentIndex)%SHAPE_COUNT; isRubberBand = false; InvalidateRect(hWnd, NULL, TRUE); UpdateWindow(hWnd); return 0; }
LRESULT OnMouseMove (HWND hWnd, UINT nCtrl, UINT x, UINT y) { if (!isRubberBand) { return 0; } DrawRubberBand(hWnd); ptCurrent.x = x; ptCurrent.y = y; DrawRubberBand(hWnd); return 0; }
LRESULT OnLButtonDown (HWND hWnd, UINT nCtrl, UINT x, UINT y) { ptStart.x = x; ptStart.y = y; isRubberBand = true; ptCurrent.x = x; ptCurrent.y = y; DrawRubberBand(hWnd); return 0; }
VOID BoxPaint( VOID ) /* Our call to FontEditPaint */ { HDC hDC; hDC = GetDC(hBox); FontEditPaint(hBox, hDC); ReleaseDC(hBox, hDC); if (fRubberBanding) DrawRubberBand(hDst, &rectRubber, R2_XORPEN); }
LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) { switch (message) { case WM_CREATE: { HMENU hMenu = ::GetMenu(hWnd); HMENU hMenuShapes = ::GetSubMenu(hMenu, 1); ::CheckMenuRadioItem(hMenuShapes, ID_SHAPE_RECTANGLE, ID_SHAPE_CIRCLE, ID_SHAPE_RECTANGLE, MF_BYCOMMAND); } case WM_COMMAND: { int wmId = LOWORD(wParam); int wmEvent = HIWORD(wParam); bool isHandled = true; LRESULT lResult = OnCommand(hWnd, wmId, wmEvent, (HWND)lParam, isHandled); if (!isHandled) { lResult = DefWindowProc(hWnd, message, wParam, lParam); } return lResult; } break; case WM_CHAR: { if (VK_ESCAPE == wParam && isRubberBand) { isRubberBand = false; DrawRubberBand(hWnd); } } break; case WM_LBUTTONDOWN: { return OnLButtonDown(hWnd, (UINT)wParam, LOWORD(lParam), HIWORD(lParam)); } break; case WM_MOUSEMOVE: { return OnMouseMove(hWnd, (UINT)wParam, LOWORD(lParam), HIWORD(lParam)); } break; case WM_LBUTTONUP: { return OnLButtonUp(hWnd, (UINT)wParam, LOWORD(lParam), HIWORD(lParam)); } break; case WM_PAINT: { return OnPaint(hWnd); } break; case WM_DESTROY: { PostQuitMessage(0); return 0; } break; } //C: Exit. return DefWindowProc(hWnd, message, wParam, lParam); }
/****************************************************************************** * long APIENTRY FontEditWndProc(hBox, message, wParam, lParam) * * purpose: Master controller for Fontedit's all-encompassing main window * * params : same as for all window functions * * side effects: countless * *****************************************************************************/ LONG APIENTRY FontEditWndProc( HWND hBox, WORD message, WPARAM wParam, LONG lParam ) { PAINTSTRUCT ps; HMENU hMenu; WORD mf; POINT pt; RECT BoxRect; switch (message) { case WM_CLOSE: if (!CheckSave()) /* See if any files need saving */ break; /* Window's being destroyed. */ if (fLoaded) /* 4/8/87 Linsh added */ DeleteBitmap(); /* Get rid of memory DC */ DestroyWindow(hFont); DestroyWindow(hBox); break; case WM_DESTROY: PostQuitMessage(0); /* Cause application to be terminated */ break; case WM_QUERYENDSESSION: if (CheckSave()) /* See if any files need saving */ return TRUE; break; case WM_ENDSESSION: if (fLoaded) DeleteBitmap(); /* Get rid of memory DC */ break; case WM_SIZE: /* Window's size is changing. lParam contains the width ** and height, in the low and high words, respectively. ** wParam contains SIZENORMAL for "normal" size changes, ** SIZEICONIC when the window is being made iconic, and ** SIZEFULLSCREEN when the window is being made full screen. */ switch (wParam) { case SIZEFULLSCREEN: case SIZENORMAL: ResizeShow(); if (kStuff != GetkStuff()) /* Did it change ? */ ResizeShow(); /* Yes resize again */ break; } break; case WM_MOVE: /* Tell popup to move with us. */ if (!IsIconic(hBox)) ResizeShow(); break; case WM_PAINT: /* Time for the window to draw itself. */ BeginPaint(hBox, (LPPAINTSTRUCT)&ps); FontEditPaint(hBox, ps.hdc); EndPaint(hBox, (LPPAINTSTRUCT)&ps); break; case WM_COMMAND: /* A menu item has been selected, or a control is notifying * its parent. wParam is the menu item value (for menus), * or control ID (for controls). For controls, the low word * of lParam has the window handle of the control, and the hi * word has the notification code. For menus, lParam contains * 0L. */ FontEditCommand(hBox, GET_WM_COMMAND_ID(wParam, lParam)); break; /* Data interchange request. */ case WM_CUT: case WM_COPY: case WM_PASTE: case WM_CLEAR: case WM_UNDO: case WM_RENDERFORMAT: case WM_RENDERALLFORMATS: case WM_DESTROYCLIPBOARD: case WM_DRAWCLIPBOARD: break; case WM_INITMENU: hMenu = GetMenu(hBox); /* Gray menu if no clipboard bitmap */ mf = (WORD)(IsClipboardFormatAvailable(CF_BITMAP) ? MF_ENABLED : MF_GRAYED); EnableMenuItem(hMenu, BOX_PASTE, mf); EnableMenuItem(hMenu, FONT_PASTE, mf); break; /* For each of following mouse window messages, wParam contains ** bits indicating whether or not various virtual keys are down, ** and lParam is a POINT containing the mouse coordinates. The ** keydown bits of wParam are: MK_LBUTTON (set if Left Button is ** down); MK_RBUTTON (set if Right Button is down); MK_SHIFT (set ** if Shift Key is down); MK_ALTERNATE (set if Alt Key is down); ** and MK_CONTROL (set if Control Key is down). */ case WM_LBUTTONDOWN: MPOINT2POINT(MAKEMPOINT(lParam), pt); if (fStartRubberBand) { /* a green signal to rubberband a rectangle for the * Fill menu command rectangle now has null dimensions. * Snap the current mouse point to nearest grid * intersection thus defining upper left corner of * rectangle */ if (PtInRect((LPRECT)&FontRect, pt)) { pt = SnapPointToGrid(pt); rectRubber.top = pt.y *scale+ptBox.y+1; rectRubber.bottom = (pt.y+1)*scale+ptBox.y-2; rectRubber.left = pt.x *scale+ptBox.x+1; rectRubber.right = (pt.x+1)*scale+ptBox.x-2; hDst = InitialiseRubberBandingRect(hBox); DrawRubberBand(hDst, &rectRubber, R2_XORPEN); } else { fStartRubberBand = fRubberBanding = FALSE; ReleaseCapture(); } } /* do operation depending upon current active command, * but not if we just added/deleted a row/column. */ if (!fJustZapped) { if (fStartRubberBand) { pt.x *= scale; pt.y *= scale; MouseInBox(hBox, message, pt); } else { MPOINT2POINT(MAKEMPOINT(lParam), pt); MouseInBox(hBox, message, pt); } } break; case WM_LBUTTONUP: /* Get other corner of rectangle */ fJustZapped = FALSE; if (fRubberBanding) { /* if rubberbanding for the Fill menu command, * terminate proceedings and clean up */ DrawRubberBand(hDst, &rectRubber, R2_NOT); EndRubberBandingRect(hDst); if (cursor) { ReadRect(); } } if (fCaptured ) { /* if cursor is + shaped, restore it to default */ ReleaseCapture(); SetCursor (hOldCursor); } break; case WM_RBUTTONDOWN: case WM_RBUTTONUP: break; case WM_MOUSEMOVE: /* If mouse is down */ MPOINT2POINT(MAKEMPOINT(lParam), pt); if ((fRubberBanding) && (wParam & MK_LBUTTON)) { /* if any of Fill menu commands is active ** (AND the mouse key depressed) draw a rubberband ** a rectangle with the mouse movements */ /* get current square number */ pt = SnapPointToGrid(pt); /* calculate grid for new square */ BoxRect.top = pt.y *scale+ptBox.y+1; BoxRect.bottom = (pt.y+1)*scale+ptBox.y-2; BoxRect.left = pt.x *scale+ptBox.x+1; BoxRect.right = (pt.x+1)*scale+ptBox.x-2; /* erase old mark */ DrawRubberBand(hDst, &rectRubber, R2_NOT); /* limit rubber band to box */ if (BoxRect.right > scale * (LONG)wBox + ptBox.x) BoxRect.right = scale * wBox + ptBox.x; if (BoxRect.bottom > scale * (LONG)kBox + ptBox.y) BoxRect.bottom = scale * kBox + ptBox.y; if (BoxRect.top < 0) BoxRect.top = 1; if (BoxRect.left < 0) BoxRect.left = 1; if (ptA.x == pt.x) { rectRubber.right = BoxRect.right; rectRubber.left = BoxRect.left; } if (ptA.y == pt.y) { rectRubber.bottom = BoxRect.bottom; rectRubber.top = BoxRect.top; } /* almost an IntersectRect */ if (ptA.x >= pt.x) rectRubber.left = BoxRect.left; else rectRubber.right = BoxRect.right; if (ptA.y >= pt.y) rectRubber.top = BoxRect.top; else rectRubber.bottom = BoxRect.bottom; /* Draw new mark */ DrawRubberBand(hDst, &rectRubber, R2_XORPEN); } else { /* if not "Fill"ing(AND mouse key depressed, * paint with the mouse movements */ if ((wParam & MK_LBUTTON) && cursor == FALSE && fJustZapped == FALSE) MouseInBox(hBox, message, pt); } break; case WM_LBUTTONDBLCLK: case WM_RBUTTONDBLCLK: break; default: /* Everything else comes here. This call MUST exist ** in your window proc. */ return(DefWindowProc(hBox, message, wParam, lParam)); break; } /* A window proc should always return something */ return(0L); }