Tech Ed session 3

Thu, November 2, 2006, 05:45 AM under Events
In exactly one week, I invite you to attend one of my 4 sessions at Tech Ed Europe in Barcelona.

When/where:
Thu, Nov 9, 13:30 - 14:45, Room 133

Title:
DEVWD21 Selecting the best Windows Mobile Technology for your Solution

Abstract:
Come to this highly interactive session to get your questions answered and hear about where Windows Mobile is going. A panel formed from the pool of talented speakers will, for this session only, be available to you all at once. This session is focused on the Windows Mobile developer so ask about tools, technologies, and even device futures to help you plan your development strategy to maximize Windows Mobile in your business.

Tech Ed session 2

Wed, November 1, 2006, 05:43 AM under Events
In exactly one week, I invite you to attend one of my 4 sessions at Tech Ed Europe in Barcelona.

When/where:
Wed, Nov 8, 13:30 - 14:45, Room 125

Title:
DEV226 Realizing the Potential of the Windows Mobile 5.0 Managed Application Programming Interfaces (APIs)

Abstract:
Successful mobile applications are designed for mobile users. We will take a comprehensive look at the managed APIs in Windows Mobile for richly interacting with core device features such as Outlook Mobile and learn how to create smart applications with the State and Notification broker. Come see how developer tasks previously requiring lengthy C++ are now achieved with two lines of managed code! Through Visual Studio 2005, we will demonstrate using the camera to capture pictures and video, the interception and processing of SMS messages, placing phone calls, dealing with system level events, programmatically sending e-mail and SMS messages to name just a few!

(If you are a desktop developer, this is a great follow up session to DEV329.)

Tech Ed session 1

Tue, October 31, 2006, 08:38 AM under Events
In exactly one week, I invite you to attend one of my 4 sessions at Tech Ed Europe in Barcelona.

When/where:
Tue, Nov 7, 16:00 - 17:15, Room 125

Title:
DEV329 .NET Compact Framework (NETCF) for Desktop Developers

Abstract:
There are many C# and VB developers that have never used NETCF. In this session, we introduce NETCF v2.0, highlighting differences from the previous version. This talk explores the development platform differences between the Windows desktop environment and Windows Mobile-based devices such as the Pocket PC and smartphone. We also examine the options for sharing .NET assets between platforms, and demo suggestions for making the best development decisions. By the end of the show you will be inspired to write your first NETCF application that leverages existing code. Attendees require no previous knowledge of mobility devices or NETCF - simply an understanding of .NET on the desktop.

WCF for devices

Tue, October 31, 2006, 06:06 AM under MobileAndEmbedded
When we talk about the NetFx3 technologies, there are always one or two attendees (not the same ones each time!) that ask if any of the technologies are applicable to mobile devices. There are no plans for WF and no immediate plans for WPF (often confused with WPF/e which is actually quite a different technology with an unfortunate name IMO).

However, the WCF story is good with Orcas and it is now public information! Read all about the WCF support on Roman's blog post. Below some choice quotes:
"... The WCF programming model support will be limited to channel layer messaging (no service model support on the device) [...]
[...] We'll expose all necessary extensibility points so people could plug in their own transport and layered channels, while maintaining a unified programming model. [...] The channels we plan to deliver out of the box are Http and... yes, e-mail (for WCF on desktop and device)."

Go read the full story!

Out of Continent

Sun, October 15, 2006, 12:45 AM under Personal
Well, the time has come for another vacation (and our 2nd honeymoon in fact, since it is still within the period that the travel agents accept it as such!). We are taking our first ever trip to Egypt to visit the pyramids in Cairo, cruise down the Nile (Luxor, Aswan etc), visit Abu Simbel and dive the Red Sea...

I’ve been looking forward to this break, given the workload of September/October (you can work out from my blog how many events I have done!). Plus, when I return I am off to Tech Ed Europe and, boy, will that be tiring (more on my Tech Ed sessions soon)...

I will be back from our holiday on 1st November so until that Wednesday... other than my nuggets... let there be silence on this domain :-D

PS For any work related queries, try one of my colleagues.

VB6 does glass on Vista

