Thursday, March 09, 2006

iPod Mame

I don't have a iPod video or nano, but this looks pretty cool: Mame on the iPod

Tuesday, March 07, 2006

Getting Real Work Done in .NET Windows Forms

I have been working on a Windows Forms (WinForms) applications since Christmas 2005. The application essentially sends files to a web site for business logic processing and receives notifications, via RSS, that the user should be interested in. This is the first WinForms app I have developed entirely on my own. When I was working for Vertigo Software I was the Project Lead/Technical Lead on a number of WinForms apps that were pretty sophisticated. Using IE to do some pretty cool rendering tricks, BITS to download application updates, and good UI. One of those apps was the Windows Server 2003 Guided Tour But this is different because I am doing it all and its eye opening. To get your WinForms app to behave like a first class Windows app, you absolutely are going to step outside the .NET managed libraries and you need to understand how an actual Win32 application is constructed. I am sure this is not news to many, and I knew this is was the case going into this development effort, but it still bears repeating. What am I talking about? Take for instance the behavior of something like MSN Messenger with the close button. Everyone is familiar with this pattern now:
  • Application main window is running and visible to the user
  • Application has a button in the Taskbar and and icon in the tray (i.e. the stuff next to the clock)
  • User clicks the Close button (i.e. the red X). Normally this exits the application, but your app is special
  • Your app should hide its taskbar button but stay running and keep its icon in the tray
How are you going to do this in WinForms? Your first instinct is to register for the Form.Closing event, cancel the event and then hide your form. You also need to show an icon in the tray. Hooking Form.Closing is part of the solution, as is hiding your form (e.g. Form.Visible=False) but this leaves once pretty big whole in the functionality of your application. If your app is running and the user tries to Logoff or Shutdown/Restart the computer, you are implicitely cancelling that event. The user Logging off, Shutting down, or restarting is called ending their session according to Windows. The only way for the user to end their session if your app is cancelling Form.Closing is to kill it with Task Manager! This is obviosuly bad and this is all it takes (in C#):
private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
      e.Cancel=true;
}
How do you solve this problem? What you really want to do is cancel the Form.Closing event in cases where the user session isn't ending. You might think that Environment.HasShutdownStarted would be your salvation, and you would be wrong. You might then stumble onto the Microsoft.Win32.SystemEvents.SessionEnding event and hook it. Here is the description from MSDN:
Occurs when the user is trying to log off or shut down the system.
Great I will just hook that and, nada. That's right, There is no guarantee your Form will receive this event before Form.Closing is fired, thus making it useless for your purposes. So what do you do? You Google like mad and hope someone has figured this because you can hear Han Solo saying in your head: "I have a bad feeling about this." Lucky for you, they have and and its actually the poor MS employee writing the documentation for Microsoft.Win32.SystemEvents.SessionEnding because in the explanation of this event, there is sample code to do exactly what you want. How does it work? You have to override the actual message loop processing function, the same one that has existing in Win32 forever, and listen to the WM_QUERYENDSESSION message manually. Then you have to track whether you have received this message manuallly and respond to it in Form.Closing. Ah, now everything behaves right. Why the data about WHY your form is closing isn't in CancelEventArgs boggles the mind. This is far from the only example, but this post is long enough as is. What lesson have I learned from this development effort? Win32 knowledge is going to be relevant for a long time, even with Windows Presentation Foundation (WPF) on the horizon. MS never seems to completely replace the last application development with the new one. Charles Petzold has already confirmed that WPF won't have even all the controls that WinForms has. Maybe this is just me, but is MS ever going to finish one framework before replacing it with another? Win32->MFC->ATL->VB6->WinForms->WPF, when is it going to stabalize? I have been on this ride enough that I don't know if I want to get on the WPF roller coaster. Cocoa is looking better and better...

Monday, March 06, 2006

First Impression: iPod Hi-Fi

