November 4, 2004 spout

The Importance of Reputation

My youngest son was called into the office today for pantsing a kid on the school playground. That is not at all like my son (he’s the sweetest kid you’d ever want to meet), but the principal was new, so she was talking about suspension. Luckily, the secretaries knew my boy, so they were able to point out the inconsistency of that behavior with the reputation he had built in 4 years at the school. It turns out that the pantsed boy was cutting in line in front of my son, who didn’t like it, so pushed him right back out of line again. The cutter” took a swing, my boy swung back and in the process (they’re only 9) they both fell. My son reached out to grab the boy’s shirt to catch himself, not knowing that the other boy was also falling and got the pants instead, causing the aforementioned pantsing.”

The moral of this story is an old saying I heard when I was a kid and have lived by since: If you rise at dawn, you can sleep til noon.” In other words, if you build yourself a reputation for good things, when occasionally you stray, folks will cut you some slack. The converse of this rule is that if build yourself a reputation for bad things, that could well stick with you for a long, long time…

November 4, 2004 spout

It’s The Thoughts That Count…

On an internal mailing list the other day, there was a question asking for how to make a tray notification icon come back up on the try after explorer.exe died and came back to life. Good notification icons do this and the asker wanted to know how to do it for Windows Forms. I had had a dearth of technical work at the time, so decided to dig into the problem and see if I could answer it.

