home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- Path: sparky!uunet!decwrl!csus.edu!netcom.com!whedon
- From: whedon@netcom.com (Bill Whedon)
- Subject: Re: Rubber Banding in C/C++
- Message-ID: <ybbn6#a.whedon@netcom.com>
- Date: Wed, 26 Aug 92 06:24:38 GMT
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- References: <1992Aug25.141019.25493@bcrka451.bnr.ca>
- Lines: 32
-
- In article <1992Aug25.141019.25493@bcrka451.bnr.ca> carr@bnr.ca (John Carr) writes:
- >
- >
- > Does anybody know how to rubber band in MS-Windows with C or
- >C++ code (preferably OWL)? I would like to be able to drop a
- >single anchor point (Point1) and then drag a second point around
- >(Point2), a rectangle will be continually drawn and redrawn from
- >Point1 to Point2 as I drag Point2 around. I would like to have
- >the rectangle redraw use XORing so as to avoid corrupting the
- >background. Any help with this would be much appreciated.
- >
- Sure. Trap the WM_LBUTTONDOWN message to start rubberbanding. You have to
- get the current location of the mouse pointer, and start drawing a rectangle
- using a hollow brush and the XOR pen. While the left button is down, (set
- an indicator which you reset on WM_LBUTTONUP), trap the WM_MOUSEMOVE
- message and (1) redraw the original rectangle with XOR, then (2) draw one
- from your base coordinate (saved when the WM_LBUTTONDOWN was sensed) to the
- new mouse coordinates.
-
- If you want to leave the final rectangle on the screen, don't XOR it again
- when the WM_LBUTTONUP is sensed, otherwise, do. You can also capture the
- pointer to keep it within the client area you're interested in.
-
- Remember to use static variables to hold your start and end points.
-
- There is an example of this (not a hollow rectangle, but an XORed screen
- area) in Petzold's "Programming Windows", Microsoft Press, ISBN 1-55615-264-7
-
- Cheers,
- Bill Whedon
-
-
-