Jump to content

View more

Image of the Day

Adding some finishing touches...
Follow us for more
#screenshotsaturday #indiedev... by #MakeGoodGames https://t.co/Otbwywbm3a
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.

Sign up now

mouse cursor on RenderForm won't hide after alt-tab

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
1 reply to this topic

#1 thomasvt   Members   


Posted 13 January 2012 - 03:57 PM


On Win7 DirectX11 using SlimDX, i have an empty project that's fullscreen with some mousecursor-hiding code like found on this forum too. The mouse is nicely hidden initially.

When alt-tabing out and activating the app again, the fullscreen returns but with a visible mousecursor.

Whichever code i try, it won't work. I even have Cursor.Hide() in my main loop :)

Here is the code, it's messy because it's test code :)

Anyone see mistakes? When i translate to DirectX 10, i get the same problem.

var form = new RenderForm();

Device device;
SwapChain swapChain;
Device.CreateWithSwapChain(DriverType.Hardware, DeviceCreationFlags.Debug, swapChainDescription, out device, out swapChain);

using (var factory = swapChain.GetParent<Factory>())
factory.SetWindowAssociation(form.Handle, WindowAssociationFlags.IgnoreAltEnter);

form.Activated += (o, e) => { swapChain.IsFullScreen = true; Cursor.Hide(); };

var backBuffer = Resource.FromSwapChain<Texture2D>(swapChain, 0);
var renderView = new RenderTargetView(device, backBuffer);

device.ImmediateContext.Rasterizer.SetViewports(new Viewport(0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));

form.MouseEnter += (s, e) => Cursor.Hide();
form.MouseLeave += (s, e) => Cursor.Show();

MessagePump.Run(form, () => {
device.ImmediateContext.ClearRenderTargetView(renderView, Color.CornflowerBlue);
swapChain.Present(0, PresentFlags.None);

swapChain.IsFullScreen = false;


#2 thomasvt   Members   


Posted 14 January 2012 - 07:26 AM

I found it myself.

As i was refactoring to get a nicely structured base class to get me started, i accidently found out that this mouse cursor problem only exists in a specific situation:

When you AltTab out of a fullscreen app, it actually becomes windowed. When reactivating the app, it remains windowed. Because I always want a fullscreen, I added the following eventhandler:

WindowsForm.AppActivated += (sender, args) => { SwapChain.IsFullScreen = true; };

Because of common sense i also set IsWindowed = false when calling Device.CreateWithSwapChain().

This combination caused the mouse cursor to stay visible after alt-tab and reactivating the app.

But when you change one thing: call Device.CreateWithSwapChain() with IsWindowed = true; this Cursor problem doesn't happen anymore. You start DirectX windowed but my AppActivated eventhandler above is triggered at startup too, so I get a fullscreen immediately at startup.

So, now I have a fullscreen app, that never becomes windowed and never shows the windows mouse cursor, finally :)

If any expert can explain this difference, I'm happy to listen, but for now I'l just accept it :)

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.