Sat, October 14, 2006, 07:00 PM under Windows | Vista
The other day at one my talks somebody asked me if the new Vista native APIs I show callable from managed code are also callable from VB6. I hadn't thought about that before, but in principle, yes, they should be. He was specifically interested in glass (glass, as in what I talked about here, here, here, here, here and here.).

Unsurprisingly, it took me longer to download the VB6 iso, to install it on my laptop and to remember how to work with that IDE, than what it did to get glass in VB6. A form, a module and a total of 11 lines of code later and the following screenshot shows the project running (or if you prefer without transparency):


Note that just like with Windows Forms (but unlike WPF), actually making controls look good on the glass surface is not trivial (unless you enjoy painting everything yourself!). You get a glimpse of the challenge here and a full blown project here.

Vista: Restart Manager

Sat, October 14, 2006, 03:45 AM under Windows | Vista
Intro
It is amazing how as end users we all take for granted that before we install something we need to save our application state, manually close everything, install the new thing, manually restart every app we were using (if we remember what they were) and try to get to the state we were before! How many times have you installed an application (or completed a Windows Update or some other patch) and then had to restart your machine? How irritating is that?

Restart Manager promises to make that experience a thing of the past. Personally, I'd like to live with Vista for a bit longer before I subscribe to that promise but I have to admit initial experiences are promising!

So what does Restart Manager (RM) do?

Fundamentally, when a RM-aware piece of software installs, it will ask all RM-aware applications to shutdown, assuming the said applications are holding resources (e.g. files) that it needs to update. The RM-aware app, will listen to the request and shutdown, saving its state! When the installation has completed, it will then restart all the RM-aware applications. The RM-aware application will then restore its state and the user has a nice experience. The classic example is that you have left Word open with a document you are working on and gone home. Overnight a patch is available and windows update does its job. So it closes down Word, install whatever, then restarts Word so when you arrive in the morning, you can't even tell what happened because Word is waiting for you where you left it with the document you were last working on :)

If the update involves a critical system component so a windows reboot is unavoidable, a reboot will take place but after reboot the RM-aware applications will also restart!

Now that Vista offers this technology, reaching this seemingly imaginary world is down to us, application developers. And since you are reading this blog... managed developers! So what is it we need to do?

Developer actions
Well, reading the above should have given you a clue :)
1. We need to make our installations follow the RM philosophy and
2. we need to make our applications at runtime also play ball

To achieve the first action we can simply use (directly or indirectly via commercial package) Windows Installer v4 and you are pretty much done!! If you have chosen an alternative deployment technology then ditch it and switch! No I am only joking, if you do wish to use something else, then you must manually work with the API which resides in rstrtmgr.dll. A typical series of calls is to create a session (RmStartSession), then register the resources we created (RmRegisterResources), then shutdown the resources/processes (RmShutdown), later on restart them (RmRestart) and finally end the session (RmEndSession). I may post a full C# sample in a future blog entry.

To achieve the second developer action for your application, you need to do a further two things:
a) Register with the system for restart, and be capable of restoring your state when (re)starting up
b) Listen for the message from an installation program that you are about to shutdown (good opportunity to save state etc)

The first of these actions is identical to what we talked about before for unexpected crashes/hangs. Now you see that there is a dual benefit to calling RegisterApplicationRestart as I’ve already mentioned in this article.

The difference with that scenario is that in this case your application doesn't crash, instead it is being asked nicely to shutdown. To listen to that request you need to hook into your window's message loop and listen for a specific message as per the example below:
    protected override void WndProc(ref Message m)
{
base.WndProc(ref m);

if (m.Msg == WM_QUERYENDSESSION) //0x0011
{
if ((m.LParam.ToInt32() & ENDSESSION_CLOSEAPP) == ENDSESSION_CLOSEAPP) //0x1
{
// some installation will shut us down next, so do some cleanup (prepare for it)
File.WriteAllText(Environment.CurrentDirectory + @"\rm.txt", "for demo purposes");
//MessageBox.Show("intercepted", “RM request”);
}
}
}
Other links
If you want to find out more about Windows Installer 4.0 working with Restart Manager then there is this video on channel9 (watch the first 3’ and then watch another 4’ starting at 15’).

There is public/external mention of Restart Manager over at eWeek.

