Solved

LostFocus event for borderless form

Posted on 2004-10-07
4
286 Views
Last Modified: 2006-11-17
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)
0
Comment
Question by:x_terminat_or_3
  • 3
4 Comments
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12247879
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
0
 
LVL 10

Expert Comment

by:fds_fatboy
ID: 12247911
Ignore that last comment from me. I should have tested it first.

Never mind - back to the drawing board...
0
 
LVL 10

Accepted Solution

by:
fds_fatboy earned 500 total points
ID: 12247976
Here we go, try this - same as before but -
set your timer to something low and enable it

then

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 lost focus"
        End If
    End If

    Timer1.Enabled = True
End Sub
0
 
LVL 2

Author Comment

by:x_terminat_or_3
ID: 12248351
Thanks.  Stupid me for not figuring out myself!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

757 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

23 Experts available now in Live!

Get 1:1 Help Now