Follow Up: Toronto VB Users Group Presentation #
Thursday, March 16, 2006 12:30:05 PM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

IE7 and VS2005#

I was working on a sample application to demostrate Compact Framework 2.0 new COM Interop feature which was going to be a managed application calling a COM component.  I needed to create the COM component but when I tried to create any Smart Device C++ project I would get a "project creation failed error" and the following script error

I had no idea what this error was and I knew it worked before and this was the first time I tried to create a C++ project after I installed IE7 so that must have been the culprit. 

Not wanting to uninstall IE7 because I have gotten used to it and like it, I did a little research and thanks to Amit Chopra there is a workaround for this.

<NOTE>This involves modifying the registry so do at you own risk.</NOTE>

  1. Close VS
  2. Start RegEdit.exe
  3. Find the following registry entry:
    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Ext\PreApproved
  4. Add a new entry and name it
    {D245F352-3F45-4516-B1E6-04608DA126CC} 
  5. Close RegEdit
  6. Start VS
  7. Try and create a Smart Device C++ project

Once you complete the above you will be able to see the wizard popup.   But when you are asked to selected an SDK you will notice there is nothing in the list.  There are items available you will just not see it.  Just click on the ListBox and navigate using your keyboard, you will notice the groupbox below the listbox changes.


Thursday, March 16, 2006 12:00:14 PM (Eastern Daylight Time, UTC-04:00) #    Comments [5]  |  Trackback

 

Developing .Net CF for XBOX 360#

Well, not yet but it sounds like it's coming!  Head over to Mike Zintel's blog and read this post.  Does this mean that they will be coming out with a PSP competitor, maybe XBOX Mobile?  Also, check out Jason Zander's post about internal teams working together which includes Mike's team. Sounds exciting and can't wait to see what's coming!  Now there is a legitimate reason to expense and XBOX 360 as R&D :)


Tuesday, March 14, 2006 10:48:48 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Presenting at Toronto VB User Group (March 15)#

I'll be doing a presentation on .NET Compact Framework for Desktop Developers at the Toronto Visual Basic User Group (TVBug) this Wednesday (March 15 2006).  If you're in the Toronto area and instrested in .NET CF development come out to this session.

Here is the abstract:

Are you a desktop developers looking to extend an application to a mobile device? Have you already written an application for a mobile device and want to extend your knowledge on what else is available? Whether you have never written a mobile application using .NET Compact Framework or have already used the .NET Compact Framework, this session will give you an overview of what devices you can develop for, what's new in .NETCF 2.0, tips and tricks for mobile development and what are the major differences from the .NET Compact Framework and the full .NET Framework.

Thanks to Daniel Moth for letting me borrow the presentation title :)


Tuesday, March 14, 2006 2:11:29 AM (Eastern Daylight Time, UTC-04:00) #    Comments [0]  |  Trackback

 

Extending OpenNETCF.Windows.Forms.Button2 class#

The OpenNETCF Smart Device Framework 2.0 is currently in Beta1 and is currently released in binary form only during the beta cycle.  Even though it's currently available only in compiled mode you can still extend the functionality of controls.  For example, I'm working on a project where I'm using the OpenNETCF.Windows.Forms.Button2 and the Image property for the button.  There are a bunch of buttons that get enabled/disbled but unfortunately when the button is disabled it still looks disabled because of the image.

To resolve the problem we can inherit from the Button2 class.  We can create a class ExtendedButton (not the name I used in the project but used it for explanation purposes).  Here is the class implementation: 

/// <summary>
/// Provides the ability for enabled and disabled images
/// </summary>
public partial class ExtendedButton : Button2
{
   private Image disabledImage = null;
   private Image enabledImage = null;

   public ExtendedButton()
   {
      InitializeComponent();
   }

   /// <summary>
   /// Gets or sets the disabled Image
   /// </summary>
   public Image DisabledImage
   {
      get
      {
         return this.disabledImage;
      }
      set
      {
         this.disabledImage = value;
      }
   }

   /// <summary>
   /// Gets or sets the image. Hides the base class implementation but 
   /// internally still calls the base implementation
   /// </summary>
   public new Image Image
   {
      get
      {
         return base.Image;
      }
      set
      {
         this.enabledImage = value;
         base.Image = this.enabledImage;
      }
   }

