我只是偶然发现了这个令人讨厌的行为,同时在示例程序上添加了全屏支持。
创建一个全屏窗口是可行的,但是只要我在包含全屏窗口的输出上移动任何窗口(来自另一个应用程序),它就会自动切换回窗口化。
有什么办法可以防止这种行为(所以全屏窗口不会回到窗口)?
作为参考,这是一个小的独立示例(因此可以轻松复制问题)。
另外,如果这有用,我正在 Windows 8.1 上运行。
我已经尝试更改 WindowAssociationFlags 和 SwapChainFlags,均未成功,与使用 FlipSequential 而不是 Discard 相同
SharpDX.DXGI.Factory2 factory = new SharpDX.DXGI.Factory2();
SharpDX.DXGI.Adapter adapter = factory.GetAdapter(0);
var renderForm1 = new RenderForm("Form 1");
factory.MakeWindowAssociation(renderForm1.Handle, SharpDX.DXGI.WindowAssociationFlags.IgnoreAll);
Device device = new Device(adapter, DeviceCreationFlags.BgraSupport);
SharpDX.DXGI.SwapChainDescription sd = new SharpDX.DXGI.SwapChainDescription()
{
BufferCount = 2,
ModeDescription = new SharpDX.DXGI.ModeDescription(0, 0, new SharpDX.DXGI.Rational(50, 1), SharpDX.DXGI.Format.R8G8B8A8_UNorm),
IsWindowed = true,
OutputHandle = renderForm1.Handle,
SampleDescription = new SharpDX.DXGI.SampleDescription(1,0),
SwapEffect = SharpDX.DXGI.SwapEffect.Discard,
Usage = SharpDX.DXGI.Usage.RenderTargetOutput,
Flags = SharpDX.DXGI.SwapChainFlags.None
};
var swapChain1 = new SharpDX.DXGI.SwapChain(factory, device, sd);
renderForm1.Left = 1922; //Just hardcoded here to move window to second screen
renderForm1.Width = 1920;
renderForm1.Height = 1080;
renderForm1.FormBorderStyle = FormBorderStyle.None;
swapChain1.SetFullscreenState(true, null);
swapChain1.ResizeBuffers(2, 1920, 1080, SharpDX.DXGI.Format.R8G8B8A8_UNorm, SharpDX.DXGI.SwapChainFlags.AllowModeSwitch);
var resource = Texture2D.FromSwapChain<Texture2D>(swapChain1, 0);
var renderView = new RenderTargetView(device, resource);
RenderLoop.Run(renderForm1, () =>
{
device.ImmediateContext.ClearRenderTargetView(renderView, new SharpDX.Color4(1, 0, 0, 1));
swapChain1.Present(1, SharpDX.DXGI.PresentFlags.None);
});
编辑:我还尝试了一个 c++ 示例(刚刚从 Microsoft 获取了 DirectX11 基础教程并添加了全屏开关),这导致了相同的行为,所以这不是 SharpDX 特定的问题。
我查看了消息循环,一旦发生这种情况,第一个全屏模式会更改回窗口模式,并且我会收到一条 WM_DISPLAYCHANGE 消息)。