Flashback: Windows Forms Parking Window

I've been doing some research around component models for Silverlight.  Since Silverlight brings us back to a client side programming model (yay member variables!), I started cruising through the Windows Forms source looking at some of the things we did back then as a way to remind myself of some of the subtleties of working in that space.  I'm looking for those things that you don't usually think of until you're about 75% done with coding then realize you didn't plan for it.

Anyway, since I worked on Windows Forms for the better part of 7 years, it's a bit nostalgic cruising through some of this code.  Just like how when you open your old high school yearbook and see someones picture and go "wow, I haven't even thought of that person in years", I came across a Windows-Forms-ism called...

The Parking Window.

The Parking Wha?  Yes, the Parking Window.

One of our goals with Windows Forms was try to smooth out as much of the oddity of Win32 as we could.  And one of the principal oddities is that of window handle (HWND) management and lifetime.  We certainly didn't want the average user to need to worry about this stuff.  In most cases, it was pretty easy.  You just gather up all of the state, and then when you actually need to show the window, you do the creation on demand, then you drive your state off the HWND instead of your internal members. 

Well, this doesn't always work so well.  See, there are certain properties of Win32 windows that you can't change once the window is created.  Like the style of the border, for example.  So to allow a user to change the border style after the window has been created, you need to recreate the handle.  Which means you need to not only pull all of the state out you want out of the existing one, but you need to recreate it and push it back in.  Okay, that's not too hard. 

But what about the children?  Oh, fiddlesticks.  The kids.

If the window you're modifying the border on has children, destroying its handle will destroy the handles of all of its children as well.  Then you need to recreate them, which is very expensive.  And expensive is bad. 

Enter the Parking Window.  The Parking Window was our solution to this problem.  It was somewhere that you could "park" HWNDs until you have a fitting parent for them.  Think of it as Window Handle Foster Care, but invisible.

So in the case of a handle-recreate, we'd check to see if there were any children.  If there were, we'd (if needed) create the Parking Window, parent the children to that, recreate the parent's handle, then move them back over.  Worked pretty well, though managing the lifetime of the Parking Window did cause some problems...

Good times.

Comments (7)

  1. What fun. Myself and anyone using Windows Forms for an extended period of time, or just making heavy use of it, have received countless exceptions somehow relating to this mysterious "parkingwindow" lurking in the background. Debugging problems that cropped up citing the "parkingwindow" means heavy use of Reflector because nobody outside of Microsoft can step into the winforms code.

    I don’t suppose you ever succeeded in getting anyone to think about releasing that code. I know you’ve moved on, but believe it or not, there are thousands of people out there still struggling with the quirkiness of windows forms on a daily basis.

    Of course, we now have a whole load more quirks in the vast WPF api to play with.

    Tim Dawson

    Divelements Limited

  2. Believe it or not…still workin on it…

  3. sciguy says:

    Unfortunately, Windows Forms Parking Window has been a bit of a pain for me during debugging. The first application in which I encountered it, it was stealing input focus. I hadn’t dealt with that completely before it started appearing in the task bar.

    Frustrating times. *shivers*

  4. Hmm – that’s concerning.  I’d like to see a repro of that.  Given that it’s invisible, it does seem troubling that it’s stealing focus.

  5. tvavrda says:

    Hi, I also have a repro of such a problem – parking window stealing focus after an MDI child form closes.

    I’ve read somewhere, that this could be caused by not disposing the form correctly. Which could be the case, but it is quite a problem to debug this.

  6. Ed Fielding says:

    Good explanation. Comment about the year-book made me think of programming unix systems in C and using the "CURSES LIBRARY"


    Reason for search was that I installed Silverlight Monday and now system locks up a lot for no known reason and when i reboot I usually see about 4 or 5 Windows Forms Parking Windows pop up and then go away … a couple of times I had to manually end the Form.

  7. ario31 says:

    Since you sound so good at this subject, (WindowsFormsParkingWindow) why is it that every time I go to shut down my computer, the WindowsFormsParkingWindow has stop responding, end now box pops up? My OS is Windows XP SP3 and have set for auto updates, plus check the updates site about once a week just to make sure I’m getting them all. This happens without fail EVERY TIME I go to shut down. I can’t hit shut-down and dart out the door because 8 hours later the screen is still there waiting on my to end now. Any ideas??



Skip to main content