Solved

Preventing WsaAsyncSelect Window tealing focus

Posted on 2004-08-12
3
398 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
  • 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

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MSDN Subscription - Azure and NFP's 3 75
Clicking on Print  property changes format of printing result 1 82
Example of WebAPI 7 33
Is COM supported from Apache 1 63
In this article, I will show how to use the Ribbon IDs Tool Window to assign the built-in Office icons to a ribbon button.  This tool will help us to find the OfficeImageId that corresponds to our desired built-in Office icon. The tool is part of…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
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…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

792 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