August 2008 Entries

I’m using the landscape skin for my standard Windows Mobile emulator, Windows Vista and Windows Mobile Device Center.  This is important for both just developing applications and your web pages.  This is a way to verify your sites render properly on mobile device.  My site … does not render correctly.

  1. To enable network access, we need to first go to File –> Configure then to the Network tab while in the emulator.
    image 
  2. Check the “Enable network blah blah blah” but you may get the error below
    image
  3. If you do, that means you need to get a VM network driver, the URL to get Virtual PC 2007 is: http://go.microsoft.com/fwlink/?linkid=46859.  This is a free download too.  It is 30mb.
    image
  4. Install it (you don’t even need to turn off your emulator)
  5. Start up Windows Mobile Device Center
  6. Go to Connection Settings and allow DMA.
    image
  7. Start up the Device Emulator from Visual Studio.  Tools –> Device Emulator Manager
  8. Cradle your device.  I’ve already cradled mine.
    image 
  9. Complete the first time connect screen on Windows Mobile Device Center.
  10. Start browsing
    image 

So I’ve been bitten with the developer bug as of late.  First it was playing with WPF with my ToDo application, now I’m going head deep with some Windows Mobile stuff.

I’ll be creating a Windows Mobile Standard (non-touch screen) application since I have a BlackJack 2 cell phone.  With emulators, we can do a surprising amount of work on both.

Tools

Since Visual Studio 2008 ships with Windows Mobile 5 emulators, if you want Mobile 6.0, we need to first download the emulators / SDKs.  They can be found on the left hand side at the MSDN Windows Mobile site: http://msdn.microsoft.com/en-us/windowsmobile/default.aspx

And the direct download link is:http://www.microsoft.com/downloads/details.aspx?familyid=06111A3A-A651-4745-88EF-3D48091A390B&displaylang=en

Creating a Visual Studio Solution

To create a new solution we go to File –> New –> Project.  We’ll select the language of our choice (c# for me) then go to “Smart Device”

image

Easy so far, right?  Next comes selecting the framework along with your target platform.  I currently only have Standard 6.0 so it only shows up.  Click OK and you’re good to start.

image

My cell isn’t a candy bar

As I stated before, I have a BJ2 cell so I’ll set my setting to a Landscape QVGA settings.  This is nice too since at design time, you can see how controls will render.

selectFormFactor

Now lets start coding!

inheritance[1]  For the ToDo application, I’ve been adding in some new toys and causing bugs.  One feature I’m adding in is text glow around the listed text.  So lets talk about doing this programmatically.

When doing effects (I’ll talk about .Net 3.5 SP1 also here), you really need to embrace object oriented programming here.  Why?  WPF is pretty strong on the inheritance.  If you don’t know what inheritance is, hopefully you’ll gain an understanding.  I tend to think inheritance uses the phrase “is a ”.  So a Manager is an Employee.  A TextBox is a Control.  See?  Easy.  X inherits Y’s properties.

Lets say you have a TextBox and you have a Background.  Well, a background is Brush which can be multiple things.  A SolidColorBrush or an ImageBrush are just a few examples, MSDN has a full overview of brushes too.

Lets see an example using Background via XAML:

<TextBox>
    <TextBox.Background>
        <SolidColorBrush Color="Red" />
    </TextBox.Background>
</TextBox>

Lets see the same example using c#:

  txt.Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(255,255,0,0))

See the difference?  More so see how I put a SolidColorBrush object into a Brush object?  That is due to polymorphism and inheritance.

Now lets create a WPF TextBox programmatically.

private static TextBox createTextBox()
{
    var txt = new TextBox
    {
        Background = new SolidColorBrush(System.Windows.Media.Color.FromArgb(0,0,0,0)),
        Foreground = new SolidColorBrush(Settings.Default.FontColor),
        IsEnabled = true,
        AllowDrop = false,
        BorderThickness = new Thickness(0)
    };
            
    if (Settings.Default.GlowColor.A != 0)
        txt.BitmapEffect = new OuterGlowBitmapEffect { GlowColor = Settings.Default.GlowColor, GlowSize = 5 }; ;

    return txt;
}

So one issue I’ve found is with .Net 3.5 SP1.  They will deprecate BitmapEffects but they don’t have a replacement yet for the OuterGlowBitmapEffect.  In the future you should use Effect instead of BitmapEffect.

Another issue is the needle in the haystack issue.  Unless you know about predefined brushes or effects, it is a tad annoying finding them.  Since “Effect” and “Brush” are post-append, I would personally put them in a new namespace, however .Net has a legacy of doing it the current way.  It is just so new, I haven’t memorized everything there.  I think it would be great if I had all my brushes in System.Windows.Media.Brushes.  New discovery is super easy then, oh the perfect world.

After I helped out at the Monsanto event with the pro-evangelists, I was talking with one of their engineers and he told me about a few different solutions for my chain looseness issue.

McMaster-Carr has a few solutions, each has pro’s and con’s in terms of space and cost.

Floating Roller Chain

5973kc1s

Pro’s:
  • $33 each
  • Adjustable
  • Would be perfect for the first gear set
Cons’s:
  • While 1.1” thick, .25 has to be sticking out on each side
  • 2.5” long, the gap between gears is about that.
  • No clearance on the chain with the wheel
Vertical-Mount — Manually adjustable
manualGear
Pro’s:
  • $48  each
  • Could possibly fit this in from the other side
  • 1.375” thick
Cons’s:
  • Still requires a gear
  • Tad expensive
  • Requires a gear
  • Have to modify the gear box so chain doesn’t rub

Automatic Spring Roller Chain

6233kp1s

Pro’s:
  • hmmm
Cons’s:
  • Big, 5” tall
  • Tad expensive @ $53
Low-Profile Automatic Spring Roller Chain

7332kc1ws

Pro’s:
  • .5” thick.
Cons’s:
  • $77 each

Lets show the gear box to see some of the issues I’m talking about

module_1

The gap is VERY narrow between gears, about an inch.  Also the width is 2.5”.  The wheel and big middle gear have under .25” of clearance between one another.  I would have to modify the structural supports to fit in something to the middle

I could remove the middle gear set, and then use a Vertical-Mount Tensioners or a Floating Roller Chain to accomplish this.  I’d have to cut a big hole to use the floater.  The vertical-mount tensioner I can just create a platform and extended it from the other side and either provide tension from the inside of the chain or the outside.

I could use the Automatic Spring Roller Chain too and have it mounted from the outside on a ridge mount.

No matter what, I think a phone call to my dad is in order along with a trip back to Chicago so he can help me install a solution.

IMG_0895

A button?  Coffee?

IMG_0893

What ever could the Coding4Fun crew be working on?

Technorati Profile

A friend of mine asked me a question regarding SQL and default parameters.

Here is what he ran into:

create function foo
(
      @required int, 
      @optional int = 0
)
returns int
as
begin
      return(select @required)
end
go

But if he ran it with this:

select [dbo].foo(2)

He would get an error saying insufficient number of arguments where passed in.  Here is what he should have done:

select [dbo].ff(2, DEFAULT)