3

I'm trying to create a full screen overlay over the entire screen, which will change the colors / saturation etc. of the entire screen and add some Text and effects. Basically I want to "replace" the entire screen, while the user still has the ability to interact normally with Windows.

Solution 1

The problem however is, that if I simply create a TopMost window over the entire screen, the user will not be able to interact with whatever is beneath this window.

Solution 2

Simply drawing on the desktop buffer doesn't solve the issue either. It will give nasty effects when windows are moved and also will result in heavy motion blur effects as well. This will never look good.

Solution 3

Hooking the "desktop draw event" is not possible in C# as I would have to inject a DLL into explorer.exe. This is not at all a pretty solution and will not work with C#. Also anti virus programs will likely detect it as something harmfull.


The closest thing I saw was this, but it the user will not be able to "click through" the overlay. In the example the overlay is mostly entirely transparent. Using a color other than the transparency key will result in the problem of Solution 1.

Question: How can I overlay the entire screen with effects efficiently?

Community
  • 1
  • 1
bytecode77
  • 14,163
  • 30
  • 110
  • 141

1 Answers1

0

UNTESTED

It sounds like your problem is clicking. In order to pass through your mouse messages, have you considered intercepting the mouse click on your top window, (assuming this has been set to be a transparent window), then hiding your window, fire the same mouse message using the user32 import SendMessage, and then showing your window again? If you don't want to hide your window, you can probably just call SendMessage directly to the various other window handles.

The following link shows how to cycle through the windows on the desktop of your application:

http://support.microsoft.com/kb/183009

I think you can also override the CreateParams if you have already made your form transparent. Doing so may allow the mouse events to pass through.

// This may be even simpler
protected override CreateParams CreateParams
{
    get
    {
        CreateParams createParams = base.CreateParams;
        createParams.ExStyle |= 0x00000020; // WS_EX_TRANSPARENT

        return createParams;
    }
}

You can make the form itself transparent in newer windows forms like:

public void MakeSeeThru()
{
   frmTransparentForm.Opacity = 0.83;
}

The above only works on Form. To do this on child controls takes more work. First you have to set the style to support transparent back color.

public TransparentControl()
{
    SetStyle(ControlStyles.SupportsTransparentBackColor, true);
    this.BackColor = Color.Transparent.
}

If the control is transparent, this does not stop you from overriding the OnPaintBackground and OnPaint methods and do your custom drawing if you like. It just draws with the default as a see-through background.

I've done this before and there is a bit of a blur if this moves around. However if the entire thing is a huge transparent form that covers your desktop there should be no motion blur.

If that has performance problems and you want to custom draw the desktop, you can grab a screenshot like:

ScreenCapture sc = new ScreenCapture();
// capture entire screen, and save it to a file
Image img = sc.CaptureScreen();

You will need to hide your form first though, so that will likely cause a flicker.

Ted
  • 3,212
  • 25
  • 20
  • I think that windows forms have a CreateParams property that can be overridden. This may let the top form be transparent to mouse events. – Ted Jul 19 '13 at 17:16
  • This is a really good idea! The only drawback I see is that it will cause a motion blur effect. See, I copy the image from the screen onto the form. The form will not be transparent so we only see what's on the form. Then how can I copy the desktop image if we see our "fake" image (the form) ? – bytecode77 Jul 19 '13 at 17:20
  • Basically all we need to do is copy the screen content without the overlay form. Is that somehow possible? – bytecode77 Jul 19 '13 at 17:34
  • Well, it still causes motion blur and some loss in quality. What if I want to create a color inversion effect? In this case `Opacity` will not work. I actually want the form to have an `Opacity` of `1` so I can entirely choose what should be displayed, without the motion blur. Is it somehow possible to hide the form, capture the screen and re-show it without flicker/lag? I tried it and didn't coma up with a solution for that. – bytecode77 Jul 19 '13 at 17:52