Disable alt-enter in Direct3D application (DirectX)

I read An Introduction to 3D Programming Games with DirectX 10 to learn DirectX, and I tried to complete the suggested exercises (chapter 4 for those who have a book).

In one exercise, it is suggested to disable the Alt + Enter function (switch full screen mode) using IDXGIFactory::MakeWindowAssociation .

However, it still switches to full-screen mode, and I cannot understand why. This is my code:

 HR(D3D10CreateDevice( 0, //default adapter md3dDriverType, 0, // no software device createDeviceFlags, D3D10_SDK_VERSION, &md3dDevice) ); IDXGIFactory *factory; HR(CreateDXGIFactory(__uuidof(IDXGIFactory), (void **)&factory)); HR(factory->CreateSwapChain(md3dDevice, &sd, &mSwapChain)); factory->MakeWindowAssociation(mhMainWnd, DXGI_MWA_NO_ALT_ENTER); ReleaseCOM(factory); 
+7
c ++ directx direct3d directx-10
source share
2 answers

I think the problem is this.

Since you create the device yourself (and not through the factory), any calls made in the created factory will not change anything.

So, either you:

a) Create a factory earlier and create a device through it

OR

b) Extract the factory, which is actually used to create the device through the code below.

 IDXGIDevice * pDXGIDevice; HR( md3dDevice->QueryInterface(__uuidof(IDXGIDevice), (void **)&pDXGIDevice) ); IDXGIAdapter * pDXGIAdapter; HR( pDXGIDevice->GetParent(__uuidof(IDXGIAdapter), (void **)&pDXGIAdapter) ); IDXGIFactory * pIDXGIFactory; pDXGIAdapter->GetParent(__uuidof(IDXGIFactory), (void **)&pIDXGIFactory); 

And call the function through factory (after creating the SwapChain)

 pIDXGIFactory->MakeWindowAssociation(mhMainWnd, DXGI_MWA_NO_ALT_ENTER); 

MSDN: IDXGIFactory

+9
source share

I have the same problem and

b) Extract the factory, which is actually used to create the device through the code below.

also doesn't help me because I have many Direct3D10 windows, but IDXGIFactory :: MakeWindowAssociation remembers it for only one. But calling the function on WM_SETFOCUS or WM_ACTIVATE also did not help for an unknown reason.

So, one of the ways I found is to use a low-level keyboard hook: see SetWindowsHookEx with the WH_KEYBOARD_LL parameter. Later you can catch Alt + Enter with the virtual code VK_RETURN with the condition that (VK_LMENU | VK_RMENU | VK_MENU) is already pressed. After you recognize this situation, simply return 1 instead of calling the CallNextHookEx function.

+1
source share

All Articles