void wxTopLevelWindowMSW::OnActivate(wxActivateEvent& event) { if ( event.GetActive() ) { // We get WM_ACTIVATE before being restored from iconized state, so we // can be still iconized here. In this case, avoid restoring the focus // as it doesn't work anyhow and we will do when we're really restored. if ( m_iconized ) { event.Skip(); return; } // restore focus to the child which was last focused unless one of our // children already has it (the frame having focus on itself does not // count, if only because this would be always the case for an MDI // child frame as the MDI parent sets focus to it before it's // activated) wxLogTrace(wxT("focus"), wxT("wxTLW %p activated."), m_hWnd); wxWindow* const winFocus = FindFocus(); if ( winFocus == this || !IsDescendant(winFocus) ) DoRestoreLastFocus(); } else // deactivating { DoSaveLastFocus(); wxLogTrace(wxT("focus"), wxT("wxTLW %p deactivated, last focused: %p."), m_hWnd, m_winLastFocused ? GetHwndOf(m_winLastFocused) : NULL); event.Skip(); } }
WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { WXLRESULT rc = 0; bool processed = false; switch ( message ) { #if defined(__SMARTPHONE__) || defined(__POCKETPC__) case WM_ACTIVATE: { SHACTIVATEINFO* info = (SHACTIVATEINFO*) m_activateInfo; if (info) { DWORD flags = 0; if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) flags = SHA_INPUTDIALOG; SHHandleWMActivate(GetHwnd(), wParam, lParam, info, flags); } // This implicitly sends a wxEVT_ACTIVATE_APP event if (wxTheApp) wxTheApp->SetActive(wParam != 0, FindFocus()); break; } case WM_HIBERNATE: { if (wxTheApp) { wxActivateEvent event(wxEVT_HIBERNATE, true, wxID_ANY); event.SetEventObject(wxTheApp); processed = wxTheApp->ProcessEvent(event); } break; } #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: // surprisingly, DefWindowProc() doesn't do it automatically // and so we need to it ourselves. 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 ( !processed ) rc = wxTopLevelWindowBase::MSWWindowProc(message, wParam, lParam); return rc; }
WXLRESULT wxTopLevelWindowMSW::MSWWindowProc(WXUINT message, WXWPARAM wParam, WXLPARAM lParam) { WXLRESULT rc = 0; bool processed = false; switch ( message ) { 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: // surprisingly, DefWindowProc() doesn't do it automatically // and so we need to it ourselves. 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 ( !processed ) rc = wxTopLevelWindowBase::MSWWindowProc(message, wParam, lParam); return rc; }