tags:

views:

1921

answers:

4

I am using the SplashScreen feature in WPF by setting a bitmap's Build Action to Splashscreen. Behind the splash screen licensing information is being check, and if it fails I show a MessageBox.

According to this Feedback, it is because the MessageBox.Owner is the splash screen and as soon as another window is open even if it is a MessageBox the splash screen window is closed which then in turn closes the MessageBox, so the user never sees the MessageBox.

So the workaround would be to set the MessageBox.Owner to another window, but that means that I have to instantiate another window which might not even be needed.

Would it be possible to set the MessageBox.Owner to the desktop window? And how, because the only other function that comes to mind is the GetDesktopWindow() api function, but that returns a window handle and MessageBox.Owner is a WPF Window.

+1  A: 

Can you post some code? I just tried adding this to the App.xaml.cs file in a new WPF application:

protected override void OnStartup(StartupEventArgs e)
{
    if (MessageBox.Show("Start app?", "Confirm Start", 
        MessageBoxButton.YesNo) == MessageBoxResult.No)
    {
        this.Shutdown();
        return;
    }

    this.StartupUri = new Uri("Window1.xaml", UriKind.Relative);
    base.OnStartup(e);
}

... and it works as expected (the "Confirm Start" prompt stays open until I've responded, and if I click "No" the app shuts down).

Matt Hamilton
Matt, I also tested it like you did and realized it does work, because I was using a splash screen, it closes the MessageBox, without the splash screen it did not close
adriaanp
So I guess now you need to decide whether to close the question as "No longer relevant" or (as @adriaanp suggests in his comment) rework it as a different question.
Matt Hamilton
+3  A: 

I found the problem. I am also using the build-in splash screen which causes this: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=381980&wa=wsignin1.0

adriaanp
The question would now be how would you set the owner of the MessageBox to the deskop window?
adriaanp
A: 

The desktop window is never the correct parent, read this to know why:

http://blogs.msdn.com/oldnewthing/archive/2004/02/24/79212.aspx

Now the problem described in this post doesn't happen so much because MS worked around it, in this post you can see how:

http://blogs.msdn.com/oldnewthing/archive/2006/11/02/931674.aspx

Nir
A: 

this has helped me a lot ..... Given me new idea but the example code that i have seen here has some modification required

here is an simple example in wpf with modification now it is working

on button click

paste this code

if (System.Windows.Forms.MessageBox.Show("are u sure", "delete", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Question) == System.Windows.Forms.DialogResult.Yes) { this.Close(); } else { MessageBox.Show("why not to delete"); }