If your application needs to know if the current form has focus (either within you application or System-wide) you can use this snippet to decide...
if AmIOnTop(Me) then
...
end if
The following are placed in a Module...
' Returns Handle of OS-Level Window that has the focus
Declare Function GetForegroundWindow Lib "user32" () As Long
Public Function AmIOnTop(pForm as form) as boolean
Dim lngMyWindowHandle as Long
Dim lngTopWindowHandle as Long
' Get Handle of Calling Window
lngMyWindowHandle = pform.hWnd
' Get handle of Operating System's Focused Window
lngTopWindowHandle = GetForegroundWindow()
' If same, the IAmOnTop, else not
AmIOnTop = (lngTopWindowHandle = lngMyWindowHandle)
Exit Function
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.