+#endif // __SMARTPHONE__ || __POCKETPC__
+
+ case WM_SYSCOMMAND:
+ {
+ // From MSDN:
+ //
+ // ... the four low-order bits of the wParam parameter are
+ // used internally by the system. To obtain the correct
+ // result when testing the value of wParam, an application
+ // must combine the value 0xFFF0 with the wParam value by
+ // using the bitwise AND operator.
+ unsigned id = wParam & 0xfff0;
+
+ // 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 )
+ {
+ if ( m_menuSystem->MSWCommand(0 /* unused anyhow */, id) )
+ processed = true;
+ }
+#endif // #ifndef __WXUNIVERSAL__
+ }
+ break;