?
Solved

LostFocus event for borderless form

Posted on 2004-10-07
4
Medium Priority
?
292 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 2000 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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

762 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