   /// <summary>
   /// Hides the System.Windows.Forms.Control.Enabled property. This is
   /// where we set the Button2.Image property depending on the enabled
   /// status.
   /// </summary>
   public new bool Enabled
   {
      get
      {
         return base.Enabled;
      }
      set   
      {
         base.Enabled = value;
         if (base.Enabled)
            base.Image = this.enabledImage;
         else
         {
            if(this.disabledImage!=null)
            base.Image = this.disabledImage;
         }
         this.Invalidate();
      }
   }

 

Here is a screen shot of the sample application:

Sample application is also attached. 

Purpose of doing this is to show that you can extend controls without having the source available to you. This functionality wasn't added to the SDF class because we are in somewhat of a code freeze for new features, but if there are enough request we can added it after the SDF2.0 release.

ExtendedButton.zip (15.35 KB)
Friday, March 10, 2006 4:00:59 PM (Eastern Standard Time, UTC-05:00) #    Comments [0]  |  Trackback

 

Operator Overloading#

NOTE: This is primarly a .NET Fx Post

In a previous project I wrote a server process to do various calculations on available data.  I was given the task to see how many calculations are done per/second.  Having never done a task like this on the desktop I decided to calculate this manually using QueryPerformanceCounter, similar to something I did previously using .NET Compact Framework.  This worked and logged to a text file but it wasn't graphical,  and from my experience non-techies like seeing graphical images. 

Since it was a server process I decided to take advantage of the System Monitor and the System.Diagnostics.PerformanceCounterCategory and System.Diagnostics.PerformanceCountrer.  Since I just had to calculate the number of calculations per/second this was farily straight forward.

You setup your PerformanceCounterCategory then setup a PerformanceCounter and call Increment(). Not a big deal just a few lines of code. 

The point of the post, Operator Overloading.  During this project someone asked me how to do operator overloading in C#.  I pointed him to the MSDN documentation but actually doing something via code is better than just reading something.  The following class was created from that exercise.

/// <summary>
/// Adds overloaded operator to increment a persecond monitor
/// </summary>
public class PerformanceCounter2
{
   private PerformanceCounter perfCounter;

