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.