K
Kevin Westhead
I'm experiencing a problem where I have a non-modal toolwindow that contains
a control derived from System.Windows.Forms.ComboBox displayed in an MDI
application. Whenever a .NET message box is displayed in the application the
derived combo boxes on the toolwindow appear to lose their base control,
i.e. base.WndProc(ref m) in the derived control's WndProc results in a
NullReferenceException. Admittedly this could be a problem with the derived
controls, however after looking at how System.Windows.Forms.MessageBox works
it seems like there are some "oddities". Also, if I call the Win32
MessageBox function directly via p/invoke, specifying the correct owner
window, then everything works fine.
Here is the section of System.Windows.Forms.MessageBox (ShowCore) that I've
been looking at:
if ((owner != null) && ((options & 2228224) != 0))
throw new ArgumentException(SR.GetString("CantShowMBServiceWithOwner"),
"style");
IntSecurity.SafeSubWindows.Demand();
num1 = (((buttons | icon) | defaultButton) | options);
ptr1 = IntPtr.Zero;
if ((options & 2228224) == 0)
{
if (owner == null)
ptr1 = UnsafeNativeMethods.GetActiveWindow();
else
ptr1 = owner.Handle;
}
Application.BeginModalMessageLoop();
result1 = MessageBox.Win32ToDialogResult(SafeNativeMethods.MessageBox(new
HandleRef(owner, ptr1), text, caption, num1));
Application.EndModalMessageLoop();
return result1;
The value of 2228224 corresponds to MessageBoxOptions.DefaultDesktopOnly |
MessageBoxOptions.ServiceNotification. The interesting thing here is that
the owner parameter is always ignored since owner must be null when options
contains the above flags. If owner is not null, the handle is never
retrieved because options cannot also contain the above flags and therefore
ptr1 remains as IntPtr.Zero. The other interesting thing is the
BeginModalMessageLoop/EndModalMessageLoop block. It appears as though this
disables all windows in the current thread, although I haven't looked at
this too deeply, and this further implies that the owner parameter plays no
part in establishing modality. Does anyone have any thoughts on this,
particularly with reference to the fact that the
BeginModalMessageLoop/EndModalMessageLoop block appears to be causing severe
problems for my non-modal windows? A single call to the Win32 MessageBox
function with a correctly specified owner window does not exhibit the same
problems.
TIA.
a control derived from System.Windows.Forms.ComboBox displayed in an MDI
application. Whenever a .NET message box is displayed in the application the
derived combo boxes on the toolwindow appear to lose their base control,
i.e. base.WndProc(ref m) in the derived control's WndProc results in a
NullReferenceException. Admittedly this could be a problem with the derived
controls, however after looking at how System.Windows.Forms.MessageBox works
it seems like there are some "oddities". Also, if I call the Win32
MessageBox function directly via p/invoke, specifying the correct owner
window, then everything works fine.
Here is the section of System.Windows.Forms.MessageBox (ShowCore) that I've
been looking at:
if ((owner != null) && ((options & 2228224) != 0))
throw new ArgumentException(SR.GetString("CantShowMBServiceWithOwner"),
"style");
IntSecurity.SafeSubWindows.Demand();
num1 = (((buttons | icon) | defaultButton) | options);
ptr1 = IntPtr.Zero;
if ((options & 2228224) == 0)
{
if (owner == null)
ptr1 = UnsafeNativeMethods.GetActiveWindow();
else
ptr1 = owner.Handle;
}
Application.BeginModalMessageLoop();
result1 = MessageBox.Win32ToDialogResult(SafeNativeMethods.MessageBox(new
HandleRef(owner, ptr1), text, caption, num1));
Application.EndModalMessageLoop();
return result1;
The value of 2228224 corresponds to MessageBoxOptions.DefaultDesktopOnly |
MessageBoxOptions.ServiceNotification. The interesting thing here is that
the owner parameter is always ignored since owner must be null when options
contains the above flags. If owner is not null, the handle is never
retrieved because options cannot also contain the above flags and therefore
ptr1 remains as IntPtr.Zero. The other interesting thing is the
BeginModalMessageLoop/EndModalMessageLoop block. It appears as though this
disables all windows in the current thread, although I haven't looked at
this too deeply, and this further implies that the owner parameter plays no
part in establishing modality. Does anyone have any thoughts on this,
particularly with reference to the fact that the
BeginModalMessageLoop/EndModalMessageLoop block appears to be causing severe
problems for my non-modal windows? A single call to the Win32 MessageBox
function with a correctly specified owner window does not exhibit the same
problems.
TIA.