Took a look at the iPod Hi-Fi at a local Apple Store this weekend. This is not a comprehensive review, for those, I have read the following: iLoung e Review PC Magazine Review Playlist Review I generally avoid knee-jerk reactions to product announcements now when there is a very good chance I can get my hands on it myself, like with the Apple products. First Impression Man does this sound good. I didn't tweak anything, just walked up to a free iPod Hi-Fi in the Apple Store, put some Alica Keys on, and stepped back. I am no audiophile. I do occasionally compare Apple Lossless to AAC 128 kbps, but I really can't hear a difference. I have some stuff in Lossless (e.g. Batman Begins soundtrack just because I ripped it that way and I don't need the space back yet). The iPod Hi-Fi sounds better to my ears than my Kenwood 5.1 Dolby Digital Home Theatre in a box that I got a number of years ago, at least for music. I have been considering a speaker system just for iPods for a while now, specifically for the kitchen, bedroom, or outdoors. So I am tempted by this. Arguements FOR include portability (D batteries!), can be connected to an Airport Express for wireless streaming, and the sound. Arguements AGAINST include price ($350!), need an iPod video or nano for full features, and I need another Airport Express for wireless streaming. Unless I get this gifted to me, I won't be buying one right now for myself. I like the design, but I think if either $350 included wireless or this was $50 cheaper, it would have been an easy sell, but maybe I am not the target market for this. Bigger Picture One of the complaints about the iPod Hi-Fi you hear is that this doesn't include radio or a CD player. Apple's tagline for this is "Home Stereo. Reinvented" and some people just don't get it. Apple is not trying to replace Sony's existing product lines. Apple's new devices are designed and intended to replace the various old analog based devices and provide the best merger of software and computer-based (i.e. hard drive and CPU based) technologies. Apple doesn't include a CD Player because the iPod replaces the CD player, why would you EVER AGAIN want a CD Player in a Home Stereo? One of the many reasons iPods have become wildly popular was because people were sick of FM Radio, why would you ever include FM Radio in a home stero again? Now whether or not you agree with any, all, or none of these decisions will determine if you buy Apple products or not. I happen to agree with most, certainly the CD Player and FM Radio exclusions. I have FM Radio on my Kenwood HIB, I have never used it.

Thursday, March 02, 2006

Tip: SqlHelper Debugging using IISReset

This is one of those things you always forget because you do it so infrequently. If you use Microsoft's SqlHelper (original not EntLib) to connect to SQL Server and call stored procedures, you should probably be aware that SqlHelper gets a list of your stored procedures parameters from SQL Server ultimately by calling SqlCommandBuilder.DeriveParameters(..). These parameter definitions get cached until your AppDomain is reloaded. The sticky bit here is that if you are changing the number of parameters on a stored procedure where its parameter definitions have already been cached, then you will see exceptions from SqlHelper that the parameter count doensn't the data you are passing in because your business tier code has already been updated to reflect the new parameter count. If you are in ASP.NET, just do an IISReset and save yourself time debugging whether you are connecting to the right database, if you really had updated the sproc, if SQL is finding a different sproc becauase its not qualified by the user that created it (e.g. SomeProc instead of dbo.SomeProc) like I just did. :)

Tuesday, February 28, 2006

Or Not Installing Vista in Virtual PC for Mac

As soon as I posted the last entry, I Apple-Tabbed back over to Virtual PC to be greeted by the following error message: Click for larger version I thought the odds on this were 50/50, now I know which 50 this CTP falls into. For completeness, I choose Win XP Pro as the OS when creating the new PC, I also tried an Unspecified OS with the same results.

Impressive Mac Windows Compatibility Scenario

My IBM Thinkpad T42 doesn't have a DVD burner. This is particularly bad since I need to get a copy of the Windows Vista February CTP burned and installed somewhere, I finally have the itch now that Vista is feature complete to start checking this out for myself. In the office, there is like one shared DVD burner that no one seems to know where it is, anyway its a hassle to track it down. I am working from home today and I think I have a DVD burner in the iMac, can I copy the .iso over and burn a DVD. This ended up presenting no problem. I copied the 2.4 GB file over my wireless network using Windows File Sharing from the T42 to the Mac. I then dragged the .iso to Roxio Toast 6 Titanium to burn the DVD. This is impressive to me because I copied such a large file over wireless between platforms with no errors and the DVD burned without any problems. Vista is installing in Virtual PC on the Mac right now...

Thursday, February 09, 2006

Top Current Windows XP Annoyance: Multiple Monitor Support

If you have ever used multiple monitor support in Windows XP, then it is highly likely you have experienced the pain I will betalking about. I use mutiple monitors when I plug my ThinkPad into a docking station for my deskbound LCD. This is what I think SHOULD happen:
  • Secondary display should extend the desktop without my intervention.
  • The second display should have a taskbar without the Start button.
  • The icons on my primary desktop (i.e. the one permanently attached to my computer) should not move.
