+ // Preserve the focus when minimizing/restoring the window: we
+ // need to do it manually as DefWindowProc() doesn't appear to
+ // do this for us for some reason (perhaps because we don't use
+ // WM_NEXTDLGCTL for setting focus?). Moreover, our code in
+ // OnActivate() doesn't work in this case as we receive the
+ // deactivation event too late when the window is being
+ // minimized and the focus is already NULL by then. Similarly,
+ // we receive the activation event too early and restoring
+ // focus in it fails because the window is still minimized. So
+ // we need to do it here.
+ if ( id == SC_MINIMIZE )
+ {
+ // For minimization, it's simple enough: just save the
+ // focus as usual. The important thing is that we're not
+ // minimized yet, so this works correctly.
+ DoSaveLastFocus();
+ }
+ else if ( id == SC_RESTORE )
+ {
+ // For restoring, it's trickier as DefWindowProc() sets
+ // focus to the window itself. So run it first and restore
+ // our saved focus only afterwards.
+ processed = true;
+ rc = wxTopLevelWindowBase::MSWWindowProc(message,
+ wParam, lParam);
+
+ DoRestoreLastFocus();
+ }
+
+#ifndef __WXUNIVERSAL__
+ // We need to generate events for the custom items added to the
+ // system menu if it had been created (and presumably modified).
+ // As SC_SIZE is the first of the system-defined commands, we
+ // only do this for the custom commands before it and leave
+ // SC_SIZE and everything after it to DefWindowProc().
+ if ( m_menuSystem && id < SC_SIZE )