Sign in to follow this  
hupsilardee

[DXGI]Disabling Alt+Enter?

Recommended Posts

hupsilardee    491
I do love the easy fullscreen switching in D3D10+. However I would not like this to be controlled via Alt+Enter, I prefer F4 to toggle fullscreen. (A throwback to my GameMaker days [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img] ). The below code controls fullscreen-switching, but why does Alt+Enter still work? The pSwapChain was definitely created without DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH.

[code]
bool Device::IsFullscreen()
{
BOOL fs;
pSwapChain->GetFullscreenState(&fs, NULL);
return (bool)fs;
}
void Device::SetFullscreen(bool fs)
{
BOOL dummy = (BOOL)fs;
pSwapChain->SetFullscreenState(&dummy, NULL);
}

// Yeah I am aware that multi-monitor systems might break this... I promise to fix that later!

void UpdateGame()
{
// message pump

if (input->KeyPressed(VK_F4))
{
// F4 toggles fullscreen
pDevice->SetFullscreen(!pDevice->IsFullscreen());
}
}

[/code]

Also, how do people get those nice blue tags on their topics? Edited by hupsilardee

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
You can use the IDXGIFactory::MakeWindowAssocation function to disable Alt+Enter: [url="http://msdn.microsoft.com/en-us/library/windows/desktop/bb174540%28v=vs.85%29.aspx"]http://msdn.microsof...0(v=vs.85).aspx[/url]

Mode switch refers to changing the monitor resolution to match the back-buffer. Even without mode switch the swap-chain can go to fullscreen mode with the desktop resolution. Edited by Erik Rufelt

Share this post


Link to post
Share on other sites
hupsilardee    491
Thanks for the quick reply. I found that page as well but was unable to get it to work. Here's the device/swap chain creation (minus error checking etc)

[code]

// Initialise SwapChainDesc...
SwapChainDesc.Flags = 0;

IDXGIFactory* factory;
CreateDXGIFactory(IID_IDXGIFactory, (void**)&factory);
HRESULT hr = D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, 0/*flags*/, D3D10_SDK_VERSION, &pDevice);
hr = factory->CreateSwapChain(pDevice, &SwapChainDesc, &pSwapChain);
hr = factory->MakeWindowAssociation(window->GetHWND(), DXGI_MWA_NO_ALT_ENTER);

factory->Release();

[/code]

I checked the HR line-by-line using breakpoints. All returns S_OK. But Alt+Enter Still Works! I can't leave this alone because Alt and Enter are both likely to be used as character controls, and it's very conceivable that the player might press both.

Share this post


Link to post
Share on other sites
mhagain    13430
This is fun.

There is a serious omission in the D3D documentation surrounding the MakeWindowAssociation call; what it fails to mention (IIRC it hints at it but never states it outright) is that the IDXGIFactory used for MakeWindowAssociation must be retrieved via calling IDXGISwapchain::GetParent first. Then it works; otherwise it won't.

Share this post


Link to post
Share on other sites
hupsilardee    491
This is also fun. Found this discussion on stackoverflow

http://stackoverflow.com/questions/2353178/disable-alt-enter-in-a-direct3d-directx-application

So I changed my startup code. (Again, without error checking)

[code]
DWORD flags = 0;
#ifdef _DEBUG
flags |= D3D10_CREATE_DEVICE_DEBUG;
#endif
//if (SingleThreadedD3D10)
//{
//flags |= D3D10_CREATE_DEVICE_SINGLETHREADED;
//}
HRESULT hr = D3D10CreateDevice(NULL, D3D10_DRIVER_TYPE_HARDWARE, NULL, flags, D3D10_SDK_VERSION, &pDevice);
IDXGIDevice* dxgiDevice;
IDXGIAdapter* adapter;
IDXGIFactory* factory;
pDevice->QueryInterface(IID_IDXGIDevice, (void**)&dxgiDevice);
dxgiDevice->GetParent(IID_IDXGIAdapter, (void**)&adapter);
adapter->GetParent(IID_IDXGIFactory, (void**)&factory);
hr = factory->CreateSwapChain(pDevice, &SwapChainDesc, &pSwapChain);
hr = factory->MakeWindowAssociation(window->GetHWND(), DXGI_MWA_NO_ALT_ENTER);
factory->Release();
adapter->Release();
dxgiDevice->Release();
[/code]

Guess what? Didn't work.

However, using DXGI_MWA_NO_WINDOW_CHANGES [i]does[/i] work, but it makes a Windows beep. Now I would like to get rid of this. What a pain.

Share this post


Link to post
Share on other sites
hupsilardee    491
I would really appreciate it if it's not too much trouble, mhagain. However I can now call the problem half-solved. If I use MWA_NO_WINDOW_CHANGES along with the above code, Alt+Enter doesn't toggle fullscreen. It does make a beeping, only in windowed mode, but most people play games in fullscreen anyway.

Although now I'm worrying about the other effects of MWA_NO_WINDOW_CHANGES

Share this post


Link to post
Share on other sites
mhagain    13430
OK, first things first, I'm using D3D11. That shouldn't matter much as the basic process is the same; just so you're aware of it.

Secondly, I create using D3D11CreateDeviceAndSwapchain - that may be relevant and I'd recommend that for D3D10 you also use D3D10CreateDeviceAndSwapchain, if for no other reason, to rule out uncertainty/difference in the basic creation.

On to the code:

[CODE]IDXGIFactory1 *pFactory = NULL;

if (SUCCEEDED (d3d11_SwapChain->GetParent (__uuidof (IDXGIFactory1), (void **) &pFactory)))
{
pFactory->MakeWindowAssociation (vid.Window, DXGI_MWA_NO_ALT_ENTER);
pFactory->Release ();
}[/CODE]

That's literally it. No need for DXGI_MWA_NO_WINDOW_CHANGES and no beep happens.

Share this post


Link to post
Share on other sites
hupsilardee    491
Thanks for the help mhagain. However it STILL doesn't work for me :( Perhaps it's because you are using DXGI 1.1? Should I start using DXGI 1.1 or will that cause problems for people on Vista who don't install their service packs?

Share this post


Link to post
Share on other sites
hupsilardee    491
Hello again. Sorry to resurrect such an old thread, but I thought I would post with 2 things:

Firstly, the problem has been solved :)

Secondly, I've been playing Black Ops 2 recently, and I noticed to my amusement that Alt+Enter is not disabled; handy for playing in windowed mode so people who knock on my door remain convinced that I'm being productive [img]http://public.gamedev.net//public/style_emoticons/default/happy.png[/img]. However, they have the same problem I had with the beeping in windowed mode [img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img]

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this