Windows RSS Platform

Mon, July 31, 2006, 03:47 PM under IE7 RSS
The RSS story varies depending on whether you are a publisher, end user or consumer developer. While almost everyone I ask is an end user (via a browser or a rich client aggregator) and many are producers (most commonly blog authors like myself), very few are developers that programmatically consume RSS today. My bet is that this will change going forward with the advent of the Windows RSS Platform.

The Windows RSS Platform ships with IE7 and hence is available not only with Vista but on WinXP too.

It has several elements:
1. Background Download component
2. Common Feed List
3. Store of feed items
4. Store of enclosures (think attachments, e.g. think podcasts)
5. RSS Object Model (more on the API in a later post)

Applications running on Windows have a choice as to which of these components they want to use - in other words it is not an all or nothing approach. For example IE7 uses the lot while Outlook 2007 optionally uses the Common Feed List (more on O12 later).

I am not going to drill into any of the above since there are mountains of information out there. Below are some links to get you started:

- The BTB033 session at Mix06
(also, if you can get hold of the PDC2005 material, check out the session on 'RSS in Windows Vista' again by Walter vonKoch - that was a clue as to who you should send any feedback that you have)

- A handful of overviews on MSDN

- An older article on MSDN

- RSS platform on the RSS Team blog

Glass in C#, an alternative approach

Sun, July 30, 2006, 03:46 PM under Windows | Vista
My blog post on extending Windows Vista's glass into the client area of managed applications seems to have drawn a lot of attention (and some questions). If you haven't already, please read glass and C# (it assumes you are already familiar with Glass on Vista).

In that approach we looked at 5 steps. There is an alternative approach to extending glass with C# on Vista. The alternative approach has the same 1st and 2nd steps. The step that changes is the 3rd step: explicitly using a black brush to paint the extended area of the form in the form's paint event handler.

Rather than do that, do this:
3. Place a panel on the form's top edge, set the panel's BackColor to color X and then set the form's TransparencyKey to the same color X.

When you run the application, the area occupied by the panel will have the glass effect :-)

Note that just using the BackColor of a panel combined with TransparencyKey of form, results in transparency (also applicable to WinXP). The fact that we do that on Vista in an area that we extended with DwmExtendFrameIntoClientArea, is what gives it the glass effect.

This approach of using panels and transparency was first described (afaik) by Tim Sneath here. If you read the comments on Tim's blog post you'll find a heap of unanswered questions regarding a fundamental problem: At runtime, clicking anywhere on the glass area, actually brings to the front the application behind it. In other words, there is true transparency i.e. inability to click on the glass area while retaining focus in this application.

The solution to the problem actually lies in what color you pick. Above I state that you should pick color X but I have not said what X must be. In Tim's example, he picked Gainsboro. If you look at Gainsboro it has the following values: R=220, G=220, B=220. The problem of the unwanted true transparency stems from the fact that all values are equal. So if you just change for example the R to be 221, then the problem goes away :-) Another gotcha if you create your own color is setting the Alpha of the color to anything but 255 (doing that will not render as glass).

So, now we have two approaches for achieving the same goal (I still prefer the explicit black painting) and you can download a project with the transparencykey approach here. Before I finish off, it is worth pointing out that when a window is maximized, any glass area appears black, which is the reason that most windows rendered fully in glass, do not offer a maximize button (to the dismay of Goths I guess :-p).



While from a practical point of view it all works, some of you will have open questions such as "why black?" and "what makes one color result in true transparency while another doesn't". I'll try to answer those in a future blog entry (if no one else beats me to it).
--
UPDATE: This one does not work post-RC1. See here

Vista: User Account Control

Sat, July 29, 2006, 02:30 PM under Windows | Vista | UAC
You, yes *you*, may not be gearing up to Windows Vista just yet but there is one core security element of Vista that IMO you must understand as soon as possible, and start working for it today on whatever Windows OS you are on. The feature in question is User Account Control. Please follow the links from item 5 here (it allows me a central place for updating resources).

Now that you've read those, I hope you understand UAC. In essence, when you set up user accounts on Vista, even if you set some of them as administrator, all interactive processes will run as standard user! The benefit is that any malicious code that gets on the user's machine also runs as standard user. If your applications require administrator privileges for some features, they will basically break on Vista (oversimplification aimed to scare you, but essentially true if you choose to ignore understanding UAC).

