Solved

Preventing WsaAsyncSelect Window tealing focus

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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
error email attachment VB2010 5 58
Messagebox for a Web Site Application 4 88
Microsoft C++ code failing in executable that worked 9 144
What .NET website keeps me current? 9 80
This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
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…

738 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