• Advertisement
Sign in to follow this  

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

This topic is 2202 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey,

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.

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]var [/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]form = [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]new[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]RenderForm[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]();[/font][/font]

[font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Device[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] device;[/font][/font]
[font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]SwapChain[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] swapChain;[/font][/font]
[font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Device[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].CreateWithSwapChain([/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]DriverType[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Hardware, [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]DeviceCreationFlags[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Debug, swapChainDescription, [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]out[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] device, [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]out[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] swapChain);[/font][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]using[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] ([/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]var[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] factory = swapChain.GetParent<[/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Factory[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]>())[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]factory.SetWindowAssociation(form.Handle, [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]WindowAssociationFlags[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].IgnoreAltEnter);[/font][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]form.Activated += (o, e) => { [/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]swapChain.IsFullScreen = [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]true[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]; [color="#2b91af"]Cursor[font="Consolas"][size="2"][font="Consolas"][size="2"].Hide(); [/font][/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]};[/font][/font]

[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]var[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] backBuffer = [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Resource[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].FromSwapChain<[/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Texture2D[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]>(swapChain, 0);[/font][/font]
[font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]var[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] renderView = [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]new[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]RenderTargetView[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](device, backBuffer);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]device.ImmediateContext.OutputMerger.SetTargets(renderView);[/font][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]device.ImmediateContext.Rasterizer.SetViewports([/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]new[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"] [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Viewport[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"](0, 0, form.ClientSize.Width, form.ClientSize.Height, 0.0f, 1.0f));[/font][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]form.MouseEnter += (s, e) => [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Cursor[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Hide();[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]form.MouseLeave += (s, e) => [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Cursor[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Show();[/font][/font]

[font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]MessagePump[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Run(form, () => [/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]{ [/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"] [/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]device.ImmediateContext.ClearRenderTargetView(renderView, [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]Color[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].CornflowerBlue);[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"] swapChain.Present(0, [/font][/font][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"]PresentFlags[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].None);[/font][/font]
[font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"][font="Consolas"][size="2"][color="#2b91af"] Cursor[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"].Hide();[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]});[/font][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]swapChain.IsFullScreen = [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]false[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"];[/font][/font]

[font="Consolas"][size="2"][font="Consolas"][size="2"]device.Dispose();[/font][/font]
[font="Consolas"][size="2"][font="Consolas"][size="2"]swapChain.Dispose();[/font][/font]

Share this post


Link to post
Share on other sites
Advertisement
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:

[font="Consolas"][size="2"][font="Consolas"][size="2"]WindowsForm.AppActivated += (sender, args) => { SwapChain.IsFullScreen = [/font][/font][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"][font="Consolas"][size="2"][color="#0000ff"]true[/font][/font][/font][font="Consolas"][size="2"][font="Consolas"][size="2"]; }; [/font][/font]


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 :)

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement