+#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;
+
+#if !defined(__WXMICROWIN__) && !defined(__WXWINCE__)
+#if wxUSE_MENUS
+ case WM_INITMENUPOPUP:
+ processed = HandleMenuPopup(wxEVT_MENU_OPEN, (WXHMENU)wParam);
+ break;
+
+ case WM_MENUSELECT:
+ {
+ WXWORD item, flags;
+ WXHMENU hmenu;
+ UnpackMenuSelect(wParam, lParam, &item, &flags, &hmenu);
+
+ processed = HandleMenuSelect(item, flags, hmenu);
+ }
+ break;
+
+ case WM_EXITMENULOOP:
+ // Under Windows 98 and 2000 and later we're going to get
+ // WM_UNINITMENUPOPUP which will be used to generate this event
+ // with more information (notably the menu that was closed) so we
+ // only need this one under old Windows systems where the newer
+ // event is never sent.
+ if ( wxGetWinVersion() < wxWinVersion_98 )
+ processed = HandleExitMenuLoop(wParam);
+ break;
+
+ case WM_UNINITMENUPOPUP:
+ processed = HandleMenuPopup(wxEVT_MENU_CLOSE, (WXHMENU)wParam);
+ break;
+#endif // wxUSE_MENUS
+#endif // !__WXMICROWIN__