![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Fast Track Visual C++ 6.0 Programming
Thats the way our drawing process works. Lets start implementing this process in OnMouseMove() now. Stretching Graphics FiguresWe draw the outlining rectangle in OnMouseMove(), and as the mouse moves, the program gives the impression that the user is stretching a rectangle over the capture site. We start OnMouseMove() by making sure that were capturing the screen and that were supposed to draw the outlining rectangle. void CCopierView::OnMouseMove(UINT nFlags, CPoint point) { if(CaptureFlag && DrawFlag){ ⇐ . . . } ⇐ CView::OnMouseMove(nFlags, point); } If the drawing process has begun, we get the current location of the mouse in screen coordinates. void CCopierView::OnMouseMove(UINT nFlags, CPoint point) { if(CaptureFlag && DrawFlag){ CDC ScreenDC; CPoint CurrentPoint = GetMessagePos(); ⇐ . . . } CView::OnMouseMove(nFlags, point); } The next step is to draw the outlining rectangle from the anchor point to the current point. To do that, we need a device context corresponding to the whole screen, as shown in the following example (the three NULLs in the call to CreateDC() correspond to the name of the device, its type, and initialization data, none of which we need here): void CCopierView::OnMouseMove(UINT nFlags, CPoint point) { if(CaptureFlag && DrawFlag){ CDC ScreenDC; CPoint CurrentPoint = GetMessagePos(); ScreenDC.CreateDC("DISPLAY", NULL, NULL, NULL); ⇐ . . . } CView::OnMouseMove(nFlags, point); } Now we can draw the rectangle itself from the anchor point to the current point. To make sure the rectangle is not filled in, we select the null brush in the device context and set the ROP2 mode to R2_NOT. void CCopierView::OnMouseMove(UINT nFlags, CPoint point) { if(CaptureFlag && DrawFlag){ CDC ScreenDC; CPoint CurrentPoint = GetMessagePos(); ScreenDC.CreateDC("DISPLAY", NULL, NULL, NULL); ScreenDC.SelectStockObject(NULL_BRUSH); ⇐ ScreenDC.SetROP2(R2_NOT); ⇐ . . . } CView::OnMouseMove(nFlags, point); }
Binary Raster OperationsWhats the ROP2 mode? ROP2 is shorthand for binary raster operation, which is the way bit-by-bit drawing is handled on the screen. In this case, were setting the ROP2 mode to R2_NOT, which means that everything we draw is the inverse of whats on the screen. This makes life simpler for us, because if we redraw the same rectangle in this mode, that rectangle disappears. The ROP2 modes appear in Table 6.1.
Finally, we draw the rectangle from the anchor point to the previous point to erase the last rectangle and then from the anchor point to the current point to draw the new rectangle. void CCopierView::OnMouseMove(UINT nFlags, CPoint point) { if(CaptureFlag && DrawFlag){ CDC ScreenDC; CPoint CurrentPoint = GetMessagePos(); ScreenDC.CreateDC("DISPLAY", NULL, NULL, NULL); ScreenDC.SelectStockObject(NULL_BRUSH); ScreenDC.SetROP2(R2_NOT); ScreenDC.Rectangle(CRect(PreviousPoint, AnchorPoint)); ⇐ ScreenDC.Rectangle(CRect(AnchorPoint, CurrentPoint)); ⇐ . . . } CView::OnMouseMove(nFlags, point); } Note that if there was no previous point set, this would be a problem the first time we drew a rectangle because wed be drawing a wild rectangle. To avoid that, we set the previous point to the anchor point when the right mouse button first goes down in OnRButtonDown(). void CCopierView::OnRButtonDown(UINT nFlags, CPoint point) { if(CaptureFlag){ DrawFlag = true; AnchorPoint = GetMessagePos(); PreviousPoint = AnchorPoint; ⇐ } CView::OnRButtonDown(nFlags, point); }
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |