'SetFocus' failed with error 0x00000057 (the parameter is in Topic is solved

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

'SetFocus' failed with error 0x00000057 (the parameter is in

Post by Nelson Joseph »

Dear All,
Whenever I click the application on the taskbar to restore the window (after minimizing), the following error occurs:

Code: Select all

'SetFocus' failed with error 0x00000057 (the parameter is incorrect.).
I am using Visual Studio 2008, wxWidgets 2.8.11

Any suggestion would be helpful. Thanks in advance.
Last edited by Nelson Joseph on Wed Aug 24, 2011 8:04 am, edited 1 time in total.
Regards,
Nelson Joseph
DavidHart
Site Admin
Site Admin
Posts: 4254
Joined: Thu Jan 12, 2006 6:23 pm
Location: IoW, UK

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by DavidHart »

Hi,

You'll need to post the relevant code e.g. how you get to the function that contains SetFocus(), and the function itself; and the call-stack that you get when you run the code in a debugger.

Without that info, my guess is that wxEvtHandler::Connect is involved, and it is called with the wrong eventSink parameter. But that is just a guess...

Regards,

David
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by Nelson Joseph »

The call stack is:

Code: Select all

>	MySampleApp.exe!wxWindow::SetFocus()  Line 643	C++
 	MySampleApp.exe!wxWindowBase::SetFocusFromKbd()  Line 546 + 0x17 bytes	C++
 	MySampleApp.exe!wxWindow::SetFocusFromKbd()  Line 665	C++
 	MySampleApp.exe!wxSetFocusToChild(wxWindow * win=0x00a120a8, wxWindow * * childLastFocused=0x00a12220)  Line 673	C++
 	MySampleApp.exe!wxTopLevelWindowMSW::OnActivate(wxActivateEvent & event={...})  Line 1137 + 0x13 bytes	C++
 	MySampleApp.exe!wxAppConsole::HandleEvent(wxEvtHandler * handler=0x00a120a8, void (wxEvent &)* func=0x0144257c, wxEvent & event={...})  Line 323	C++
 	MySampleApp.exe!wxEvtHandler::ProcessEventIfMatches(const wxEventTableEntryBase & entry={...}, wxEvtHandler * handler=0x00a120a8, wxEvent & event={...})  Line 1241	C++
 	MySampleApp.exe!wxEventHashTable::HandleEvent(wxEvent & event={...}, wxEvtHandler * self=0x00a120a8)  Line 907 + 0x1c bytes	C++
 	MySampleApp.exe!wxEvtHandler::ProcessEvent(wxEvent & event={...})  Line 1301 + 0x1c bytes	C++
 	MySampleApp.exe!wxWindow::HandleActivate(int state=1, bool __formal=true, bool __formal=true)  Line 3883 + 0x1c bytes	C++
 	MySampleApp.exe!wxWindow::MSWWindowProc(unsigned int message=6, unsigned int wParam=2097153, long lParam=0)  Line 2722 + 0x21 bytes	C++
 	MySampleApp.exe!wxTopLevelWindowMSW::MSWWindowProc(unsigned int message=6, unsigned int wParam=2097153, long lParam=0)  Line 372 + 0x14 bytes	C++
 	MySampleApp.exe!wxFrame::MSWWindowProc(unsigned int message=6, unsigned int wParam=2097153, long lParam=0)  Line 1096 + 0x14 bytes	C++
 	MySampleApp.exe!wxWndProc(HWND__ * hWnd=0x000c0528, unsigned int message=6, unsigned int wParam=2097153, long lParam=0)  Line 2618 + 0x1c bytes	C++
 	user32.dll!770a62fa() 	
 	[Frames below may be incorrect and/or missing, no symbols loaded for user32.dll]	
 	user32.dll!770a6d3a() 	
 	user32.dll!770a6ce9() 	
 	user32.dll!770a6de8() 	
 	user32.dll!770a6e44() 	
 	ntdll.dll!77e4011a() 	
 	user32.dll!770a78d7() 	
 	user32.dll!770a7c1d() 	
 	MySampleApp.exe!GetMessage(tagMSG * lpMsg=0x0017f5fc, HWND__ * hWnd=0x00000000, unsigned int wMsgFilterMin=0, unsigned int wMsgFilterMax=0)  Line 309	C++
 	MySampleApp.exe!wxEventLoop::Dispatch()  Line 225 + 0xf bytes	C++
 	MySampleApp.exe!wxEventLoopManual::Run()  Line 115 + 0xd bytes	C++
 	MySampleApp.exe!wxAppBase::MainLoop()  Line 312 + 0x15 bytes	C++
 	MySampleApp.exe!wxAppBase::OnRun()  Line 368	C++
 	MySampleApp.exe!wxEntryReal(int & argc=1, char * * argv=0x00a04df0)  Line 448 + 0x1b bytes	C++
 	MySampleApp.exe!wxEntry(int & argc=1, char * * argv=0x00a04df0)  Line 209 + 0xd bytes	C++
 	MySampleApp.exe!wxEntry(HINSTANCE__ * hInstance=0x01310000, HINSTANCE__ * __formal=0x00000000, HINSTANCE__ * __formal=0x00000000, int nCmdShow=1)  Line 386 + 0xd bytes	C++
 	MySampleApp.exe!WinMain(HINSTANCE__ * hInstance=0x01310000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x003b64a9, int nCmdShow=1)  Line 21 + 0x33 bytes	C++
 	MySampleApp.exe!__tmainCRTStartup()  Line 574 + 0x35 bytes	C
 	MySampleApp.exe!WinMainCRTStartup()  Line 399	C
 	kernel32.dll!76f9339a() 	
 	ntdll.dll!77e69ed2() 	
 	ntdll.dll!77e69ea5() 	
 	ig4icd32.dll!04480007() 	
Regards,
Nelson Joseph
Auria
Site Admin
Site Admin
Posts: 6695
Joined: Thu Sep 28, 2006 12:23 am
Contact:

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by Auria »

DavidHart wrote: You'll need to post the relevant code e.g. how you get to the function that contains SetFocus(), and the function itself
+1
"Keyboard not detected. Press F1 to continue"
-- Windows
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by briceandre »

Auria wrote:
DavidHart wrote: You'll need to post the relevant code e.g. how you get to the function that contains SetFocus(), and the function itself
+1
Well, reading the backtrace, I am not sure Nelson is connecting an event handler to the 'SetFocus' event. From what I see, the function that is triggered is the default wxWindow one.

Maybe you have a problem elsewhere in you code that corrupts some data and that the crash only occurs after.

How big is your application ? Is it envisageable to post its code here ?
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by Nelson Joseph »

Thanks briceandre, you are right. I am not calling SetFocus() function explicitly. But I am using Sash window. If I remove the Sash Window then it wont occur. Since the code is too long to post here. I can post the part of code which you need.

If I comment the following code, then it won't say any problem.

Code: Select all

m_pSashWindowLeft = new wxSashLayoutWindow( this, ID_SASH_LEFT,
		wxDefaultPosition, wxSize( size.GetWidth()/6,
		size.GetHeight() ), wxSW_3D | wxBORDER_DOUBLE | wxCLIP_CHILDREN ); 

	m_pSashWindowLeft->SetDefaultSize( wxSize( size.GetWidth()/6,
		size.GetHeight() ) );

	m_pSashWindowLeft->SetOrientation( wxLAYOUT_VERTICAL );
	m_pSashWindowLeft->SetAlignment( wxLAYOUT_LEFT );
	m_pSashWindowLeft->SetSashVisible( wxSASH_RIGHT, true );

	m_pSashWindowRight = new wxSashLayoutWindow( this, ID_SASH_RIGHT,
		wxDefaultPosition );

	m_pSashWindowRight->SetOrientation( wxLAYOUT_VERTICAL );
	m_pSashWindowRight->SetAlignment( wxLAYOUT_LEFT );
	m_pSashWindowRight->SetSashVisible( wxSASH_RIGHT, true );

	m_layoutAlgorithm = new wxLayoutAlgorithm();
P.S. wxWidgets's sample code of SashWindow has this problem.
Regards,
Nelson Joseph
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by briceandre »

P.S. wxWidgets's sample code of SashWindow has this problem.
Do you mean you have the same crash with the sample application ? If yes, then you should probably open a ticket for a bug.

Note that what surprises me is that your configuration does not seem to be an exotic one (wx2.8.11, MSVC 2008). So, I would be surprised you find a bug in a such common control of the stable version of wxWidgets. Are you sure your build process of the wx libs did not fail with corrupted generated libs ?
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by Nelson Joseph »

Thanks for your quick reply.

The sample/sashtest is not crashing but it shows the following message in output window while we are trying to restore the window after minimize it. Since I also use sash window in my application the same error message appears.

16:14:42: ..\..\src\msw\window.cpp(643): 'SetFocus' failed with error 0x00000057 (the parameter is incorrect.).

while building my application it doesn't show any corrupted libs.

Could you give any suggestion?
Thanks in advance.
Regards,
Nelson Joseph
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by briceandre »

I compiled the sash sample with wx2.8.11, MSVC 2010 (I do not have MSVC2008 installed on my computer), ANSI, static, mutllib, debug build. There is no message about a set focus problem. I run this code on Windows XP. If you are interested, I can try with MSVC 2008 on a Win7, same build option, but I will do this this afternoon, when I will have access to a computer with this setup.

If I was you, I would rebuild the whole wxLib from a fresh install, check the sample and, if you still have the error with sample, I would fill a ticket to wx tracker.
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by Nelson Joseph »

Thank you for your quick reply.

Do you think this message occurs because of compiler/library settings?
I have attached a screen-shot. Please find attached document. It happens only on clicking in the taskbar button (minimizing/restoring)

Thanks.
Attachments
Sash Test Sample - Set Focus Problem
Sash Test Sample - Set Focus Problem
Regards,
Nelson Joseph
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by doublemax »

I think this message is harmless and can be ignored

The more interesting question is why this leads to a crash in your application and not in the sample.
Use the source, Luke!
Nelson Joseph
Experienced Solver
Experienced Solver
Posts: 65
Joined: Sun Oct 26, 2008 5:15 am
Location: Chennai, India
Contact:

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by Nelson Joseph »

doublemax,

My Application does not crash. It just throws this message whenever I click the taskbar button ( for minimizing/restoring )
My task is to rectify it. It seems that it happens in Windows 7 and MSVS 2008
Regards,
Nelson Joseph
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by briceandre »

I can reproduce this problem on my Win7 computer, with MSVC 2008 compiler. I nearly 100% sure it was not present on WinXp with MSCV 2010 compiler. I can check tomorrow if the problem is caused by Win7 or by the compiler version.
I will investigate furthermore to see if I can find the origin of the problem.
briceandre
Ultimate wxWidgets Guru
Ultimate wxWidgets Guru
Posts: 672
Joined: Tue Aug 31, 2010 6:22 am
Location: Belgium

Re: 'SetFocus' failed with error 0x00000057 (the parameter i

Post by briceandre »

Well, I investigated this problem furthermore and it does not seem to be linked to sashWindow. I can generate this problem with apps that do not have sashWindows.

From what I saw, the problem occurs when wxWidgets tries to restore keyboard focus to the last window that had the focus. In this case, the Windows function 'SetFocus' refuses the SetFocus function, but does not really gives a reason for why it was refused (it just says that the parameter is incorect, but the only parameter is a HWND and this parameter is the proper HWND of the last window that had focus in my case).

The result is that the main frame gets the focus, but this focus is not given back to the last child window of the frame that had the focus.

I will check tomorrow under WinXP what is exactly the behaviour in this case.

I think you can file a bug for this, but I don't think it's really a big issue and would suggest you to do like DoubleMax told you : just don't bother about this message. Note that this message will not be displayed in non-debug mode.
bzcdr
In need of some credit
In need of some credit
Posts: 2
Joined: Tue Sep 01, 2015 6:40 am

Re: 'SetFocus' failed with error 0x00000057 (the parameter is in

Post by bzcdr »

I see this with wxWidgets 3.0.2 on Windows 7, when minimizing with the task bar button. This happens because the WM_SIZE and WM_ACTIVATE messages come in different order depending on whether minimize is done with task bar or the minimize button in title bar. wxwidgets sets a member variable wxTopLevelWindowMSW::m_iconized during WM_SIZE, so if WM_ACTIVATE happens first, the value will be out of sync with the current state. It so happens that the WM_ACTIVATE event has a flag whether or not window is minimized. This flag could be put into the wxActivateEvent object when it is constructed and then tested in wxTopLevelWindowMSW which currently only tests the m_iconized flag:

Code: Select all

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.GetMinimized())  //<-- What comes after || is new code
        {
This new GetMinimized() accessor could be made private friend, available only to wxTopLevelWindowMSW to minimize exposure.
Post Reply