home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.os.ms-windows.programmer.misc
- Path: sparky!uunet!mcsun!sunic!aun.uninett.no!ugle.unit.no!torstein
- From: torstein@kjemi.unit.no (Torstein Hansen . Elektrokjemi)
- Subject: Re: Mouse Grid Snapping
- Message-ID: <1992Aug27.192938.29340@ugle.unit.no>
- Sender: news@ugle.unit.no (NetNews Administrator)
- Organization: Lab. of Chem.Eng, Norwegian Inst. of Tech.
- References: <1992Aug27.163123.8921@bcrka451.bnr.ca>
- Date: Thu, 27 Aug 92 19:29:38 GMT
- Lines: 34
-
- In article <1992Aug27.163123.8921@bcrka451.bnr.ca> carr@bnr.ca (John Carr) writes:
- >
- >
- > Does anyone know how to implement mouse grid snapping in MS-WINDOWS
- >using C or BorlandC++ ?
-
- There is no functions in the Windows API to implement a grid snapping feature.
- You may try to simulate one by:
-
- Declare a variable to hold the actual mouse position. (RealMousePos)
- Declare a variable to hold the "virtual" mouse position (VirtualMousePos)
-
- When your program receives a mouse message compare the mouse position in
- lParam with what you have stored in VirtualMousePos. Update RealMousePos
- accordingly.
- If the change in RealMousePos suggests an updated VirtualMousePos
- then
- Set VirtualMousePos to nearest grid point of RealMousePos
- call SetCursorPos(VirtualMousePos.X,VirtualMousePos.Y)
- else
- call SetCursorPos(VirtualMousePos.X,VirtualMousePos.Y)
-
- Be careful not to restrict mouse movement in other applications...
-
- Last: You might consider restricting actions like line drawing etc. to grid
- points, or use SetCursorPos only when a buttondown or buttonup message is
- received. By doing this the user will get a better "feeling" of what is going
- on.
-
- I hope this was of any help.
-
- Regards...
-
- Torstein Hansen
-