Results 1 to 2 of 2

Thread: Tell if my form is on top

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 1999
    Location
    Phoenix, az
    Posts
    1,517
    Hi,

    I would like to see if my form
    is the top in the Zorder of the
    other programs in the computer.

    Can someone give me the code to
    do that?

    (Not Forms in MY program.. Other
    Programs.. )

  2. #2
    Guest
    Use the GetForegroundWindow api function.

    Code:
    Declare Function GetForegroundWindow Lib "user32.dll" () As Long
    
    Private Sub Command1_Click()
    Dim hforewnd As Long
    Dim handl As Long
        handl = Me.hWnd
        hforewnd = GetForegroundWindow()
        If handl = hforewnd Then
          MsgBox "Your program is on top of all others!"
        Else
         MsgBox "Your program is not on top of all others!"
        End If
    End Sub
    Of course, your program will always be on top because it has the focus, so you can use the GetAsyncKeyState api function to detect key presses.

    Code:
    Private Declare Function GetAsyncKeyState _
    Lib "user32" (ByVal vKey As Long) As Integer
    
    Private Sub Form_Load()
    Timer1.Interval = 100
    End Sub
    
    Private Sub Timer1_Timer()
    'Detect Tab key
    If GetAsyncKeyState(vbKeyTab) Then
        Command1_Click
    End If
    End Sub

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width