Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Preventing WsaAsyncSelect Window tealing focus

Posted on 2004-08-12
3
Medium Priority
?
406 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 250 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: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone 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

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…
Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
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 is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

730 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