Solved

LostFocus event for borderless form

Posted on 2004-10-07
4
287 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
vba find the last empty column 10 89
VBA saving file message display 5 56
MS Access - Capture pressed key onclick 4 28
VB6 Compile Compatibility Issue 4 90
Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

863 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

20 Experts available now in Live!

Get 1:1 Help Now