Link to home
Start Free TrialLog in
Avatar of x_terminat_or_3
x_terminat_or_3

asked on

LostFocus event for borderless form

Hi all

I'm making an app that displays a topmost borderless form.  I want to hide the form if it loses focus, but since it's borderless, it seems no LostFoucs, DeActivate events are fired.  Also, I tried the subclassing with GetWindowProc, and the message isn't fired there as well.

How to detect lostfocus for borderless forms?


With kind regards



Ramses (ps, pts will be raised to max if I get a working reply within 3hrs)
Avatar of fds_fatboy
fds_fatboy

It's nasty but how about this:

Place a timer on your window
In declarations:
  Private Declare Function GetForegroundWindow Lib "user32" () As Long

Then for your timer...
Private Sub Timer1_Timer()
   Static blnGotFocus as Boolean
   Timer1.Enabled = False

    if not blnGotFocus = GetForegroundWindow = Me.hWnd Then
        blnGotFocus = Not blnGotFocus
        if blnGotFocus Then
            cls
            print "I've got focus"
        Else
            cls
            print "I've got focus"
        End If
    End If

    Timer1.Enabled = True
End Sub
Ignore that last comment from me. I should have tested it first.

Never mind - back to the drawing board...
ASKER CERTIFIED SOLUTION
Avatar of fds_fatboy
fds_fatboy

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of x_terminat_or_3

ASKER

Thanks.  Stupid me for not figuring out myself!