home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / os / mswindo / programm / misc / 1497 < prev    next >
Encoding:
Text File  |  1992-08-25  |  1.8 KB  |  43 lines

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