Transparent Windows

  • Thread starter Thread starter Aaron Pfeifer
  • Start date Start date
A

Aaron Pfeifer

I'm developing an application in c#. What I'd like to do is
display a transparent window but remove all functionality
from it, like being able to click on it, activate it, etc.
That is, I'd like to display this transparent window, and
then display another window directly beneath it which i can
click on and use as if the transparent window weren't there.

Take for example, the ThruView feature in ATI's TV Player.
"ThruView" allows you to set the TV as a translucent window
in the background that can be seen through active
applications. This enables you to view TV and work on
applications at the same time. So it just blends in with
your applications, but you can't actually click on the tv.
It just blends in with all of your other windows.

I'd like to replicate this functionality in .NET,
preferably c#, but cannot figure out how to. The
transparency feature doesn't work and forwarding messages
that I intercept in WndProc() doesn't seem like a clean
solution. Any ideas?

Thanks in advance!
 
Hi, Aaron,

I've got a project that does this.

Instead of making parts of your window transparent, on Load(), set your
form's Region to be a shape that excludes the region you want to be
transparent.

Some of my windows wanted to be translucent, which I do the same way,
but then have the underlying window draw a highlight; this might not
work for you. Let me know if you need some code for this; I'm afraid
mine's pretty convoluted, but maybe it could be a starting point.
Here's a sample, slightly reworked for (hah!) clarity:

in the form constructor:
this.Load += new EventHandler(MakeShape);


protected void MakeShape(object sender, EventArgs e)
{Region = MakeFormRegion();}


public Region MakeFormRegion()
{
Rectangle outer = new Rectangle(0, 0, width, height);
Region result = new Region(outer);
Rectangle inner = new Rectangle(2, 2, width-4, height-4);
Region hole = new Region(inner);
result.Exclude(hole);
return result;
}

Peace,
--Carl
 
Hey Carl,

Thanks for the reply. I think I was not so clear on the type of feature I
was looking for. I kept saying transparent, when I actually meant opaque.
So I was looking to display a form (with no borders) that would have an
opaque background image. I wanted to be able to click on this form, but for
that event to actually go through the form to the window beneath it.

Making a certain part of the window completely transparent is a good idea,
but i always want the form completely shown.

It's probably best to understand if you looked at a project I found on
codeproject.com that acted as the base for my solution. The link is:

http://www.codeproject.com/csharp/floatingForm.asp

In this solution, the person has actually subclassed NativeWindow and caught
the WM_NCHITTEST message. When this message is caught, the Result property
is changed to (IntPtr) -1. As a result, for any windows in the same thread,
this event will pass through and go to the window beneath it.

If you try running the sample program at the link above and move the
floating form above a regular windows form, you'll notice that clicking
anywhere below the titlebar on the floating form will pass right through it
to the form beneath it (even though it's opaque).

Also, this example showed me how to create a window that won't show up by
pressing Alt+Tab or in the taskbar. It's a really interesting piece of code.

Anyway, thanks for the help! Take care.

Aaron
 
Back
Top