Jump to content

  • Log In with Google      Sign In   
  • Create Account

[DXGI]Disabling Alt+Enter?


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
11 replies to this topic

#1 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 11 November 2012 - 08:45 AM

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 Posted Image ). 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, 11 November 2012 - 09:06 AM.


Sponsor:

#2 Erik Rufelt   Crossbones+   -  Reputation: 3479

Like
0Likes
Like

Posted 11 November 2012 - 09:07 AM

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, 11 November 2012 - 09:10 AM.


#3 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 11 November 2012 - 09:29 AM

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.

#4 mhagain   Crossbones+   -  Reputation: 7978

Like
1Likes
Like

Posted 11 November 2012 - 10:46 AM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#5 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 11 November 2012 - 11:13 AM

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.

#6 mhagain   Crossbones+   -  Reputation: 7978

Like
1Likes
Like

Posted 11 November 2012 - 11:16 AM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#7 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 11 November 2012 - 11:29 AM

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

#8 mhagain   Crossbones+   -  Reputation: 7978

Like
2Likes
Like

Posted 11 November 2012 - 01:26 PM

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.

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#9 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 15 November 2012 - 10:52 AM

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?

#10 hupsilardee   Members   -  Reputation: 486

Like
0Likes
Like

Posted 03 December 2012 - 10:31 PM

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

#11 mhagain   Crossbones+   -  Reputation: 7978

Like
0Likes
Like

Posted 04 December 2012 - 04:42 AM

Some more info and discussion on the beep here: http://stackoverflow.com/questions/3662192/disable-messagebeep-on-invalid-syskeypress

It appears that the gentleman thought C++ was extremely difficult and he was overjoyed that the machine was absorbing it; he understood that good C++ is difficult but the best C++ is well-nigh unintelligible.


#12 Endurion   Crossbones+   -  Reputation: 3575

Like
1Likes
Like

Posted 04 December 2012 - 09:27 AM

As a game player I'd prefer to have Alt-Enter in, this is IMHO quasi standard; whereas F4 feels like the odd one out.

What's so bad about having both?
Fruny: Ftagn! Ia! Ia! std::time_put_byname! Mglui naflftagn std::codecvt eY'ha-nthlei!,char,mbstate_t>




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.



PARTNERS