Solved

LostFocus event for borderless form

Posted on 2004-10-07
4
291 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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 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…

718 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