-
One of Coding4Fun’s favorite contributor, Arian Kulp, was awarded the Microsoft MVP award for Visual C#. Last year another one of our contributors, Brian Peek, won the award. And Brian was awarded again this year!
Awesome work guys.
And as always, if you are interested in becoming a contributor like Arian and Brian, contact Code4Fun@microsoft.com. We’d love to have you.
-
Chris Craft decided to do 30 days of Windows Mobile development. Seeing some of the applications Chris created, I must say, I was a tad jealous. Getting past my bruised ego, I started checking out the applications he wrote and saw some really neat stuff.
He has multiple applications that use GPS, a SMS logger, a drawing application, a trip planner, Bluetooth manager, …
Chris even has a recap of week 1, week 2 and week 3!
-
This year the XNA team have up’ed the ante with their Dream-Build-Play challenge. You can have a team between 1 to 7 people and have to create a game for the Xbox 360. There are $75,000 in prizes along with a chance to receive an Xbox LIVE publishing contract!
Key facts to pay attention to:
- The game must be playable on the Xbox 360.
- Entries are due between 9/1/2008 - 9/23/2008
- Max size is 200mb
- Winners announced on October
For additional information, head over to http://dreambuildplay.com.
-
Summary:
Bluetooth is now found in a variety of devices and enable the user to use wireless accessories. The Bluetooth protocol allows a user to “discover” any device that is in proximity to your Bluetooth radio. Why not see who is in proximity to you? Why not have the presence of a device execute programs or alert you?
Andy Konkol – http://copyandwaste.com
Hardware:
-
Bluetooth radio (USB dongle)
-
SMA Female Jack
-
SMA male to N-male pigtail
-
2.4 GHz antenna (with N-female connector)
Software:
Download:
Bluetooth and Hardware:
Bluetooth was designed for devices to communicate wirelessly over short distances. However, with a very simple hardware modification you can extend the range of your Bluetooth radio with standard 2.4ghz antennas used in wireless networking (802.11 a/b/g).
Modifying Bluetooth dongles to accept external antennas is documented all over the Internet. In principle it is very easy: find the antenna lead and solder on a connector/antenna. I purchased a very cheap Bluetooth USB dongle on eBay and opened the casing. After finding the antenna trace on the circuit board I soldered on a SMA Female connector to it. After soldering the antenna jack in place I slipped a 3 inch chunk of heatshrink and heated it to cover the exposed circuit board. Now I had a Bluetooth radio that accepts external antennas. Adding an antenna simply increases the range of your radio, allowing you to “see” devices from a farther distance.
To connect an external antenna to the dongle I needed to use a connector converter called a pigtail. I used a SMA male to N-male pigtail. I connected one end of the pigtail to my dongle and the other to an omni-directional 9dbi panel antenna that had an N-female connector.
Software:
To take advantage of my newly modified hardware I needed to download the Coding4Fun Toolkit. Included in the toolkit is an API for Bluetooth devices. This API allows you to do a wide variety of things with your Bluetooth radio but I focused on two methods from the ServiceAndDeviceDiscovery library: DiscoverAllDevices and DiscoverDeviceByName.
DiscoverAllDevices allows you to “scan” the airwaves on the 2.4 GHz band and report back what devices your radio sees.
DiscoverDeviceByName allows you to scan for a particular device with a specified name and report back if it is present or not.
private bool DevicePresent()
{
BluetoothDeviceServicesManager workerBTMgr = new BluetoothDeviceServicesManager();
Device workerDevice = workerBTMgr.DiscoverDeviceByName(_watchItem.DeviceName);
return (workerDevice != null);
}
public void Run(String Operation)
{
switch (Operation)
{
case "SingleDevice":
if (DevicePresent())
{
_parentForm.Invoke(_parentForm.AddToDeviceSeenList, new object[] { _watchItem });
}
else
{
_parentForm.Invoke(_parentForm.RemoveFromDeviceSeenList, new object[] { _watchItem });
}
break;
case "AllDevices":
BluetoothDeviceServicesManager workerBTMgr = new BluetoothDeviceServicesManager();
List<Device> Devices = workerBTMgr.DiscoverAllDevices();
_parentForm.Invoke(_parentForm.ThreadUpdateDiscoverBox, new object[] { Devices });
break;
}
}
Both of these methods require that the device you are scanning for is in discoverable mode (which most manufacturers enable by default). Using the two methods described above I was able to tell if a device is in proximity. And ultimately enabling me create alerts and execute programs based on what device is present.
To perform device discovery and not have my UI lag I had to create two worker threads. One worker thread to discover all devices and display it under my devices listbox, and another to discover devices by name specified in the “watchlist.” I am not an expert at multi-threaded programs but I managed to implement them without any major headaches.
User Interface:
Since the “Add to watchlist” and “Edit” buttons essentially do the same thing, I decided to overload a windows form. I also wanted to keep track of the parent form and disable it when the WatchItemForm was shown.
The second overload allows me to fill in the form control's text based on the data that is already set for the WatchItem that has been selected (the Edit button).
public WatchItemForm(Form1 f, String DeviceName)
{
InitializeComponent();
this._parentForm = f;
lblDeviceName.Text = DeviceName;
}
public WatchItemForm(Form1 f, WatchItem item)
{
InitializeComponent();
this._parentForm = f;
lblDeviceName.Text = item.DeviceName;
tbxPicturePath.Text = item.ImagePath;
tbxProgramPath.Text = item.ProgramPath;
this._parentForm.Enabled = true;
}
I wanted to have a pop up notify window similar to outlook and was able to find Robert Misiak's NotifyWindow. This is a very simple library which allows you to create pop up notify windows very easily. I edited NotifyWindow to include a “picturepath” variable as well as picturebox on the form. As you can see creating a NotifyWindow is quite easy:
public void NotifyDeviceWindow(WatchItem x)
{
NotifyWindow nw;
nw = new NotifyWindow();
//validate Alert Message
if (x.AlertMessage == null)
{
nw.Text = x.DeviceName;
}
else
{
nw.Text = x.AlertMessage;
}
//validate picture
if (x.ImagePath != null)
{
FileInfo imgfile = new FileInfo(x.ImagePath);
if (imgfile.Exists)
{
nw.PicturePath = x.ImagePath;
}
else
{
MessageBox.Show("Image does not exist");
}
}
nw.Notify();
if (x.ProgramPath != null)
{
RunProcess(x.ProgramPath);
}
}
Process Flow/Software Operation:
- User clicks the “Discover” button, a thread is spawned which enumerates all Bluetooth devices in proximity
- Thread finishes and updates the Devices listbox
- User selects a discovered device and clicks “Add to watchlist” A watch item form is spawned and asks you for an alert message, a picture path, and an executable path
- User clicks save , a WatchItem object is created and added to the watchList object
- A timer starts and every 10 seconds a thread is spawned to discover that device by name
- If the device is discovered, it is added to the “deviceSeenList” and a notify alert is sent and the executable is executed.
- If that device is still present after the next timer click, no notification is sent, If that device is not present it is removed from the “deviceSeenList”
Screenshots:
-
Dan Fernandez had been keeping busy and recently did a talk over at TechEd for Coding4Fun. He did a talk on programming using the iTunes, YouTube, Zune, Vista Peer-to-Peer, and World of Warcraft API sets. Here are some direct source links.
Dan even released is PPT deck.
-
Summary
Creating custom wallpaper is easy. But what about custom screen savers? This post will detail how to build a custom saver using Windows Presentation Framework (WPF). The posted code also provides some insight on how to create interesting particle effects using WPF’s animation engine, and how to implement multiple monitor support in .Net.
Erik Klimczak - Clarity Consulting
Download
Introduction
Microsoft Unified Communications (UC) is a new technology that has been getting a lot of hype in the past couple of months. UC is essentially the integration of messaging, voice, and video across the applications and devices that people use every day. More information about UC can be found here. One of the coolest things about UC is the concept of “presence” (see below). The Presence indicator effectively allows the user to reflect his/her status in other Office Communicator Server friendly applications (i.e. Outlook, Office communicator, Live Meeting, etc.)

