[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

LostFocus event for borderless form

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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

650 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