PDA

View Full Version : Problem with inmediate mode for mouse (Clootie's libs)



cronodragon
02-11-2006, 07:06 AM
I made a version with DirectInput that is buffered and it works almost fine. One problem I found is when using the exclusive mode the cursor is lost, and other is the movement values of the mouse are not the same as the desktop mouse, making my cursor to delay it's position. Anyway, even solving this problem I'm limiting the coordinates of the mouse inside the window frame, causing the app and desktop pointer to have different positions. And, even with the desktop cursor hidden, I can see it interacting with background windows, not clicking but rolling over :? And it's supposed to be foreground and exclusive, no idea why it makes that! :x

So, I don't want to fight nature anymore, and instead I want to allow and show the desktop cursor always, and I want to follow it while it crosses the window. But I have followed tutorials, I have followed the sample in DX9 SDK (the code for inmediate mode is so simple compared to buffered), but I just can't make it work!! :x When I call GetDeviceState, it returns errors. I Adquire the device in a loop, and it returns 1, but when calling GetDeviceState it keeps returning some error code. It's hard to debug which error it is, but after crawling in the code I found it sends: DIERR_INVALIDPARAM... According to SDK:

"An invalid parameter was passed to the returning function, or the object was not in a state that permitted the function to be called. This value is equal to the E_INVALIDARG standard COM return value."

Not very informative. What can I do? I'm starting to hate DirectInput, it offers full control of the device, but that's not true... maybe I should read the mouse coordinates with WinAPI. Just in case, I'm using a formless application. Any suggestion?? Thanks in advance for any help.

Clootie
02-11-2006, 08:34 AM
Do you have small repro case? I would like to look at it.

cronodragon
02-11-2006, 02:11 PM
Thanks Clootie. I made a demo for you, and I get exactly the same errors (source included):

http://www.teleportmedia.com/mundano/Mouse.zip

This is the output I get:


Creating DirectInput, result = 0
Creating system mouse device, result = 0
Setting data format, result = 0
Setting cooperative level, result = 0
Aquiring device, result = -2147024891
Getting device state, result = -2147024884
Aquiring device, result = 0
Getting device state, result = -2147024809
Aquiring device, result = 1
Getting device state, result = -2147024809
Aquiring device, result = 1
Getting device state, result = -2147024809
Aquiring device, result = 1

Everything goes fine in the initialization, then I can't read nor acquire the device. It's weird. :?

Clootie
02-11-2006, 08:29 PM
Yes, it's really an invalid param:
as you called "Mouse.SetDataFormat(c_dfDIMouse);" you should later use "DIMOUSESTATE" and not "DIMOUSESTATE2".

For second version of mouse state struct you should initialize with c_dfDIMouse2.

cronodragon
02-11-2006, 08:34 PM
Wow! Thanks a lot Clootie :D

cronodragon
02-11-2006, 09:00 PM
Now I have it working. One question is, how do I determine the starting position of the mouse pointer? I'm using a formless window.

Clootie
02-11-2006, 11:47 PM
GetCursorPos()?

cronodragon
03-11-2006, 12:43 AM
Thanks again, and there is the SetCursorPos() function I needed. :D