While building out some communicator functionality on another project I found myself recreating the presence “bubbles” in xaml so that they could scale without losing quality (see below). I used Expression Design to re-create the presence bubbles and export then to xaml.
In doing so it occurred to me that the presence “bubbles” would make for some excellent art sprites.
So after a hop-skip-and a jump to Photoshop I found myself with a shiny new “presence art” wallpaper.

Immediately after creating the wallpaper I thought to myself, “this would also make a great screen saver”. This article will attempt to show how to build a custom WPF screen saver that implements a simple physics particle effect using the WPF animation engine.
Particle Animation
With my graphic designer hat on I knew that I wanted to create a floating particle effect. Particle effects can be used to simulate anything from rain, snow, fire to bubbles and clouds. Then by varying the presence “bubbles” in size and opacity the illusion of depth and space can be created. After some research I found the CompositionTarget.Rendering event handler in WPF. Essentially, this event is a timer that ticks all the time and fires once each time WPF decides to render a frame. Inside the event handler you have complete freedom to do whatever you want to any object. In other words, hooking CompositionTarget.Rendering is very much a "do it yourself" animation system. This event is especially good for physics-based animations and is very similar to the way Flash’s rendering engine works. The MSDN entry for this event handler can be found here.
Once I had found the appropriate animation hook I created the particle user control. This control holds the various particle attributes that will be animated. The code below shows the various properties that can be used to create very interesting physics-based effects. These properties can be used to calculate collision detection, gravitational pull and other kinetics-related effects.
C#
1: public partial class Particle : UserControl
2: {
3:
4: public Particle()
5: {
6:
7: InitializeComponent();
8: }
9:
10: public static readonly DependencyProperty StatusProperty = DependencyProperty.Register("Status", typeof(Status), typeof(Particle), new UIPropertyMetadata(Particle.StatusValueChanged));
11: public Status Status
12: {
13: get { return (Status)GetValue(StatusProperty); }
14: set { SetValue(StatusProperty, value); }
15: }
16:
17: private static void StatusValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
18: {
19: Particle myclass = (Particle)d;
20: myclass.imgStatus.Source = Application.Current.FindResource(((Status)e.NewValue).ToString() + "Png") as BitmapImage;
21: }
22:
23: public double Radius
24: {
25: get { return this.imgStatus.Height / 2; }
26: set { this.imgStatus.Height = this.imgStatus.Width = value * 2; }
27: }
28:
29: private double vy;
30: public double VY
31: {
32: get { return this.vy; }
33: set { this.vy = value; }
34: }
35:
36: private double vx;
37: public double VX
38: {
39: get { return this.vx; }
40: set { this.vx = value; }
41: }
42:
43: private double mass;
44: public double Mass
45: {
46: get { return this.mass; }
47: set { this.mass = value; }
48: }
49: private double x;
50: public double X
51: {
52: get { return this.x; }
53: set { this.x = value; }
54: }
55:
56: private double y;
57: public double Y
58: {
59: get { return this.y; }
60: set { this.y = value; }
61: }
62: }
VB
1: Partial Public Class Particle
2: Inherits UserControl
3:
4:
5: Public Sub New()
6: InitializeComponent()
7: End Sub
8:
9: Public Shared ReadOnly StatusProperty As DependencyProperty = DependencyProperty.Register("Status", GetType(Status), GetType(Particle), New PropertyMetadata(AddressOf Particle.StatusValueChanged))
10: Public Property Status() As Status
11: Get
12: Return CType(GetValue(StatusProperty), Status)
13: End Get
14: Set(ByVal value As Status)
15: SetValue(StatusProperty, value)
16: End Set
17: End Property
18:
19: Private Shared Sub StatusValueChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
20: Dim [myclass] As Particle = CType(d, Particle)
21: [myclass].imgStatus.Source = TryCast(Application.Current.FindResource((CType(e.NewValue, Status)).ToString() & "Png"), BitmapImage)
22: End Sub
23:
24: Public Property Radius() As Double
25: Get
26: Return Me.imgStatus.Height / 2
27: End Get
28: Set(ByVal value As Double)
29: Me.imgStatus.Width = value * 2
30: Me.imgStatus.Height = Me.imgStatus.Width
31: End Set
32: End Property
33:
34: Private _vy As Double
35: Public Property VY() As Double
36: Get
37: Return Me._vy
38: End Get
39: Set(ByVal value As Double)
40: Me._vy = value
41: End Set
42: End Property
43:
44: Private _vx As Double
45: Public Property VX() As Double
46: Get
47: Return Me._vx
48: End Get
49: Set(ByVal value As Double)
50: Me._vx = value
51: End Set
52: End Property
53:
54: Private _mass As Double
55: Public Property Mass() As Double
56: Get
57: Return Me._mass
58: End Get
59: Set(ByVal value As Double)
60: Me._mass = value
61: End Set
62: End Property
63:
64: Private _x As Double
65: Public Property X() As Double
66: Get
67: Return Me._x
68: End Get
69: Set(ByVal value As Double)
70: Me._x = value
71: End Set
72: End Property
73:
74: Private _y As Double
75: Public Property Y() As Double
76: Get
77: Return Me._y
78: End Get
79: Set(ByVal value As Double)
80: Me._y = value
81: End Set
82: End Property
83:
84: End Class
85:
86:
Once I had the particle class created, I decided to use a variation of a spring physics equation to get the desired float animation. The spring equation forces the particles toward each other and then springs them past each other similar to how a ball on the end of a rubber band would act when pulling it and letting it spring back and forth. Then by tweaking the force and velocity applied to each particle I successfully simulated a floating effect (I am by no means a physicist and I am sure there is a better way of implementing this equation). By combining the CompositionTarget.Rendering event and the positioning logic we can effectively scatter and animate the particles on our Canvas. The math involved looks something like this:
C#
1: void Spring(Particle a, Particle b)
2: {
3: double dx = b.X - a.X;
4: double dy = b.Y - a.Y;
5:
6: double dist = Math.Sqrt(dx * dx + dy * dy);
7: if (dist < _minDist)
8: {
9: double ax = dx * _spring;
10: double ay = dy * _spring;
11:
12: a.VX += ax;
13: a.VY += ay;
14:
15: b.VX -= ax;
16: b.VY -= ay;
17:
18: Canvas.SetLeft(a, a.X);
19: Canvas.SetTop(a, a.Y);
20:
21: Canvas.SetLeft(b, b.X);
22: Canvas.SetTop(b, b.Y);
23:
24:
25: }
26:
27: Canvas.SetLeft(a, a.X);
28: Canvas.SetTop(a, a.Y);
29:
30: Canvas.SetLeft(b, b.X);
31: Canvas.SetTop(b, b.Y);
32:
33:
34: }
35:
36: VB:
37: PrivateSub Spring(ByVal a As Particle, ByVal b As Particle)
38: Dim dx AsDouble = b.X - a.X
39: Dim dy AsDouble = b.Y - a.Y
40:
41: Dim dist AsDouble = Math.Sqrt(dx * dx + dy * dy)