This is what Windows XP does:
  • Nothing. I have to do something to trigger the activation of the secondary display. My current method of choice is the Thinkpad hotkey, but...
  • I can't activate extending the desktop as a permanent option. I have to go into Display Properties to turn on extension and move the displays around to the proper location. I do this nearly everyday.
  • After setting up the desktop, my desktop icons are moved to the new extended desktop most of the time. This is inexcusable in a 5 year old product.
Alas, I know there is a utility to do this, Ultramon (thanks to Scott Hanselman's Ultimate Tool List), but I am not paying $39.95 to get functionality that should be in Windows XP. A quick Google for what the situtation will be like in Vista reveals only that there will be unspecified improvements. CNet has this article which mentions mutiple-monitor improvements, best quote:
Suokko said the company wants to make it easier for laptops to connect to any external monitors that happen to be available. "It's there, but it's somewhat complex today," he said.
Also of potential interest for current Windows users may be MaxiVista to use a laptop or other PC as a secondary display. And MS has this article which reitereates much of what I just said. There is also an open source project, Synergy. This is not strictly a multiple monitor solution, but it does allow you to use a single mouse and keyboard across mutiple computers, Mac, Windows, or Unix. I haven't tested it yet, but it could be cool. You might want the Mac GUI for it from SynergyKM (thanks Lifehacker). And as for what the situation is like on the Mac, I have only connected one external display, a project, to my iBook a few years ago, all I remember was that it worked and I didn't have to fiddle with OS X. But I did find this Mac OS X Tiger Timesaver: Using Multiple Displays article on Dummies.com with screenshots. Looks mostly the same as in Windows XP, except you can pick which monitor the Menu Bar is put on. I might have to bring in my PowerBook to work and connect to the external LCD to see if settings persist across monitor connections, which is The Way It Should Be™.

Will the real video iPod please stand up?

ThinkSecret is reporting a True video iPod to sport 3.5-inch display, touch-screen click wheel is set for release as early as this spring. In Steve Jobs' January Macworld Keynote, April 1, the 30th anniversary of Apple Computer, Inc. might see some interesting annoucements. If ThinkSecret is right, this totally makes sense. Is this the portable video device I have been waiting for? It just might be. A 3.5" diagnol screen would actually fit in the existing iPod shell if the click wheel is removed. I maintain the PSP is too big for truly portable video, you can't put the device in your pocket or on a belt clip without it getting ridiculous. I also maintain that optical discs and memory cards on the PSP are yesterday's storage solutions, downloads for everything. The key with this new iPod has to be fingerprints on the display. How are they going to keep finger prints off of it? Every touch-screen I have ever seen is mucked up with prints. Are you going to have to carry around a lint cloth to wipe the screen to watch video? Anyway, this will make a nice birthday present to myself if it's real. :)

Thursday, February 02, 2006

AnandTech: Apple Makes the Switch: iMac G5 vs. iMac Core Duo

AnandTech: Apple Makes the Switch: iMac G5 vs. iMac Core Duo Really good performance comparison on AnandTech between the iMac G5 and the iMac Core Duo. I especially like when they disable one of the cores on the Intel chip and pit it against the G5. From my view, this says that the PPC architecture was good, it's too bad IBM didn't care or wasn't fast enough in competing with Intel and AMD on dual core and low power designs. Anyway, technically it won't make a differnece how good the G5 is when you can run Windows and OS X on the same hardware.

Programmatically changing log file names in Log4net

I am working on a side Windows Forms project that of course I need logging in. I had spent some time looking at log4net to use as a common logging framework for all the apps we build at my company, so I thought I could save some time instead of rolling my own. Plus I have an aversion to the MS Enterprise Library, seems like you get a whole lot of "tax" just to get something like logging. So I integrated log4net into my Windows Forms project because I really wanted to RollingFile appender. log4net is all configuration based. You can either embed the configuration in your app.config or in a seperate log file. This includes the path and name of the file to log to with the RollingFile appender. Trouble is I don't know the path until run-time because it is dependent on the user's profile directory. Unfortunately, the IntelliSense on the log4net objects provide no obvious way to get to the appenders, no obvious way that is unless you completely understand their "repository" concept. Thankfully, someone else does: Programmatically changing log file names in Log4net This works like a charm and I am extremely happy with it.