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

  1. Newsgroups: comp.os.ms-windows.programmer.misc
  2. Path: sparky!uunet!mcsun!sunic!aun.uninett.no!ugle.unit.no!torstein
  3. From: torstein@kjemi.unit.no (Torstein Hansen . Elektrokjemi)
  4. Subject: Re: Mouse Grid Snapping
  5. Message-ID: <1992Aug27.192938.29340@ugle.unit.no>
  6. Sender: news@ugle.unit.no (NetNews Administrator)
  7. Organization: Lab. of Chem.Eng, Norwegian Inst. of Tech.
  8. References: <1992Aug27.163123.8921@bcrka451.bnr.ca>
  9. Date: Thu, 27 Aug 92 19:29:38 GMT
  10. Lines: 34
  11.  
  12. In article <1992Aug27.163123.8921@bcrka451.bnr.ca> carr@bnr.ca (John Carr) writes:
  13. >
  14. >
  15. > Does anyone know how to implement mouse grid snapping in MS-WINDOWS
  16. >using C or BorlandC++ ?
  17.  
  18. There is no functions in the Windows API to implement a grid snapping feature.
  19. You may try to simulate one by:
  20.  
  21.   Declare a variable to hold the actual mouse position. (RealMousePos)
  22.   Declare a variable to hold the "virtual" mouse position (VirtualMousePos)
  23.  
  24.   When your program receives a mouse message compare the mouse position in
  25.     lParam with what you have stored in VirtualMousePos. Update RealMousePos
  26.     accordingly. 
  27.   If the change in RealMousePos suggests an updated VirtualMousePos
  28.   then
  29.     Set VirtualMousePos to nearest grid point of RealMousePos
  30.     call SetCursorPos(VirtualMousePos.X,VirtualMousePos.Y)
  31.   else
  32.     call SetCursorPos(VirtualMousePos.X,VirtualMousePos.Y)
  33.   
  34. Be careful not to restrict mouse movement in other applications...
  35.  
  36. Last: You might consider restricting actions like line drawing etc. to grid
  37. points, or use SetCursorPos only when a buttondown or buttonup message is 
  38. received. By doing this the user will get a better "feeling" of what is going
  39. on.
  40.  
  41. I hope this was of any help.
  42.  
  43. Regards...
  44.  
  45. Torstein Hansen
  46.