简体   繁体   English

每次在屏幕外的Winform上,都无法从画图事件中忽略VM_ERASEBKGND吗?

[英]Ignoring VM_ERASEBKGND from paint event does not work every time on winform off-screen why?

I have a windows form application that draws image and geometry form in front of it. 我有一个Windows窗体应用程序,可在其前面绘制图像和几何图形。 I have a problem that occurs when I drag the windows form off-screen and bring it back on-screen, makes the part that went off-screen all cleared. 我有一个问题,当我在窗口外拖动窗口窗体并将其重新显示到屏幕上时,使所有离开屏幕的部分都被清除了。

I read that this might occurs because of windows message sending to my application the VM_ERASEBKGND and clear the part that went off-screen. 我读到这可能是由于Windows消息向我的应用程序发送了VM_ERASEBKGND并清除了屏幕外的部分而导致的。 (Am I right ? ) (我对吗 ? )

So first, I have created a test application that only displays an image and I overrides the WndProc method that does work in that case, here how it is implemented : 因此,首先,我创建了一个仅显示图像的测试应用程序,并且覆盖了在这种情况下有效的WndProc方法,在这里是如何实现的:

protected override void WndProc(ref System.Windows.Forms.Message m)
  {
     switch (m.Msg)
     {
         //0x0014 reprensts VM_ERASEBKGND message
        case 0x0014:
           //ignore this message else pass it to base
           break;
        default:
           base.WndProc(ref m);
           break;
     }
  }

Basically, I'm am just ignoring VM_ERASEBKGND message, and it does work in that case. 基本上,我只是忽略了VM_ERASEBKGND消息,在这种情况下它确实起作用。 The application is a Form that contains a PictureBox. 该应用程序是一个包含PictureBox的窗体。

Now, I wanted to integrate this to another project that is quite the same, a PictureBox into a Form, but has some more Control such has ScrollBar , Axis, GridPanel. 现在,我想将其集成到另一个完全相同的项目中,将一个PictureBox集成到一个Form中,但还有更多控件,例如ScrollBar,Axis和GridPanel。

When overwriting the WndProc method the same way I did in another project, it doesn't work even though it goes into the break point and does not process base.WndProc(ref m) . 以与在另一个项目中相同的方式覆盖WndProc方法时,即使它进入了断点并且不处理base.WndProc(ref m) ,该方法也无法正常工作。 However, it seems to doesn't care that I am not processing the message, it still does clear my Form. 但是,似乎不在乎我没有处理邮件,它仍然可以清除我的表格。

My question is : is it possible that other control like axis and scrollbar makes the form cleared when moving off-screen even though I've overwritten WndProc like in the example above and ignored ERASEBKGND. 我的问题是 :即使我已经像上面的示例一样覆盖了WndProc并忽略了ERASEBKGND,其他的控件(例如轴和滚动条)是否有可能在移出屏幕时清除表格。

This is a really weird behavior from windows since it does work in one application, but not in another which is almost the same. 从Windows来说,这是一种非常奇怪的行为,因为它确实在一个应用程序中起作用,但在几乎相同的另一个应用程序中却不起作用。

My easy trick to resolve this problem, which is not the best solutions in your case, but still works, is to override WndProc of your form and catch your VM_ERASEBKG. 解决这个问题的简单方法(这不是您的最佳解决方案,但仍然有效)是覆盖表单的WndProc并捕获您的VM_ERASEBKG。 And instead of passing to base, Present back your swapchain which redraws your swapchain. 而不是传递给基础,而是展示您的交换链,从而重绘您的交换链。

GPU and CPU from windows 32 handles often gives bad behavior when using DirectX with winforms. 将DirectX与Winforms一起使用时,Windows 32手柄上的GPU和CPU通常会产生不良行为。

Protected Overrides Sub WndProc(ByRef m As Message)
      Select Case m.Msg
         Case VM_ERASEBKGND
            swapchain.Present(1,PresentFlags.None)
            Exit Select
         Case Else
            MyBase.WndProc(m)
            Exit Select
      End Select
   End Sub

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM