(Tool)Band Aid

So, I recently completed writing a Desk band for windows. What is a desk band, you ask? Well, your windows start bar is the home for several desk band objects. These are basically COM objects that support a bunch of interfaces and register themselves in appropriate places so that windows knows to load them.

In short, you register your windows class and it gets put in the toolbar. Nearly the same code can work in multiple places in IE, Explorer, and in the Start Bar. So, I learned a few lessons:
  • It is far easier to do your initial development so the band will work in the IE toolbar than in the start bar. This lets just run the COM object (and automatically start IE) rather than manually starting up the desk band, and attaching to the Explorer process. When you get most of what you need done, you can test it in the Start bar.
  • A conditional compilation switch in your code will make sure that you don't accidentally register the release version of your desk band object to run in IE (if you don't intend it to).

So, I based my deskband on the sample SDK code from Microsoft. But it has a few problems.

  • It registers fine. The normal "regsvr32 myobj.dll" works great, but it doesn't implement any unregister functions. You have to write those yourself. Now, I know that if you use ATL or MFC that you can get that for basically free, but it seems a bit of an overkill if you are doing just a small simple COM object. And besides, you have to do custom registration for it to get loaded automatically anyway.
  • The window with the text is kind of ugly. I really wanted a desk band that didn't have a big square box.

So, here's what I did to get rid of the box...

First of all, I registered the window class with a background color of NULL. That way, it won't automatically erase the background with blue. I also changed the flags so that there isn't a black border around the window contents.

The next thing I did was implement a handler for the Erase method that windows will call whenever the window needs to be erased. MSDN says that you should do this. If you don't do this, you'll get text that writes on top of itself over and over, works fine until your text changes. Then it looks like some kid scribbled on the screen. But at least you have the same background that the toolbar has. (there are some people that don't use the blue jelly toolbar, they must like grey).

So, how do we keep the nice gradient, or the grey background, or whatever they have as a background while we're drawing on it all the time? StretchBitBlt. Enough said.

... What? That wasn't enough said?

Ok, so here's what I did. realizing that the gradient is vertical, when my erase event gets invoked, I just stretch bit blit whatever is on the left hand side of the draw window all the way across my drawing rect. Then, I text out on top of that. It's easy once you figure it out.


Popular posts from this blog

KnockoutJS, WebAPI, and TypeScript

The most efficient algorithm to scan a bitmap