To work with this security feature, you must understand elevation, shields, virtualisation and security configuration options plus what you need to do programmatically for you applications to run on Vista. So, watch my nugget here or download it here to get the full picture...

There is one important bit of UAC that I do not cover in that short video (due to time): manifests. So after you’ve watched the video, come back and continue reading…

Fundamentally, on Vista you should declare that your app is aware of UAC (logo certification requirement). To do that you must embed a manifest in your application. Here are the steps on how to do that for managed applications in Visual Studio 2005 on Windows Vista:

1. Add to your VS2005 C# project this manifest file (replacing MyProjectNamewith your actual project name). Open the file in notepad and replace MyProjectNamewith your actual project name, same for description and Version.
2. Add this rc file to your project (replacing MyProjectName with your actual project name and removing the .txt extension). Open it with notepad and change MyProjectName to your actual project name.
3. Open your project file (csproj) in your favorite XML editor, scroll to the bottom and add/paste the following just before the closing Project element (replacing MyProjectNamewith your actual project name):
<propertygroup>
<win32resource>MyProjectName.res</win32resource>
</propertygroup>
<propertygroup>
<prebuildevent>"C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0\Bin\rc.exe" "$(ProjectDir)$(ProjectName).rc"</prebuildevent>
</propertygroup>

4. Rebuild!

The big clue that this has worked for you, apart from no compilation errors, is that virtualization gets turned off for your app (regardless of the security policy setting, which I show in my nugget). Try writing to HKLM and watch it fail with the manifest and succeed without.

If you change the level attribute of the requestedExecutionLevel element in the manifest from asInvoker to requireAdministrator, then you'll get the elevation prompt at startup (do this only if your app is explicitly aimed at administrators).
--
UPDATE: Also see this

Screencast on TaskDialog, CommandLink, cue banner

Sat, July 29, 2006, 02:20 PM under Windows | Vista
Regular readers will have read my previous blog entries on TaskDialog and TaskDialogIndirect. For the full C++ story on TaskDialog in depth read this.

You will have also read about CommandLink, TextBox cue banner and VistaBridge (that also includes the new CommonFileDialog).

Now you can enjoy all that in a short video I created (especially useful for seeing the above in action for those of you not running Windows Vista yet).

Watch it here (wmv) or download it here (zip).

My nuggets are up

Tue, July 18, 2006, 07:52 AM under Links
…just got word that they are finally available for your viewing pleasure so go check out my nuggets!

1. Under "Filter nuggets by" go to the "Presenter" listbox and select "Daniel Moth".
2. Click the "Search" button.
3. From the list of nuggets select the ones of interest and the "Add to My Downloads".
4. In the top right panel under "My Downloads" you can watch/download the nuggets.

Nuggets are basically short (10'-20') pre-recorded videos that have minimal slides and capture the presenter's screen & voice while they demonstrate some technology feature.

Other sites call nuggets, screencasts (not to be confused with webcasts, which are longer online presentations with a live audience).

see you at MGX and TechReady

Fri, July 14, 2006, 04:31 PM under Events
...if you are a Microsoft employee that is...

MGX is Microsoft's global sales conference and TechReady is the internal technical conference (think TechEd for MSFT personnel only).

I am thrilled to be attending TechReady3 in Seattle and also looking forward to catching up with people in Redmond that I know from my MVP days and others that I have only met virtually since joining here.

I cannot put my hand on heart and say that I am "super-excited" to be going to MGX (and probably won't ever go again) but everybody has to do it once… apparently. Having said that, MGX is in Orlando and I haven't been there before so that's cool. If I am lucky I will do some SCUBA diving and maybe go say hello to mickey mouse (no I am not talking about any current or ex-colleagues :-p).

Not sure if I'll blog or check email that often from the States so wish me a nice holiday business trip.

Flying out in a few hours and will be back in August :-)

Vista: CommandLink Button

Thu, July 13, 2006, 08:57 PM under Windows | Vista
I've been holding back on talking about CommandLink (and other Vista features) becuase I have been waiting for my "productions" to appear on msdn. By productions I mean a few short videos recorded with Camptasia... by the time they have been through bureaucracy cubed though, Vista will probably be on version 3.. LOL.. anyway..

