• Advertisement
Sign in to follow this  

[DXGI]Disabling Alt+Enter?

This topic is 1876 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

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 smile.png ). 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.


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());
}
}



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
Advertisement
You can use the IDXGIFactory::MakeWindowAssocation function to disable Alt+Enter: http://msdn.microsof...0(v=vs.85).aspx

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



// 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();



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


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();


Guess what? Didn't work.

However, using DXGI_MWA_NO_WINDOW_CHANGES does 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
You need pSwapChain->GetParent for MWA.

I have this working in my own code and I'll dig it out later on this evening for you if you need it.

Share this post


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

IDXGIFactory1 *pFactory = NULL;

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


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
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
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 happy.png. However, they have the same problem I had with the beeping in windowed mode laugh.png

Share this post


Link to post
Share on other sites
Some more info and discussion on the beep here: http://stackoverflow.com/questions/3662192/disable-messagebeep-on-invalid-syskeypress

Share this post


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

  • Advertisement