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. 开发者_Python百科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
Usually when you call message box functions, they take a "parent" window as an argument. Which window are you passing as the "parent" window?
may be you call message box in a second thread not in main thread
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; }
}
}
精彩评论