[.net] Mouse hidden but can still click 'x'

Started by
6 comments, last by Galaximo 17 years, 6 months ago
I'm running a fullscreen Managed DirectX application. I am hiding the mouse using System.Windows.Forms.Cursor.Hide(). Even though the mouse is hidden while in the game if you move the mouse towards the upper right corner of the screen or upper left and click it clicks the 'x' or the window icon respectively. This causes the device to be lost and crashes the app. I've tried looking for a way to keep the mouse restricted to the current window but couldn't find it. That may work if you know how to do it. Any ideas? Thanks.
Advertisement
This might be considered a bad practice (or not a good idea), but why not just remove the close button from the form, or disable it by overriding the close button event handler?

Since your app is running fullscreen, I assume you have some other way of closing it (such as an in game menu)?
Actually, because the application's window isn't maximized, I'm clicking Visual Studio's 'x'. :)
do you care what the mouse position is? You can just do System.Windows.Forms.Cursor.Position = new Point(center of my form).

If you have a cursor in your game, you can just read the position first, difference it with the value that you normally set it to, and add that value to your internal cursor coordinates.
You can use DirectInput to acquire the mouse device in exclusive mode. This will completely prevent clicking any GUI buttons.
deathkrushPS3/Xbox360 Graphics Programmer, Mass Media.Completed Projects: Stuntman Ignition (PS3), Saints Row 2 (PS3), Darksiders(PS3, 360)
Quote:Original post by Galaximo
Actually, because the application's window isn't maximized, I'm clicking Visual Studio's 'x'. :)

Wait a second. You say you are clicking visual studio's close button, and it is causing your app to close?

If your app is crashing when you switch out of the app, you had probably best handle it in your program. Does the same thing happen when you alt+tab out of your app?
Quote:Original post by Moe
Quote:Original post by Galaximo
Actually, because the application's window isn't maximized, I'm clicking Visual Studio's 'x'. :)

Wait a second. You say you are clicking visual studio's close button, and it is causing your app to close?
That's fairly normal if you're running the application from within Visual Studio (via the Debug menu).

[Website] [+++ Divide By Cucumber Error. Please Reinstall Universe And Reboot +++]

When acquiring the mouse device using DirectInput setting Exclusive mode did the trick. Thanks for the input guys.

This topic is closed to new replies.

Advertisement