Thanks, John. It works, but there is something I don't understand here. I
used this:
Declare Function apiGetActiveWindow Lib "user32" Alias "GetActiveWindow" ()
As Long
Public Function GetActivehWnd()
Dim hwnd As Long
Dim hWndCurrent As Long
' Get the handle to the currently active window.
hwnd = apiGetActiveWindow()
hWndCurrent = hwnd
' Find the top window (which has no parent window).
While hwnd <> 0
hWndCurrent = hwnd
hwnd = apiGetParent(hwnd)
Wend
GetActivehWnd = hWndCurrent
End Function
For testing purposes, I ran it on a form timer (non-modal form) and updated
the status bar to show the value of GetActivehWnd(). This always returns a
non-zero number when the Access app containing this function has the focus
(regardless of which form/query/report in Access has the focus), but always
returns a zero when any other app (including another Access app) has the
focus.
While this does return sufficient information for my needs, I thought that
the API call would return a long integer that is different depending on which
app has the focus in Windows. Am I missing something fundamental here?
"John Nurick" wrote:
> I've never tried anything like this, but the logical approach would seem
> to be to use the GetActiveWindow or GetForegroundWindow API function to
> get the handle of the window the user is working in, and then compare
> this with Screen.ActiveWindow.hWnd (and/or the handle of the Access
> application window or Screen.AtiveReport.hWnd).
>
> On Sat, 8 Apr 2006 22:41:01 -0700, Brian
> <(E-Mail Removed)> wrote:
>
> >On second thought, I jumped the gun on answering my own question. The API
> >call tells me whether my app is minimized/maximized/restored, but not whether
> >it has the focus. If a user leaves the app maximized/restored but Alt-Tabs or
> >uses the Start button to open a different app, I still have the problem of
> >not knowing that the user is playing Solitaire instead of working.
> >
> >What I am trying to do is capture the time the app is actually in use (has
> >the focus) using the timer on a a particular form.
> >
> >"Brian" wrote:
> >
> >> Never mind. I found it in the MS KB - uses Access window handle via API call.
> >> Here's the MS article address:
> >>
> >> http://support.microsoft.com/?kbid=210118
> >>
> >> "Brian" wrote:
> >>
> >> > Is there a way to pause a form timer (or does some event fire) when an Access
> >> > app loses the focus (such as when a user minimizes the app he is supposed to
> >> > be using at work and instead goes out to browse the Internet...)
> >> >
> >> > This is different from a form losing the focus because when a user minimizes
> >> > Access, the current form retains the focus, so that event never fires.
>
> --
> John Nurick [Microsoft Access MVP]
>
> Please respond in the newgroup and not by email.
>
>