private void UnmapWindow(Hwnd hwnd, WindowType windows) {
if (hwnd.mapped) {
Form f = null;
if (Control.FromHandle(hwnd.Handle) is Form) {
f = Control.FromHandle(hwnd.Handle) as Form;
if (f.WindowState == FormWindowState.Normal) {
f.waiting_showwindow = true;
SendMessage(hwnd.Handle, Msg.WM_SHOWWINDOW, IntPtr.Zero, IntPtr.Zero);
}
}
// it's possible that our Hwnd is no
// longer valid after making that
// SendMessage call, so check here.
// FIXME: it is likely wrong, as it has already sent WM_SHOWWINDOW
if (hwnd.zombie)
return;
if ((windows & WindowType.Client) != 0) {
XUnmapWindow(DisplayHandle, hwnd.client_window);
}
if ((windows & WindowType.Whole) != 0) {
XUnmapWindow(DisplayHandle, hwnd.whole_window);
}
hwnd.mapped = false;
if (f != null) {
if (f.waiting_showwindow) {
WaitForHwndMessage (hwnd, Msg.WM_SHOWWINDOW);
CreateParams cp = f.GetCreateParams();
if (!ExStyleSet (cp.ExStyle, WindowExStyles.WS_EX_MDICHILD) &&
!StyleSet (cp.Style, WindowStyles.WS_CHILD)) {
WaitForHwndMessage (hwnd, Msg.WM_ACTIVATE, true);
}
}
}
}
}