Results 1 to 7 of 7

Thread: [vb2010] Get from when a window is in foreground with precision of a millisecond

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    428

    [vb2010] Get from when a window is in foreground with precision of a millisecond

    I need to know from when the last desktop window is in foreground on the desktop, with the best possible precision and without to freeze the program.

    If I insert a code like this in a timer:

    Code:
            Static OldHwnd As IntPtr
    
            TopHwnd = NativeMethods.GetForegroundWindow()
    
            If TopHwnd <> OldHwnd Then
                   NewTime = Now    'NewTime is a DateTime variable
            End If
    
            OldHwnd = TopHwnd
    I have not a good precision (about 15-20 milliseconds minimum working interval). Something else?

  2. #2
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: [vb2010] Get from when a window is in foreground with precision of a millisecond

    Take a look at the precision of using DateTime.Now:

    http://blogs.msdn.com/b/ericlippert/...-datetime.aspx

    So you might want to look at somehow using stopwatch.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    428

    Re: [vb2010] Get from when a window is in foreground with precision of a millisecond

    Ty for the info... but remains the problem of the Timer.Interval

  4. #4
    PowerPoster SJWhiteley's Avatar
    Join Date
    Feb 2009
    Location
    South of the Mason-Dixon Line
    Posts
    2,256

    Re: [vb2010] Get from when a window is in foreground with precision of a millisecond

    What, exactly, are you trying to do which requires such precision?
    "Ok, my response to that is pending a Google search" - Bucky Katt.
    "There are two types of people in the world: Those who can extrapolate from incomplete data sets." - Unk.
    "Before you can 'think outside the box' you need to understand where the box is."

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    428

    Re: [vb2010] Get from when a window is in foreground with precision of a millisecond

    Hooking the keyboard I must handle (e.handle=true) some keys if certain windows go into foreground, or, if the windows popoup exactly when I press a key, I send the keys to those windows, with bad results.

    I can't find a API like "GetWindowLastActivationTime(Hwnd as IntPtr)", so I need to check continuosly what window is in the foreground. 15 milliseconds are too much: with this interval sometimes I send a key to the popup windows.
    Last edited by phil2000; Apr 20th, 2015 at 05:32 PM.

  6. #6
    Frenzied Member
    Join Date
    Oct 2012
    Location
    Tampa, FL
    Posts
    1,187

    Re: [vb2010] Get from when a window is in foreground with precision of a millisecond

    Quote Originally Posted by phil2000 View Post
    Ty for the info... but remains the problem of the Timer.Interval
    What do you mean? You cant use a timer to measure that reliably. You should use a stopwatch rather than a timer per that article. You care only about measuring time elapsed from point A to point B correct?

    StopWatch Class

  7. #7

    Thread Starter
    Hyperactive Member
    Join Date
    May 2009
    Posts
    428

    Re: [vb2010] Get from when a window is in foreground with precision of a millisecond

    Quote Originally Posted by jayinthe813 View Post
    ..... You care only about measuring time elapsed from point A to point B correct?
    Nope. AFTER I have to misure the time elapsed (StopWatch is OK) but BEFORE (and this is the problem) I have to get with extreme precision the time when a Window jumps in foreground.

    Once I have the righ time, with StopWatch I can get the time elapsed from that moment... but the problem is to get te initial time. The minimum Timer.Interval is about 15 ms... too much.

    I have to find the EXACT time in which a table jumps in foreground, like already said, something as a API like "GetLastActivationTime(Hwnd as IntPtr)" (that unlukely don't exists......)

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