AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

How can I find out whether my VB-application has the focus?
Open a new form and add an timer and an label to it.
Set the timer's interval to 200 (Your application will look
5 times a second if it has got the focus)

Then use the following code in your form:


Option Explicit
Private Declare Function GetActiveWindow Lib "user32" () As Long
Private Sub Timer1_Timer()
    If GetActiveWindow <> 0 Then
        Label1.Caption = "I have the focus" 'if GetActiveWindow is non-zero
    Else
        Label1.Caption = "Another program has the focus" 'if GetActiveWindow is zero
    End If
End Sub

Tip submitted by Uwe Will

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/