PC Review


Reply
Thread Tools Rate Thread

Application LostFocus?

 
 
=?Utf-8?B?QnJpYW4=?=
Guest
Posts: n/a
 
      9th Apr 2006
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.
 
Reply With Quote
 
 
 
 
=?Utf-8?B?QnJpYW4=?=
Guest
Posts: n/a
 
      9th Apr 2006
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.

 
Reply With Quote
 
=?Utf-8?B?QnJpYW4=?=
Guest
Posts: n/a
 
      9th Apr 2006
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.

 
Reply With Quote
 
John Nurick
Guest
Posts: n/a
 
      9th Apr 2006
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.

 
Reply With Quote
 
=?Utf-8?B?QnJpYW4=?=
Guest
Posts: n/a
 
      9th Apr 2006
Thanks. I'm sure that will work.

"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.
>
>

 
Reply With Quote
 
=?Utf-8?B?QnJpYW4=?=
Guest
Posts: n/a
 
      10th Apr 2006
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.
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ComboBox LostFocus Arne Garvander Microsoft Dot NET Framework Forms 2 22nd Apr 2008 02:08 PM
MER Lostfocus mark r Microsoft Access Form Coding 9 3rd Jan 2008 03:55 AM
lostfocus Boni Microsoft VB .NET 0 1st Aug 2005 01:50 PM
lostfocus Sam Microsoft VB .NET 1 7th Apr 2005 01:49 AM
LostFocus Elwin Microsoft Access Form Coding 3 11th Jul 2003 05:37 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 03:38 PM.