SetMousePostion

Started by
8 comments, last by totoro 18 years, 7 months ago
If there is a way in c++ set and and find location of mouse click, and is it possible to move object if you click and hold in c++, please help my life depends on it. peace homie
Advertisement
Yes, it depends on your API of choice. If you're doing Win32 programming, look into intercepting the WM_MOUSEDOWN, WM_MOUSEMOVE and WM_MOUSEUP events. The parameters sent along them are the coordinates of the mouse.

If you're using SDL you can also process the analogous events. wxWidgets provides callbacks for the events but for individual mouse buttons (EVT_LEFTDOWN, EVT_LEFTUP) and uses EVT_MOTION for the mouse move event.

In DirectInput you can check the state of the mouse using the appropriate function and determine if the buttons are up or down. If the button is down and it was up the previous frame then an MOUSEDOWN event has occured and in a similar fasion you detect an MOUSEUP. You can also get the coordinates of the mouse easily.
i said c++ no win32 stuff, just in c++ using console functions
Under what operating system? This is not a C++ question. How you deal with cursors and mice is dependent on the platform you are using.
C++ doesn't have any kind of built in way of accessing the mouse (or for that matter the keyboard particularly directly). So you have to use some kind an API appropriate to whatever OS you're using, unless its DOS or something else where you can do direct hardware access in which case you have to program code for a serial mouse, PS/2 mouse and a USB HID driver. You don't want to go there.
What api could i use, to access the mouse in dos.
To use a mouse in DOS you'll have to do a little bit of assembly, using interrupt 33h. Here is a small tutorial to get you started.
to use assembly do you have to include anything files
Most compilers allow for the use of inline assembly, which you can use without headers. The syntax for that depends on your compiler.
POINT MousePos;
GetCursorPos(&MousePos);

With GetCursorPos you will fill POINT structure MousePos witch have x and y position of the cursor.

This topic is closed to new replies.

Advertisement