最小化Alt Tab上的DirectX 10窗口

时间:2013-04-17 09:20:49

标签: c++ winapi directx directx-10

我一直试图让我的DirectX 10应用程序正确处理全屏幕的alt选项卡。当我从全屏播放选项卡时,应用程序会自动进入窗口模式。

我尝试监听WM_ACTIVATEAPP以手动最小化并最大化程序。它可以工作,但它打破了已经工作的程序中的其他功能(在全屏和窗口之间切换)。从alt选项卡恢复后第一次尝试从全屏切换时,黑屏闪烁并保持全屏,第二次触发WM_ACTIVATEAPP导致整个程序最小化而不是正确进入窗口模式

以下是我正在使用的代码:

关于WM_SIZE:

mD3D->ResizeBuffers(width, height);
mBufferWidth = width;
mBufferHeight = height;
mViewport.SetViewportRect(0, 0, width, height);
mD3D->GetDevice()->RSSetViewports(1, &mViewport.GetViewport());

在WM_ACTIVATEAPP上:

if(wParam == TRUE && mSwapChainDesc.Windowed == FALSE)
{
  // Restore
  ChangeDisplaySettings(NULL, CDS_FULLSCREEN);
  mSwapChain->SetFullscreenState(TRUE, NULL);
  mSwapChainDesc.Windowed = FALSE;
  ResizeBuffers(mBufferWidth, mBufferHeight);
}
else if(wParam == FALSE && mSwapChainDesc.Windowed == FALSE)
{
  // Minimize
  ShowWindow(hwnd, SW_SHOWMINNOACTIVE);
  mSwapChain->SetFullscreenState(FALSE, NULL);
  ChangeDisplaySettings(NULL, 0);
}

开启窗口模式请求:

if(mSwapChainDesc.Windowed)
{
  mSwapChain->SetFullscreenState(TRUE, NULL);
  mSwapChainDesc.Windowed = FALSE;
}
else
{
  mSwapChain->SetFullscreenState(FALSE, NULL);
  mSwapChainDesc.Windowed = TRUE;
}
ResizeBuffers(mBufferWidth, mBufferHeight);

ResizeBuffers:

mDevice->OMSetRenderTargets(0, 0, 0);

// Release all outstanding references to the swap chain's buffers.
mRenderTargetView->Release();

HRESULT hr;
// Preserve the existing buffer count and format.
// Automatically choose the width and height to match the client rect for HWNDs.
hr = mSwapChain->ResizeBuffers(1, width, height, DXGI_FORMAT_UNKNOWN, 0);

// Get buffer and create a render-target-view.
ID3D10Texture2D* pBuffer;
hr = mSwapChain->GetBuffer(0, __uuidof( ID3D10Texture2D), (void**) &pBuffer );

hr = mDevice->CreateRenderTargetView(pBuffer, NULL, &mRenderTargetView);
pBuffer->Release();

mDevice->OMSetRenderTargets(1, &mRenderTargetView, NULL );

// Set up the viewport.
D3D10_VIEWPORT vp;
vp.Width = width;
vp.Height = height;
vp.MinDepth = 0.0f;
vp.MaxDepth = 1.0f;
vp.TopLeftX = 0;
vp.TopLeftY = 0;
mDevice->RSSetViewports( 1, &vp );

如何最小化窗口并仍然能够使用DirectX 10在窗口和全屏之间切换?

0 个答案:

没有答案