views:

202

answers:

2

Yesterday I asked a question about starting an application hidden on windows mobile : See Here

According to ctacke's answer I want to create my own message pump to prevent Application.Run method to show the form, but I don't know how to do that. It would be OK if you can show me an example on how to create a custom message pump in c# or suggest me a reference about it.

Thanks in advance

+1  A: 
KMan
+1  A: 

Replacing the message loop in the Application class is not practical. There is far more going on then the boilerplate Windows message loop. It isn't the real problem anyway, the Application class forces the form to become visible with a call to ShowWindow(). That's necessary because forms are lazily initialized, without the ShowWindow() call it never creates the native Window handle.

This issue is easy to fix in the regular .NET framework version by overriding SetVisibleCore():

protected override void SetVisibleCore(bool value) {
  if (!this.IsHandleCreated) {
    this.CreateHandle();
    value = false;  // Prevent becoming visible the first time
  }
  base.SetVisibleCore(value);
}

But I don't think that's available in CF. To find a solution, you'll need to explain exactly why you want to prevent the UI from being shown. Without any created window handle, an app is usually dead as a doornail. It could be as simple as delaying the Application.Run() call.

Hans Passant
It's not trivial, but I'll disagree that it's not practical. The SDF does it, and does it just fine. There are many cases where it's useful - like if you actually want to support IMessageFilters or, like this user, actually control the visibility of the start form.
ctacke