user626528
user626528

Reputation: 14399

Message box under the main window

Sometimes my message box is shown under the main window of the application. Thus, message box is invisible and the main window looks like it's hanged and doesn't responds to any input. It's possible to "unfreeze" the main window by using alt-tab to switch to another app and back, and it finally shows message box in it's right place - above the main window. But this is not obvious for the user.

Any ideas, how to avoid this problem?

UPD the main window is native; I've tried using MessageBox with and without specifying parent window, but had the same problem in both cases

Upvotes: 1

Views: 956

Answers (3)

user626528
user626528

Reputation: 14399

I'm not sure what was the reason, but using my own wrapper for the native parent window fixed this problem:

public class Win32Window : IWin32Window
{
    public Win32Window(IntPtr val)
    {
        _handle = val;
    }

    readonly IntPtr _handle;

    public IntPtr Handle
    {
        get { return _handle; }
    }
}

Upvotes: 0

DeveloperX
DeveloperX

Reputation: 4683

may be you call message box in a second thread not in main thread

Upvotes: 0

Michael Pryor
Michael Pryor

Reputation: 25336

Usually when you call message box functions, they take a "parent" window as an argument. Which window are you passing as the "parent" window?

Upvotes: 2

Related Questions