I started with a dim memory of a piece in MSJ by Paul Dilascia on the subject. Searching on msdn.com, I found Paul DiLascia’s 2/99 MSJ C++ Q&A (http://www.microsoft.com/msj/0299/c/c0299.aspx) (emphasis added by me):

provided you have Windows 98 or the Microsoft Internet Explorer 4.0 desktop installed. Whenever Internet Explorer 4.0 starts the taskbar, it broadcasts a registered message TaskbarCreated to all top-level parent windows. This is your cue to recreate the icons. If you’re using MFC, all you have to do is define a global variable to hold the registered message and implement an ON_REGISTERED_MESSAGE handler for it.”

From there, I dug through the SDK docs on ON_REGISTERED_MESSAGE (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vcmfc98/html/_mfc_on_registered_message.asp) and found:

// example for ON_REGISTERED_MESSAGE
const UINT wm_Find = RegisterWindowMessage( FINDMSGSTRING )

BEGIN_MESSAGE_MAP( CMyWnd, CMyParentWndClass )
//AFX_MSG_MAP
END_MESSAGE_MAP( )

Figuring I’d have to be able to call RegisterWindowsMessage from managed code, I surfed to pinvoke.net and found RegisterWindowMessage (http://pinvoke.net/default.aspx/user32.RegisterWindowMessage):

[DllImport(“user32.dll”, SetLastError=true, CharSet=CharSet.Auto)]
static extern uint RegisterWindowMessage(string lpString);

Now that I knew how to figure out the Window message value for which to watch, I looked back into the MSDN documentation on System.Windows.Forms.Control, the base class of Form and all other HWND-based classes in Windows Forms (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemwindowsformscontrolclasswndproctopic.asp) and the WndProc method I would have to override to catch the message, finding:

protected virtual void WndProc(
ref Message m
);

and:

All messages are sent to the WndProc method after getting filtered through the PreProcessMessage method.

The WndProc method corresponds exactly to the Windows WindowProc function. For more information about processing Windows messages, see the WindowProc function documentation in the Windows Platform SDK reference located in the MSDN Library.

Notes to Inheritors: Inheriting controls should call the base class’s WndProc method to process any messages that they do not handle.”

Putting this together, I figured you could add re-awakening” to notification icons in the following way (some compiler errors left in to keep readers on their toes : ):

using System.Windows.Forms;
using System.Runtime.InteropServices;

class MyMainForm : Form {
  [DllImport(“user32.dll”, SetLastError=true, CharSet=CharSet.Auto)]
  static extern uint RegisterWindowMessage(string lpString);

  static uint taskbarCreatedMessage = RegisterWindowMessage(“TaskbarCreated”);

  protected override void WndProc(ref Message m) {
    if( (uint)m.Msg == taskbarCreatedMessage ) {
      // re-show your notify icon
    }
    base.WndProc(ref m);
  }
 
}

After posting this answer to the list, I couldn’t help but crank up a quick app to test it (after fixing the compiler errors of course : ). To my satisfaction, it worked immediately. I put up a notify icon in Windows Forms, killed explorer.exe and was pleased to see my icon show back up again when explorer.exe was restarted.

However, just to make sure, I commented out my code to see my icon not be restored. Those of you familiar with the internals of Windows Forms know what happened next, of course, because my notify icon was restored properly to the tray even without my code, as illustrated by Reflector against the .NET 1.1 Windows Forms implementation:

public sealed class NotifyIcon : Component {
  …
  static NotifyIcon() {
     NotifyIcon.WM_TASKBARCREATED =
      SafeNativeMethods.RegisterWindowMessage(“TaskbarCreated”);
  }

  private void WmTaskbarCreated(ref Message m) {
    this.added = false;
    this.UpdateIcon(this.visible);
  }

  private void WndProc(ref Message msg) {
    …
    if (msg.Msg == NotifyIcon.WM_TASKBARCREATED) {
      this.WmTaskbarCreated(ref msg);
    }
    …
  }
  …
  private static int WM_TASKBARCREATED;
  …
}

What? Why would someone post a question about how to make something work that already worked? I figured that the questioner was referring to .NET 1.0 and I was digging through .NET 1.1 code.

However, reading through the 1.0 code showed the same support, meaning that neither the questioner nor I had bothered to check for this support before running off to add it. So, the lesson? Write your tests first!

Still, I learned a bit along the way and that was fun. : )

November 2, 2004 fun

There Are No Words…

Here.

This is what Don Box’s 12-year old son thought a good last minute costume would be when trick-or-treating the Indigo halls of Microsoft suddenly seemed an imperative. I guess this is the consequence of having a life-sized cardboard cutout readily available…

November 2, 2004 fun

There Are No Words…

There Are No 
Words…

This is what Don Box’s 12-year old son thought a good last minute costume would be when trick-or-treating the Indigo halls of Microsoft suddenly seemed an imperative. I guess this is the consequence of having a life-sized cardboard cutout readily available…

Don Box
Personal Email
Tue 11/2/2004 6:12 PM

November 1, 2004 tools

MaxiVista: Changing My Mind About Tablets

When I first read about MaxiVista, the thing that really got me interested was that it gave me two things that I really want from my Tablet PC. The 1st is to be able to use a slate-only Tablet as a 2nd monitor for my laptop so that I can continue my addiction to keeping my whole life on a laptop, but still be cool like the other kids (I’ve so far avoided multi-monitor setups because I love my laptop too much and I was afraid of the conflicting addictions).

The 2nd thing I get is a result of the first, i.e. if I’m going to use the Tablet as an adjunct to my laptop, then I shouldn’t worry about a generation sometime in the future where Tablet convertibles can replace my laptop, but just get the best slate I can find and enjoy it as a remote viewer/editor of info via file sharing and terminal services.

If you have a device you’d like to turn into a 2nd monitor and you don’t yet have MaxiVista, Scott Hanselman’s posted a 30% off MaxiVista coupon.

October 29, 2004 .net

First Commercial .NET No Touch Deployment App

Mark Levison of Databeacon talks about the first commercial-grade .NET No-Touch Deployment application to be deployed over the internet (at least, as far as he and I know). I asked Mark what his motivations were for using a smart client instead of a web app. These were his reasons:

  1. Integration with Desktop export to excel, word, send to mail recipient, etc.
  2. The user never has to wait for a round trip to the server. Once the application is up and running everything is done locally, the user is never left waiting by a suddenly slow internet connection.
  3. Our application gets a full blown window with its menu and toolbar, we’re not stuck inside of IE.
  4. Uses the clients CPU do all of work. Our application is graphically and sometimes computationally intensive, if we did all of this work server side, we would eventually run into scaling problems.”

Congrats Mark and Databeacon. This is but the beginning of much greater things to come.

NOTE: I don’t know if this was exuberance at making the instructions for running the sample easy or not, but you should absolutely not [u]se the Microsoft .NET Framework wizard to grant full trust to trusted sites.” Trusted or not, you should not award any code any more permission than it needs. For instructions on how to build an MSI setup for configuring a NTD client for just the right amount of permissions until you can use ClickOnce (which handles permission elevation much better than NTD), you can read this article on the topic.

October 28, 2004 .net

Way Cool Windows Forms 2.0 Samples

My Windows Forms partner in crime, Mike Weinhardt, pointed out to me this morning that the Windows Forms team has posted their way cool Windows Forms 2.0 samples, including:

  • Design Mode Dialog - Mike Harsh
    This is a sample dialog component that allows any form to go into design mode” at runtime. This component highlights the new, easy to consume, designer infrastructure APIs in Whidbey and has the same usage pattern as other common dialogs.
  • Stock Quote Chart Generator - Joe Stegman
    This app uses the sample asynchronously polls a web service for stock quotes and charts the results over a customizable time period.
  • MSN Messenger Clone - Scott Morrison
    This is a Windows Forms app that emulates the functionality of MSN Messenger.
  • Internet Explorer Clone - Joe Stegman
    This is a Windows Forms app that looks like Internet Explorer 6 and uses the new WebBrowser control.
  • Windows Forms RSS Portal - Joe Stegman
    This is portal type application that aggregates RSS feeds asynchronously.
  • Outlook 2003 Clone - Joe Stegman
    This is a UI front end that has the look and feel of Microsoft Outlook 2003.
October 26, 2004

Inside Some MS Product Team Processes

It was very cool to see into some of the internal MS product team processes:

This stuff is very cool because even internally, if you’re not on a product team or if you’re on a different product team, it’s useful to see what other product teams do.

This just makes you want to drop everything and sign up for a product team, doesn’t it? MS is hiring…


← Newer Entries Older Entries →