Welcome to MSDN Blogs Sign in | Join | Help

Lester's WPF blog


Simple, easy & beautiful

News

Part II : Creating Non-Rectangular Splash Screen - using WPF

There was a delay in posting this and guess what - the reason was that the feature was not available in the Jan CTP bits. So I had to wait for the Feb CTP bits to be released. So here is how a simple flash screen could be implemented in WPF.

 

void OnClick(object sender, RoutedEventArgs e)

{

   HwndSourceParameters s = new HwndSourceParameters("visual");

   HwndSourceParameters param = new HwndSourceParameters("vis", 200, 200);

   param.UsesPerPixelOpacity = true;

   

   HwndSource hwndSource = new HwndSource(param);

   using (System.IO.Stream xamlStream = System.IO.File.OpenRead("XamlPad_Saved.xaml"))

   {

      hwndSource.RootVisual = XamlReader.Load(xamlStream) as Visual;

   }

   ShowWindow(hwndSource.Handle, 5);

}

[DllImport("user32.dll", CharSet = CharSet.Auto)]

public static extern bool ShowWindow(IntPtr hWnd, int nCmdShow);

Wasnt that simple. The property that was missing in the Jan CTP bits is UsesPerPixelOpacity. Now thats what does the trick. A snapshot of what this looks like is below:

So the flash screen is the moon. If you put in a timer which closes it then you have your initial flashscreen. And for those who were wondering what the xaml that creates the moon looks like, here it goes:

<StackPanel xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" >

<Path Stroke="Black" StrokeThickness="1" Fill="#CCCCFF">
  <Path.Data>
    <!-- Combines two geometries using the exclude combine mode. -->
    <CombinedGeometry GeometryCombineMode="Exclude">
      <CombinedGeometry.Geometry1>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="75,75" />
      </CombinedGeometry.Geometry1>
      <CombinedGeometry.Geometry2>
        <EllipseGeometry RadiusX="50" RadiusY="50" Center="125,75" />
      </CombinedGeometry.Geometry2>
    </CombinedGeometry>
  </Path.Data>
</Path>
 </StackPanel >
 

hmmm... yeah its taken from the SDK ;) ...it has lots of samples and is a good resource to have at hand.

Posted: Friday, February 24, 2006 5:48 PM by llester
Filed under: , , ,

Comments

Nick on Windows Presentation Foundation (Avalon) said:

Lester Lobo posted an example of UsesPerPixelOpacity=true: http://blogs.msdn.com/llobo/archive/2006/02/24/538757.aspx...
# February 27, 2006 7:47 PM

Олег Михайлик said:

Окошки непрямоугольной формы, с тенями и прозрачностью — это, конечно, визуальны
# March 2, 2006 5:27 AM

Ricciolo said:

# March 3, 2006 5:00 AM

lijincheng said:

how to open a half-transparent window?

# October 11, 2006 4:53 AM
New Comments to this post are disabled
Page view tracker