+
+bool wxTopLevelWindowMSW::EnableCloseButton(bool enable)
+{
+#ifndef __WXMICROWIN__
+ // get system (a.k.a. window) menu
+ HMENU hmenu = ::GetSystemMenu(GetHwnd(), FALSE /* get it */);
+ if ( !hmenu )
+ {
+ wxLogLastError(_T("GetSystemMenu"));
+
+ return FALSE;
+ }
+
+ // enabling/disabling the close item from it also automatically
+ // disables/enables the close title bar button
+ if ( ::EnableMenuItem(hmenu, SC_CLOSE,
+ MF_BYCOMMAND |
+ (enable ? MF_ENABLED : MF_GRAYED)) == -1 )
+ {
+ wxLogLastError(_T("EnableMenuItem(SC_CLOSE)"));
+
+ return FALSE;
+ }
+
+ // update appearance immediately
+ if ( !::DrawMenuBar(GetHwnd()) )
+ {
+ wxLogLastError(_T("DrawMenuBar"));
+ }
+#endif // !__WXMICROWIN__
+
+ return TRUE;
+}
+
+// ----------------------------------------------------------------------------
+// wxTopLevelWindowMSW message processing
+// ----------------------------------------------------------------------------
+
+long wxTopLevelWindowMSW::HandleNcActivate(bool activate)
+{
+#if wxUSE_POPUPWIN
+ /*
+ Normally, when another top level (whether it is overlapped or popup)
+ window is shown, it is activated and the parent window (i.e. we) loses
+ the activation. This, however, looks very ugly when the child window is
+ a [custom] combobox which we implement using a popup window as surely
+ opening a combobox shouldn't result in deactivating the parent window.
+
+ So we don't redraw the title bar in this case, even if we still return
+ TRUE to let the change of activation to take place as otherwise the
+ controls inside the popup window wouldn't work properly.
+ */
+ if ( !activate && wxPopupWindow::FindPopupFor(this) )
+ {
+ return TRUE;
+ }
+#endif // wxUSE_POPUPWIN
+
+ return FALSE;
+}
+
+long
+wxTopLevelWindowMSW::MSWWindowProc(WXUINT msg, WXWPARAM wParam, WXLPARAM lParam)
+{
+ if ( msg == WM_NCACTIVATE && HandleNcActivate(wParam != 0) )
+ {
+ // we processed WM_NCACTIVATE ourselves
+ return TRUE;
+ }
+
+ return wxTopLevelWindowBase::MSWWindowProc(msg, wParam, lParam);
+}