Solved

Preventing WsaAsyncSelect Window tealing focus

Posted on 2004-08-12
3
391 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
Comment Utility
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
Comment Utility

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
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
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 demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now