McMillan's Visual Basic Code - Code Snippets - Test whether your Application is active
Code Snippets
Home



Test whether your Application is active

This snippet will allow you to test whether your application is the active application

Option Explicit

Private Declare Function GetCurrentThreadId Lib "kernel32" () As Long
Private Declare Function GetForegroundWindow Lib "user32" () As Long
Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal _
hWnd As Long, lpdwProcessId As Long) As Long

Public Function AppIsActive() As Boolean

   Dim r As Long
   Dim hWnd As Long

   Dim ProcessID As Long
   Dim CurrentThreadID As Long
   Dim ActiveThreadID As Long

   hWnd = GetForegroundWindow
   ActiveThreadID = GetWindowThreadProcessId(hWnd, ProcessID)

   CurrentThreadID = GetCurrentThreadId

   AppIsActive = CurrentThreadID = ActiveThreadID

End Function

© Copyright Notice

Unless otherwise stated, the code on this site is Copyright to Andrew McMillan. You may use this code in your projects (both commercial and non-commercial) but you are not permitted to republish this code in any form without the Author's prior consent.

The code on this site is supplied "as is" and no claims are made as to its soundness. The Author claims no responsibility for or liability from use of said source code.


Home