For the developer types, lookout for a nugget coming real soon!

Vista: Sample Sidebar Gadget

Thu, October 12, 2006, 09:33 AM under Windows | Vista
While most people think they know all there is to know about Sidebar and Sidebar gadgets, I strongly recommend you read my blog entry that details the feature: Sidebar Gadgets. The best way of course is to actually try out all the system gadgets that give you a glimpse of what is possible. Only then you'll have acquired an appetite to go build your own!

First step to creating our own gadget is to know what a gadget looks like on the file system. Easy one that... it is just a folder! A folder with a .gadget extension placed in one of two places: the system folder or the user folder (more on both follows).

1. Navigate to the following path on your machine (copy it and paste it on your explorer window): "%userprofile%\appdata\local\microsoft\windows sidebar\gadgets".
2. Create a folder named "moth.gadget".
3. In that folder, place this gadget.xml file.
4. Drop in the same folder this daniel.html file (right click and save it, don't worry about what is inside it for now).

Go to the gadget picker and you see your gadget (“Moth Gadget”)! So all we have to do to get our gadget in the gadget picker is use a manifest which is always named gadget.xml. Now go ahead and open the XML file in your favourite editor (~20 lines) and check out the element names. It should be obvious what each one describes (name, version, author, description, icon etc) and also obvious what you need to change for your own gadgets. Spot the correlation of values between the XML file and the text that appears in the gadget picker. Looking at the gadget.xml contents, notice under the base element (under the host element, under the hosts element) the attribute "src"? That points to where the actual content of your gadget is in terms of how it renders itself when added to the Sidebar (and that is why we added the html file).

5. Drop in the same folder an image with a name of “daniel.PNG” (I have one here if you are desperate for images). Now in the gadget picker we can also see our own icon for the gadget (rather than the default).

6. Now add the gadget to your Sidebar. If everything went to plan, you can see on a plain white background some text. This text is the machine name of the computer you are running on.

Open the html file in your favourite editor and observe its contents (~25 lines). It has 3 sections: script (the guts of all Sidebar gadgets is script), head (for styling) and body (for context). It should be fairly obvious to web developers what it does: In the script section we setup the 'machName' span to the return value of a gadget API (System.Environment.machineName). In the body we simply render the machName. "Not running in Sidebar!" is what you see if you open the html file outside of Sidebar of course.

So to summarise, gadgets are basically DHTML. A combination of html+script+css+images and you've got it (preferably PNG files so you can play with some transparency). Of course, you should also take advantage of the Sidebar gadget API to create powerful gadgets.

Questions that usually pop up at this stage:
Q1. (tone of disbelief) How powerful can I possibly make a gadget when I am only using DHTML?
A1. Very :) Just check out the gadgets that ship out of the box. You can view all of that code for inspiration by browsing to "C:\Program Files\Windows Sidebar\Gadgets" <-- this is also my top tip :)

Q2. Where can I find more about the Gadget API?
A2. On msdn of course. The gadget API page appears empty, but you can navigate to the topics below it from the treeview on the left.

Q3. Is there a tutorial more comprehensive that what you just showed?
A3. My sample above demonstrates how easy it is with essentially two files to hook into the gadget plumbing. The best samples are the ones on your Vista machine as per Q1 above. However, you can find two additional more comprehensive walkthroughs: One on msdn and one on technet. Enjoy!

Q4. No offense to web people and script fans, but can I not write these in binary code?
A4. Of course you can use ActiveX. You may lose the simplicity of deployments but you gain all the richness of ActiveX technology. Follow the link for more on gadgets with activex.

Q5. How about .NET code and in particular WPF?
A5. While originally this was the plan, regrettably the feature had to be cut (and will hopefully re-appear in a future version). There are a few samples of using WPF with gadgets but they are more a proof of concept rather than an attractive (or a supported) scenario. One such example (via an XBAP) is here.

Q6. Any other gadget resources?
A6. If you consume the links above (and from my previous post on Sidebar), as a side effect you'll discover other resources :) There is an example of using Atlas to call web services (very popular scenario) from gadgets here.

My nugget on the subject should be out next week

Vista: Sidebar gadgets