CommandLink is a new style of button in Vista. If you want to see what it looks like, take a trip back to my TaskDialog post.

If you followed the link, you saw those squares with a green arrow and two pieces of text: "instruction" and "text". The "instruction" bit is the normal button text we know and love. The "text" bit is in smaller font and that is where you can add as much detail as you want about the button and its purpose. This is the text that typically today you have to place in a label next to the button or in the button's tooltip. Finally, although in my screenshot you can see the square rectangle around the button, when you hover the mouse away from the button, the rectangle fades away (harder to describe than to see which is why I was waiting for the video to go up before describing these).

Kenny Kerr (C++ guru) demonstrates how to do CommandLinks from native code in his msdn article.

Catherine Heller provided my colleague Eric Nelson here in the UK with some code that lets us use CommandLink from C# code. By bizarre coincidence (or is it outright plagiarism?) I use similar code in my Vista talks :-)

Get the CommandLinkButton code here and remember that this works on Windows Vista only.

TextBox with cue banner support for Windows Mobile

Thu, July 13, 2006, 07:30 PM under MobileAndEmbedded
When talking about TextBox with cue banner I thought I had done a good job at the end of the post of hinting that someone should write a pure managed version; a version that is not restricted to Windows Vista, but rather would work on WindowsCE/WindowsMobile devices (via the .NET Compact Framework of course).

Since nobody stepped up, I thought I'd tackle it myself :-). I have to say that what I thought would be a 10 minute job ended up taking 6 times as long and right about now I give up as what I have is good enough and a nice starter for someone else to take and polish, iron out any issues etc.

So, with no pinvokes and explicitly tested on WM 5.0 and WinXP, here is the TextBoxWithPrompt code file. Simply save this file and add it to one of your projects and then build all. Now open a form and go to the toolbox where you can drag the TextBoxWithPrompt onto your form and change its TextPrompt property to e.g. “Enter your name”



As always feel free to contact me via the link on the left about my blog entries.

my blog subscriptions

Thu, July 13, 2006, 06:23 PM under Links

Recently I trimmed down the number of blogs I subscribe to and will do that again over the next couple of weeks. It came to the point where there were always 3-5 thousand unread items in my aggregator... I could never catch up!

So on my quest to be more selective I faced the dilemma of what I do with group blogs. The same goes for aggregate blogs. (discussion for the difference between the two here)

Current plan is to split the group/aggregated feeds from the direct ones (i.e from the ones where a single person is blogging.. allegedly :-).

Goal will be to keep enough direct subscriptions so that by the end of each week I can say "I've caught up with all of them". Who knows, I might bring back my BLOTW feature (BLOTW 2004 and BLOTW 2005). Will share my OPML when I am done with the trimming...


As for the group and aggregate feeds that I subscribe to (I call them "mass feeds")... they will be in a separate area and will only be scanned occasionally rather than read thoroughly. So, in contrast with the direct feeds, I do want to increase the number of mass feeds I subscribe to. One of the reasons is that a lot of the blogs that I am trimming out are part of some mass feed already so I can keep in touch with those that way :-)

Here is my current list of "mass feeds" (let me know if there are others I should know of) in truly random order:

http://bloggingabout.net/blogs/
http://blogs.conchango.com/
http://codebetter.com/blogs/
http://www.dotnetjunkies.com/WebLog/
http://blogs.geekdojo.net/
http://geekswithblogs.net/
http://msmvps.com/blogs/
http://www.pluralsight.com/blogs/
http://www.developerfusion.co.uk/blogs/
http://blogs.vbcity.com/
http://wdevs.com/
http://weblogs.asp.net/Bloggers.aspx?GroupID=2
http://www.wintellect.com/Weblogs/
http://blogs.msdn.com/

... and my latest addition, the feature-rich:
http://www.dotnetslackers.com/ ("an emergent and popular .NET community")


Webcast follow up

Sun, July 9, 2006, 09:46 AM under MobileAndEmbedded
Thank you all that attended my webcast.

For those that missed it, you can replay it here: .NET Compact Framework for Desktop developers. You get the same experience except slide animations seem to have been taken out and of course you can't interact and ask questions.

Speaking of questions, looks like my content was so clear that I didn’t have to clarify anything :-p. Instead, here are some of the questions that I received.

