views:

1675

answers:

3

I have a window with these values:

WindowState="Maximized"
AllowsTransparency="True"
Opacity="0.5"
WindowStyle="None"

This window is coming on top of other window (as a pop-up) with content on it on a specific location.

I have a new requirement. This window have to show a rectangle area from the window below. In other words, i have to set a "hole" in this window which will be totally transparent (without the opacity value). Until this moment i couldn't figure out a way to make this transparent hole.

Hope to get an idea...

+1  A: 

try to avoid AllowsTransparency=true, it is very buggy and slow.

you can PInvoke SetWindowRgn to create a a window of any shape:

  1. Use CreateRectRgn twice, once for the window bounding rectangle and once for the hole.
  2. Use CombineRgn with RGN_AND as the 4th parameter to get a region with an hole in it
  3. Call SetWindowRgn to apply the region to the window
  4. Don't forget to delete all the regions except for the one you passed to SetWindowRgn
Nir
Thanks for your answer,I found it a little bit impossible to create a window region with a hole inside it... or maybe you know a way to do it?
Satumba
I've added instructions about how to create a region with an hole.
Nir
Thanks dude, although i decided to use my solution i marked your suggestion as the answer.
Satumba
+3  A: 

I found a kind of solution for it:

this is the pop-up window that on top of another window, and containing a hole to the other window in a desired place:

Window's header:

    WindowState="Maximized"
    AllowsTransparency="True"
    WindowStyle="None"

Window's content:

<Window.Background >
    <SolidColorBrush x:Name="BackgroundBrush" Color="WhiteSmoke" Opacity="0" ></SolidColorBrush>
</Window.Background>
<Canvas x:Name="ContectHolder" >
    <Path Stroke="Black" Fill="WhiteSmoke" Opacity="0.8">
        <Path.Data>
            <CombinedGeometry GeometryCombineMode="Exclude">
                <CombinedGeometry.Geometry1  >
                    <RectangleGeometry Rect="0,0,2000,2000"  />
                </CombinedGeometry.Geometry1>
                <CombinedGeometry.Geometry2>
                    <RectangleGeometry Rect="75,75,400,900" />
                </CombinedGeometry.Geometry2>
            </CombinedGeometry>
        </Path.Data>
    </Path>
</Canvas>
Satumba
A: 

Simple solution:

http://www.java2s.com/Code/CSharp/GUI-Windows-Form/TransparentFormsholes.htm

Jorge Varas
That's not WPF..
Ant
Not a relevant answer
Satumba