Solved

Preventing WsaAsyncSelect Window tealing focus

Posted on 2004-08-12
3
402 Views
Last Modified: 2013-12-03

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
0
Comment
Question by:apakian
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
adg080898 earned 125 total points
ID: 11789864
Make the hidden windows reject reciving focus, add the following case to the window proc of the invisible window(s):

case WM_ACTIVATE:
    if (lParam) {
        SetFocus((HWND)lParam);
    }
    return 0;

The WM_ACTIVATE message passes the window handle of the previous owner of focus in lParam. This change makes it "give back" focus upon activation.
0
 

Author Comment

by:apakian
ID: 11790081

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;
 }

 
0
 
LVL 8

Expert Comment

by:adg080898
ID: 11790533
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)wParam, NULL) == GetCurrentThreadId())
      SetFocus((HWND)wParam) // i.e it's in my thread, give it back to him.
   return 0;

0

Featured Post

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question