Q1) I see from one of the last slides that you won't be covering SQL CE/SQL Mobile/SQL Everywhere. Please consider doing so in a future webcast.
A1) Thank you for the suggestion. In the mean time you can find info on SQL Everywhere here and here. Ask questions on this topic here.

Q2) Does Groove offer support for mobile devices yet?
A2) I have absolutely no idea. I would think not and indeed searching seems to bring back no relevant results so I'll stick with "no it is not supported at the moment" guess. If anyone has info to the contrary please enlighten me and I'll update this. Groove home page.

Q3) Are there any particularly cool open source projects for Windows Mobile?
A3) Yes, SDF from OpenNETCF. Source for v1.x is free and for v2.x available at a small fee. Binaries are free regardless of version.

Q4) What's your initial opinion of the new Mobile Client Software Factory? Is it useful for beginners or should novices focus on more meat and potatoes issues?
A4) I think it is a great effort. As everything else, only you know if it is of value for your particular scenario but definitely do check it out.

Q5) Windows Mobile or Tablet PCs?
A5) Mobility development is a wide field from laptops to tabletpcs to UMPCs to PocketPCs to Smartphones to watches! Depending on the job requirements one or more of the previous platforms can be chosen for any particular project. There is no universal answer.
Expect to read more on this blog soon regarding the Vista mobility story

Q6) Mapping for devices?
A6) See this and this. I would expect this to fully support mobile browsers or someone will be missing a trick.

Q7) In some Windows Mobile devices the .Net Compact Framework is in the system ROM in others it has to be downloaded and installed, what is the performance and other impacts of the built in framework vs a downloaded version?
A7) If you are building against a NETCF version that you expect to be in ROM on all your target devices, then there is no issue. If you don't, then you need to deploy the NETCF runtime with your app. In that case, NETCF is installed in RAM and hence using some of it (much like installing any application on your device). The other difference between the NETCF being in RAM or ROM is a tiny perf advantage in the ROM case. This is not something you should be worried about as it will definitely not be your perf bottleneck if you have one.

My Vista System Performance Rating

Sat, July 8, 2006, 02:49 AM under Windows | Vista
I had a couple of people ask me after my Vista sessions
"What are you running it on? It seemed *very* fast!"
Since I haven't installed Beta 2 on my main laptop (Toshiba Tecra M5) yet, for all Windows Vista demos I still use an M3.

Best way to show the spec and what Vista thinks of it is to browse to Control Panel -> System and Maintenance -> Performance Rating and Tools.

Screenshot follows:

--
UPDATE: Also see Windows Experience Index

Beta lifestyle

Fri, July 7, 2006, 11:48 AM under Random
How much pre-release software are you using? Loads right? Whether you love it or hate it, that is the result of increased transparency. Companies are not afraid to share very early what they are working on and have put systems in place to gather feedback from customers (while having an open dialog with users about features and quality). I have no problem with that and I think the breed of user that shies away from software that has the "Beta" label on it will become extinct very soon.

