views:

181

answers:

2

Working in .NET Compact Framework, C#, .Net 3.5, Visual Studio 2008. Targeting Windows Mobile and CE devices from the same project (it's a CE app, runs on both types of devices).

I have a form that must be displayed using ShowDialog. the form itself is just a blank screen with a "loading..." message on it. AFTER the form displays on the screen, I need to run another chunk of code on the same thread that will pop up another form using ShowDialog, so that the "Loading" screen is the parent of the new screen.

don't tell me that this scenario is wrong or i shouldn't use showdialog. we've been through that as a team and this is the way we are writing the app because it solves a significant number of other problems.

... the problem with this scenario, though, is that there is no Shown even in compact framework, so I can't do my usual trick of putting code in that event to do this.

how do other people solve this need in compact framework? if it helps, i do have the OpenNetCF library... is there something in there that can help?

A: 

Okay, I'll resist my very strong urge to tell you that this is wrong and you shouldn't be using ShowDialog. Now that I've not said it, let's look at what's going on.

Your app calls Application.Run at some point. That sets up a message pump that dispatches Windows events to the proper Windows (controls) in the system.

When you call ShowDialog, the system sets up another temporary message pump. This means that Windows events coming into this pump will not get dispatched outside to other controls (this is how you get the modality).

Now you're saying you need to pop yet another dialog on top of that (so creating yet another pump) but you need it to come up after some sort of initialization code in the first Dialog (not the overall parent Form) has been displayed.

Is this all correct? If so, I think there are two routes I'd look at. First, I'd look at overriding OnActivated in the first Dialog. Since you're using ShowDialog I'd think that it would be nearly synonymous with the Shown event.

If that doesn't quite get you what you want, then I'd look at adding a MessageWindow to the first dialog (or using the SDF's NativeWindow to subclass it) and look at all of the Windows messages coming in to provide your own Shown event.

ctacke
a coworker pointed me to the NativeWindow and I am already using MessageWindow in another context... i'll look into this further. It sounds like it's the most viable answer to the problem.
Derick Bailey
well that was a useless endeavor. turns out there is 0x18 message (WM_SHOWWINDOW) in compact framework... at all... so there is now Show event becasue the message pump for CE doesn't have that message. what the crap?!....
Derick Bailey
Sure, and that's why the CF doesn't have the Shown event. But if you have it subclassed you can then look at things like WM_WINDOWPOSCHANGED, WM_ENABLE and WM_CREATE to figure out when it is being shown.
ctacke
A: 

ended up using form activate with a boolean to check and see if i've done the work or not

Derick Bailey