In Windows Vista, under Control Panel
à
Personalize menu, you see screen saver option, which opens up a dialog “Screen
Saver Settings”
The calling of the screen saver program
from this dialog involves three command line options. /S is passed to your
program Main method to start the screen saver; /P hwnd is passed to
preview the screen saver on top of the current dialog with the handle
hwnd; /C hwnd is passed to show configuration window for the
screen saver on top of the current dialog with the handle
hwnd;
Introduction
WpfMystify3D is a screen saver
application that is currently available in both the Desktop Mode and Windows
User mode. Users may directly run the application upon downloading the zip files
that comes along with this.
The Main method:
[STAThread]
static public int Main(string[]
args)
{
App a = new App();
if
(args[0].ToUpper().StartsWith("/S"))
{
a.Run(new
Mystify());
}
else if
(args[0].ToUpper().StartsWith("/C"))
{
return a.Run(new
Settings());
}
else if
(args[0].ToUpper().StartsWith("/P"))
{
var parentHandle =
args[1];
a.Run(new
Mystify());
}
return 0;
}
As you notice, the screen saver window
and the configuration window gets opened as per the command line argument. The
preview mode currently does not involve checking of any parent window handles.
The WPF window comfortable sits on top of all the other active windows using the
attribute TopMost=true.
Application features:
This application displays 3D graphical
elements mystified based on the configurations set in the Xml file named
“WpfMystifySettings.xml”. This Xml file is stored in the applications
folder and is read every time the screen saver is activated or the settings been
changed by the user.
While running the application, certain
function keys are enabled to perform certain actions.
F2 – This shows the Screen Saver
settings dialog where in you may change the attributes of the graphical
elements.
Esc – This exit the
application.
If any key is pressed or mouse moved or
clicked, the application exits.
Reading the Screen Saver
Settings
private void
GetScreenSaverSettings()
{
XmlDocument xData = new
XmlDocument();
xData.Load(@"..\..\WpfMystifysettings.xml");
XmlElement root =
xData.DocumentElement;
XmlNode node =
root.SelectSingleNode("Settings/MeshType");
meshtype =
node.InnerText;
node =
root.SelectSingleNode("Settings/Rotation");
rotation =
node.InnerText;
node =
root.SelectSingleNode("Settings/Design");
design =
node.InnerText;
node =
root.SelectSingleNode("Settings/Background/Color1");
color1
=Color.FromRgb(byte.Parse(node.InnerText), 0,0);
node =
root.SelectSingleNode("Settings/Background/Color2");
color2 = Color.FromRgb(0,
byte.Parse(node.InnerText), 0);
node =
root.SelectSingleNode("Settings/Background/Color3");
color3 =
Color.FromRgb(0,0,byte.Parse(node.InnerText));
}
The above code gets the values for the
attributes MeshType, GradientColors, Design and Rotation from the xml file.
Here, MeshType refers to the GeometryModel3D that could be a Plane, Cube or
Sphere. GradientColors are used to set the RadialGradientBrush for the
background application of the 3D model. Design takes the values Floral, Ocean
and Grid and these refers to the picture files that are used to apply as
material for the foreground and background surface of GeometryModel3D.
The sample XML file for the settings
is given below:
<?xml version="1.0"
encoding="utf-8"?>
<WpfMystify>
<Settings>
<MeshType>Cube</MeshType>
<Rotation>Both</Rotation>
<Design>Ocean</Design>
<Background>
<Color1>123</Color1>
<Color2>80</Color2>
<Color3>147</Color3>
</Background>
</Settings>
</WpfMystify>
Rotation might be Horizontal, Vertical
or Both. I have two story boards, one for the horizontal transformation of the
surface and the other for vertical transformation of the surface. User can set
both the storyboards running simultaneously. The following XAML code provides
the declarative part of these story boards.
<Storyboard
x:Key="RotateStoryboardHorizontal">
<ParallelTimeline
RepeatBehavior="Forever" Storyboard.TargetName="myRotateInner"
Storyboard.TargetProperty="Angle" >
<DoubleAnimation
From="0" To="360" Duration="0:0:20"/>
</ParallelTimeline>
</Storyboard>
<Storyboard
x:Key="RotateStoryboardVertical">
<ParallelTimeline
RepeatBehavior="Forever" Storyboard.TargetName="myRotateOuter"
Storyboard.TargetProperty="Angle" >
<DoubleAnimation
From="0" To="360" Duration="0:0:30"/>
</ParallelTimeline>
</Storyboard>
Output Screen Saver
Designs:
Ocean:
|