   public PerformanceCounter2(string categoryName, string counterName, string instanceName, bool readOnly, bool reset)
   {
      this.perfCounter = new PerformanceCounter(categoryName, counterName, instanceName, readOnly);
      if (reset)
      {
         this.perfCounter.RawValue = 0;
      }
   }
   public static PerformanceCounter2 operator +(PerformanceCounter2 perfCounter, long incrementBy)
   {
      lock (perfCounter)
      {
         perfCounter.perfCounter.IncrementBy(incrementBy);
      }
      return perfCounter;
   }
   public static PerformanceCounter2 operator ++(PerformanceCounter2 perfCounter)
   {
      lock (perfCounter)
      {
         perfCounter.perfCounter.Increment();
      }
      return perfCounter;
   }
}

Now instead of creating a PerformanceCounter you create the new PerformanceCounter2 object from the above class.  When you want to increment your performance counter, instead of calling

perfCounter.Increment();

you would call

perfCounter++;

The above class was created from an exercise to teach someone operator overloading.  It was used in production but I don't think added any real benefit.  The sample application included puts this class to use and the image below is a screen shot from using the sample application. 

PerfCounter.zip (12.56 KB)


Wednesday, March 08, 2006 4:54:41 PM (Eastern Standard Time, UTC-05:00) #    Comments [0]  |  Trackback

 

Toronto WiFi#

Looks like Toronto will be getting a free public WiFi network by years end.  The company putting it together will be Toronto Hydro Telecom, which is a spin off from Toronto Hydro.  The Canadian wireless carries Rogers, Bell Mobility and Telus Mobility I'm sure are not too happy about it especially since Bell and Telus have their EV-DO networks available and Rogers will soon be coming out with their UMTS network.  I think it's great that there will be this free public network.  The only catch is it will only be free for six months after it's set up, after that they will start charging.  Oh well can't get everything for free and living 1hr away from Toronto it's of no use to me :(


Wednesday, March 08, 2006 2:19:59 PM (Eastern Standard Time, UTC-05:00) #    Comments [0]  |  Trackback

 

Drawing Rotated Text in .NET Compact Framework 2.0#

Back in February of last year I posted a sample on drawing rotated text using .NET Compact Framework 1.0 and OpenNETCF Smart Device Framework 1.4.  Since then, Compact Framework 2.0 has been released and Smart Device Framework 2.0 Beta1 has also been released.  Changes in the OpenNETCF.Drawing namespace caused the existing sample to not work anymore simply because the functionality in the SDF2.0 was removed.  Why was it it removed?  With CF2.0 there is a new class within the Microsoft.WindowsCE.Forms namespace called LogFont which replaces the SDF1.4 OpenNETCF.Drawing.FontEx class. 

Some of the more trickier parts of the code are setting the proper angle.  With the OpenNETCF.Drawing.FontEx class setting the font angle was as easy as setting the Angle property.  With the LogFont class, there was no Angle property, but from reading the MSDN documentation on the class points us to the Escapement property.  To set the font at an angle of 90 degrees, you will have to set the Escapement property to 900 or (90 * 10).  The other thing to note is the FaceName property has to be a null terminated string so you have to end it withe a '/0'.  Below are some other properties to add more functionality to the  LogFont:

Here is an implementation of drawing rotated/angled text using the above information.  For a complete sample see the sample application. 

private void DrawTextSample()
{
   //For VGA support get the scale to adjust dynamically
   int scale = (int)this.Scale(this.offGfx);

   //Get the size of the current font
   SizeF size = this.offGfx.MeasureString(this.txtDraw.Text, this.Font);

   //Create a new logfont class
   Microsoft.WindowsCE.Forms.LogFont lf = new Microsoft.WindowsCE.Forms.LogFont();

   //Escapement defines the angle at which you want the text to draw
   lf.Escapement = Convert.ToInt32(this.numericUpDown1.Value)*10;
   
   //Set the wieght of the font
   lf.Weight = this.Weight;
   
   //Set the quality to draw the font
   lf.Quality = this.Quality;
   
   //Set the name of the font. Note the null termintion char
   lf.FaceName = this.Font.Name + "/0";
   
   //Set the font height. Note that we mulitply by scale to adjust for VGA devices
   lf.Height = (int)size.Height * scale;
   
   //Specifies the font family
   lf.PitchAndFamily = Microsoft.WindowsCE.Forms.LogFontPitchAndFamily.Default;
   
   //Specify if it is strikeout
   lf.StrikeOut = Convert.ToByte(this.chkStrikeout.Checked);
   
   //Specify if underlined
   lf.Underline = Convert.ToByte(this.chkUnderline.Checked);
   
   //Create a font that is compatible with the graphics object
   Font font = Font.FromLogFont(lf);
   
   //Fill the background
   using(SolidBrush b = new SolidBrush(this.BackColor))
      this.offGfx.FillRectangle(b, new Rectangle(0,0,this.Width,this.Height));
   
   //Get the middle of the screen
   Point point = new Point(Screen.PrimaryScreen.WorkingArea.Width / 2,
                           this.chkStrikeout.Top / 2 );
   
   //String format is a new class for CF2.0. Here we need to specify to not wrap the text
   //and to not clip the text if it is outside the bounds
   StringFormat sf = new StringFormat(StringFormatFlags.NoWrap | StringFormatFlags.NoClip);
   
   //Draw the text
   using (SolidBrush brush = new SolidBrush(Color.Red))
      this.offGfx.DrawString(this.txtDraw.Text, font, brush, point.X, point.Y, sf);
   
   //Force the screen to repaint
   this.Invalidate();
}

It's a little more work drawing rotated/angled text using CF2.0 but the end result is the same as previous.

RotatedText1.zip (14.21 KB)
Wednesday, March 08, 2006 11:06:00 AM (Eastern Standard Time, UTC-05:00) #    Comments [1]  |  Trackback

 

All content © 2012, Mark Arteaga
Related Sites
Archives
Sitemap
Disclaimer

Powered by: newtelligence dasBlog 1.9.7174.0

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

Send mail to the author(s) E-mail

Theme design by Jelle Druyts