[SDL] SDL app keeping focus

Lilith Calbridge lilith at dcccd.edu
Sun Jul 22 08:44:32 PDT 2007



>>> On 7/22/2007 at 1:57 AM, Jason <jesus_freak at picknowl.com.au>
wrote:
> Lilith Calbridge <lilith <at> dcccd.edu> writes:
> 
>> 
>> Without my docs at hand I'm just guessing.  Is there an event that
>> detects loss of focus?  If so, is there a means to regain the
focus?
>> 
> 
> The only loss-of-focus message I'm aware of under Windows is
WM_KILLFOCUS, 
> which
> a program can choose to handle. If not, it doesn't get it in the
event 
> queue.
> 
> This message occurs when a program is about to lose keyboard focus,
which
> typically means the window which is active is about to become
inactive, and
> another window will become the active one. But this isn't necessarily
the 
> case
> (though I can't think of any examples off hand for which it isn't
true).
> 
> The only way to get it back is this call (straight out of the VC
docs):
> HWND SetFocus(
>   HWND hWnd   // handle to window to receive focus
> );
> 
> If you are handling this message for your own window, then probably
the best 
> way
> to do it is to have a handler for WM_KILLFOCUS, which internally has
a 
> little
> bit of a delay and then calls SetFocus back onto the main window of
your 
> app.
> 
> IMHO, a background app grabbing the focus and then not giving back up
again
> within a few moments is rather scary. What's the point of a
background app
> getting keyboard access anyway - it seems rather pointless. Whatever
work 
> that
> app is doing should be done in a windowless worker thread - it does
what it
> needs to without interfering with what the user is doing.

The things that pop up on me seem to be mostly system utility like
"Your Windows OS needs a security update" and utilities that feel they
need to tell you that something is complete.  Apparently they seem to
feel that what they have to say is important enough to interrupt what
you're doing.

Another thing that has cost me focus is that I have a dual monitor
system so it's fairly easy for me to accidentally move the cursor to the
other window unintentionally.

-- 
Lilith


More information about the SDL mailing list