Wed, October 11, 2006, 11:20 PM under Windows | Vista
After talking about gadgets in general, let's focus on Sidebar gadgets specifically.

Sidebar gadgets are hosted, managed, installed, picked in Sidebar. Sidebar without gadgets is useless and gadgets without Sidebar are non-existent. Sidebar contains gadgets (gadgets can also be dragged onto the desktop area). Multiple instances of the same gadget can appear on the Sidebar.

Sidebar is a Vista feature and it is basically a pane on the side of the screen (whichever side you want on whatever monitor you want). It is an executable (sidebar.exe) and also has a systray icon. You can "close" the Sidebar in which case it is still running and is minimized to the systray or you can "Exit" the Sidebar in which case it is gone for real (along with any gadgets you dragged onto the desktop).

Sidebar can be configured to be always on top (or not) and the same is true of any gadgets that were dragged onto the desktop area. All gadgets have a thumb for moving them around and a close button for removing them from the Sidebar. Some of them also have a config button (little spanner icon). Furthermore, those gadgets can have their opacity tuned. Right click on the gadget and you get this menu:


Clicking on the Sidebar systray icon will bring to the front the Sidebar (if that was behind a window) and also any gadgets on the desktop (if they were behind a window). Right clicking on the icon will show a menu and right clicking on the Sidebar itself will also produce a menu. Both of these menus are in the following screenshot:



Clicking on "Properties" produces the following dialog.


The last thing to know about Sidebar is that there is a gadget picker that previously looked like this and now looks as follows (access it from the top of the Sidebar "+"):


You can add a gadget to the Sidebar from the gadget picker by double clicking, right clicking and selecting "Add" or finally by simply dragging and dropping. To remove the gadget from your system, right click on it in the gadget picker and select "Uninstall".

As the screenshot above shows there are 11 gadgets shipping out of the box.
- Calendar (Browse the days of the calendar)
- Clock (Watch the clock in your own time zone or any city in the world)
- Contacts (See a list of Windows contacts, search for a contact, or select a contact to see e-mail address and phone numbers)
- CPU meter (See the current CPU and RAM)
- Currency (Convert from one currency to another)
- Feed Headlines (Track the latest news, sports, and entertainment headlines)
- Notes (Capture ideas, notes, and reminders in a quick and easy way)
- Picture Puzzle (Move the pieces of the puzzle and try to put them in order)
- Slide Show (Show a continuous slide show of your pictures)
- Stocks (Monitor your favourite stocks)
- Weather (See what the weather looks like around the world)

These are the system gadgets and the user can install additional gadgets. I encourage you to familiarise yourself with these OOB gadgets as collectively they show some of the cool thing gadgets can do.

Before we close the description of this feature, it is important to understand that the security aspects have been thoroughly thought of and you can read about some of them here.

Next we look at the developer story with a sample Sidebar gadget :-)

Gadgets, gadgets, gadgets

Wed, October 11, 2006, 03:54 PM under Windows | Vista
If you didn't know about it, then yes it is true. Our marketeers have managed to name 3 slightly different things with the same name. I can sort of see where they are coming from, since in all 3 cases we are talking about task specifics mini-applets that are not quite full blown applications but are also not web pages so “gadgets” seemed appropriate for each category.

I am talking of course about (note the spelling/casing!)
* live gadgets (web)
* SideShow gadgets (Vista)
* Sidebar gadgets (Vista)

The compatibility between these is not there *yet*. Each has its own API that the other two hosts will not understand. SideShow gadgets are probably more removed from the other two. Live gadgets can be made under certain circumstances to run in Sidebar (via an iframe) but the vice versa story is not as good. I am being vague on the compatibility as I know it will get better in the future and the current story is ever changing. But here I am talking about (in)compatibility when I haven’t introduced each one of them!

* Being a client guy myself, I will not ever mention live gadgets here again (famous last words). To find out more about them visit these pages: 1 , 2 , 3 , 4.

* SideShow is a platform that attracts me hugely but I will refrain from talking about those gadgets until after Tech Ed Europe, in November (I am hoping to own hardware then and, if not, I'll just have to use the emulator - either way, stay tuned!).

* This leaves us with Sidebar gadgets... but that is the subject of my next post :-p