From 9650c5b55bb2cf2a6a57a120b56cb9c8206b2aff Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 24 Oct 2014 13:45:41 +0000 Subject: [PATCH] Avoid spurious error messages for WM_MDISETMENU under Windows XP. WM_MDISETMENU handler doesn't seem to reset the last error under Windows XP and this could result in spurious debug error messages when setting the initial menu in which case NULL is returned to indicate that there was no previous menu, but this doesn't indicate that an error occurred. Explicitly reset the last error to ERROR_SUCCESS ourselves before using WM_MDISETMENU to ensure that the last error can only be set after its return if it was really done by the code handling it, i.e. if an error really happened. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@78056 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/mdi.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/msw/mdi.cpp b/src/msw/mdi.cpp index e2e47e8577..725d47ab49 100644 --- a/src/msw/mdi.cpp +++ b/src/msw/mdi.cpp @@ -1442,13 +1442,18 @@ void MDISetMenu(wxWindow *win, HMENU hmenuFrame, HMENU hmenuWindow) { if ( hmenuFrame || hmenuWindow ) { + // Under XP, the last error seems to be not reset by this function, so + // ensure we don't report spurious errors below when setting the menu + // initially. + ::SetLastError(ERROR_SUCCESS); + if ( !::SendMessage(GetWinHwnd(win), WM_MDISETMENU, (WPARAM)hmenuFrame, (LPARAM)hmenuWindow) ) { - DWORD err = ::GetLastError(); - if ( err ) + const DWORD err = ::GetLastError(); + if ( err != ERROR_SUCCESS ) { wxLogApiError(wxT("SendMessage(WM_MDISETMENU)"), err); }