apakian
asked on
Preventing WsaAsyncSelect Window tealing focus
I create 3 windows in my app,,, the main display window, a second window for debug and a third for Winsock messages.
I have noticed that the winsock window steals focus away from my main window about 3-4 seconds into the program starting.
Is there a way to prevent this , as the winsock window is not visible, and it requiring me to click on the main window
first to get focus before i can type to it.
thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I thought it was a hidden window. Why would it receive focus? I just universally gave focus back since the hidden window never needs it.
Yes, I guess I should have said to hook WM_SETFOCUS.
BUT, I thought your hidden window and your "real" window were both "top level" windows, so I expected WM_ACTIVATE to work before it even bothered sending WM_SETFOCUS.
> if ( wparam is one of my windows )
Who cares if it is one of your windows, just give it back always, if it (wParam) is not NULL of course. What other window would it be? It will only obey setfocus to another window in your thread.
But if you want...
case WM_SETFOCUS:
if (GetWindowThreadProcessId( (HWND)wPar am, NULL) == GetCurrentThreadId())
SetFocus((HWND)wParam) // i.e it's in my thread, give it back to him.
return 0;
Yes, I guess I should have said to hook WM_SETFOCUS.
BUT, I thought your hidden window and your "real" window were both "top level" windows, so I expected WM_ACTIVATE to work before it even bothered sending WM_SETFOCUS.
> if ( wparam is one of my windows )
Who cares if it is one of your windows, just give it back always, if it (wParam) is not NULL of course. What other window would it be? It will only obey setfocus to another window in your thread.
But if you want...
case WM_SETFOCUS:
if (GetWindowThreadProcessId(
SetFocus((HWND)wParam) // i.e it's in my thread, give it back to him.
return 0;
ASKER
i will give you the points, but can you see what the difference would be with the following,
which better, ?
inside wsaproc
{
if(msg==WM_SETFOCUS)
{
if ( wparam is one of my windows )
{
SetFocus(wparm) // i.e if the window that is giving up focus is my main window, then just give it back to him.
}
return 0;
}