Looking back in the past, it used to be that I would have a separate (older) machine for testing anything Beta, then I moved to Virtual PCs, then I started installing stuff on my main laptop only if I knew it would uninstall cleanly. Now (and maybe this is part of my job, I don't know) I just stick anything that is coming down the pipeline on my laptop and couldn't care less about its stability or removability - I just want to play with it. I want it to always be there without having to switch to another (virtual or not) slower box. My current attitude culminates with the expectation that I will repave the box every couple of months (that is only 6 times a year!).

Since it was released, I've been running Office 12 Beta 2 and using Outlook/Word/PowerPoint 2007 every single day with no serious problems (outlook crashed once and was polite enough to offer me the option of starting in safe mode). IE has become my main browser again with IE 7 (now at Beta 3) after Firefox stole me away from it last year. I still haven't gotten round to putting Windows Vista on this laptop mostly because I inherited another laptop with Vista on it already (Feb CTP that I updated to Beta 2). That's next on my list and I might go for 5456 or Beta 2 or hung on a bit for the next one (so compared to some of you, I know am still behind in this game :-).

Do you find it is a bit like an addiction? I mean, when something finally gets released, I just want the next version already; case in point Live Messenger and ActiveSync 4.2

Note how I haven't even mentioned dev stuff such as NetFx3 or NETCF SP1 (out of Beta now) or any Orcas bits... as a developer, I take it as read that those things will land on my machine

Also note how I don't mention any of the Beta web stuff (i.e. thin client, no local bits) since, technically, that is cheating IMO :-)

using pattern

Mon, July 3, 2006, 04:20 PM under dotNET
Previously we described the using statement. After showing a quick code example and describing the intent of the construct, we proceeded to a more pragmatic description of what it does which I repeat here:
"The using statement accepts as an argument an object that implements IDisposable; it defines a coding block where the ctor of the said object is called at the start and the Dispose method is called in the end."

Taking the definition above, a design pattern is formed (or to be more precise in this case, an idiom):

Sometimes you have a piece of code that has to be enclosed between two code blocks A and B. Code blocks A and B are repeated in multiple places in your project(s). When you recognise that, you can extract a new class with a ctor containing code block A and the Dispose method containing code block B. Replace all client side occurrences with a using block passing in the newly extracted class.

As an example, instead of:
void SomeMethod()
{
Cursor.Current = Cursors.WaitCursor;
statusBar1.Text = "Busy...";
button1.Enabled = false;

// do some real work here

button1.Enabled = true;
statusBar1.Text = "Ready";
Cursor.Current = Cursors.Default;
}
we write:
void SomeMethod()
{
using (BusyTaskRegion bt = new BusyTaskRegion(statusBar1, button1))
{
// do some real work here
}
}
...after extracting the following class:
class BusyTaskRegion : IDisposable
{
private Control _c1;
private Control _c2;

public BusyTaskRegion(Control c1, Control c2)
{
this._c1 = c1;
this._c2 = c2;
Cursor.Current = Cursors.WaitCursor;
c1.Text = "Busy...";
c2.Enabled = false;
}

public void Dispose()
{
this._c1.Enabled = true;
this._c1.Text = "Ready";
Cursor.Current = Cursors.Default;
}
}
Another example would be measuring performance of some code (i.e. extract the timer setup and tear down into a class and then use it via using). I was trying to find the pattern formally documented online but I couldn't. However, I did find examples of its usage here, here and here (much better than my fictitious example above!).

When I first saw this (at a previous project for some impersonation code), it felt wrong on two levels. First, it felt like using was being misused in scenarios that it wasn't originally intended for (e.g. when people read the client side code they have to take an extra mental step to digest that no memory management stuff takes place). Second, it felt wrong to define classes that have just a constructor and a Dispose method with nothing else in-between.

What do you think?

using statement

Mon, July 3, 2006, 06:35 AM under dotNET
The using statement has been in C# for ever and was newly added to VB8 as well (Using). I hope everybody is familiar with it by now (not to be confused with the using directive typically appearing at the top of code files - Imports in VB). If I asked you to tell me about the using statement, I bet that most of you would use a code example , maybe something like the following.

Given a class like this:
class SomeType : IDisposable{
public SomeType(){
// do some ctor stuff
}

public void DoSomething(){
// do some useful stuff
}

public void Dispose(){
// clean up unmanaged resources
}
}
We know that the client code should use it like this:
SomeType st = new SomeType();
try
{
st.DoSomething();
}
finally
{
st.Dispose();
}
The using statement makes that cleaner, easier to remember and easier to enforce like this:
using (SomeType st = new SomeType())
{
st.DoSomething();
}
So, the easy way to describe the purpose of using (without a code example) is this:
The using statement offers an elegant way of ensuring that the developer does not forget to call Dispose on an object that (directly or indirectly) holds unmanaged resources. (My links to msdn at the top pretty much say the same thing)

Effectively, we all associate the using statement (or at least I always did) with not leaking. However, if we look at the using statement not from an intent point of view but instead from a practical point of view, we would probably come up with this:
The using statement accepts as an argument an object that implements IDisposable; it defines a coding block where the ctor of the said object is called at the start and the Dispose method is called in the end.

Next, we'll see how to take that last statement further to describe a design pattern.

Happy 20th to me :-)

Sun, July 2, 2006, 03:03 AM under Personal
Today, 2nd July is my birthday! I am glad they moved Tech Ed Europe to November this year, as I am sick of spending my birthday at a conference!

Oh and, yes, I am just 20 years old... if I count in hex that is ;-)