Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 476
  • Last Modified:

idle time in vb

How do you determine if the vb application is idle . Is there any api call which determines if the application is idle. So that given a amount of idle time. The application has to be shut off
0
bkunnath
Asked:
bkunnath
  • 2
1 Solution
 
Tommy HuiCommented:
Is this from within the same program, or is this from another program?
0
 
rayfordCommented:
I'm not aware of any API calls to track activity.  I've always done this manually.  If you aren't already you could simply use a Public countdown variable (lets say nAPP_IS_Vacant) for how many ticks you want it to countdown until it is determined nAPP_IS_vacant=0 and shut the app down.  

You would then simply have a global Timer function (not a form specific timer) such as that provided in the 8th revision of the 101 VB Tech tips for FEB.  This timer would decrement the counter but ALL FORMS should have key preview turned on and any CLICKS or KEYUPS would reset the counter to its starting point of nAPP_IS_Vacant = 6,000,000 or whatever you choose again.  

If you decide this is a valid answer let me know and I will provide a post of the Public systemwide Timer code for you as the Answer.  Form specific timers are not as useful as they have requirements such as that form has to be activated to activate the timer etc..  Global timer class module is far more versatile and ideal for this sort of application-wide use.
0
 
VBDesignsCommented:
The way I do it is to take control of the VB Message Handler (note that this code can be cleaned up a bit).  If PeekMessage = 0 then you are idling:

Public Function MainWindowProc() As Boolean
    ' This is the main window procedure for the game!  It's used
    ' in non-debug mode for speed issues!
   
    Dim tMsg As MSG
    Dim hWnd As Long
    Dim quitreceived As Boolean
    Dim bProcess As Boolean
   
    On Error GoTo ErrorMainWindowProc

    Do
        bProcess = True
       
        ' See if a message is waiting
        If PeekMessage(tMsg, 0, 0, 0, PM_REMOVE) = 0 Then
            ' Here, we are idle.
            ' Can call MDVIdle here.
            If gtGO.MDVInitialized Then
                MDVIdle
            End If
        Else
            ' Here, we have a message
            If tMsg.Message = WM_QUIT Then
                quitreceived = True
                ' disable ALT+SPACE system menu by
                ' ignoring WM_SYSKEYDOWN && VK_SPACE combo
                ' (can't do this by processing the message)
                'elseif (msg.message not (WM_SYSKEYDOWN or msg.wParam not VK_SPACE) then
            Else
                TranslateMessage tMsg
                DispatchMessage tMsg
            End If
        End If
    Loop While (Not quitreceived) And (Not gbExited)
   
    MainWindowProc = True

ErrorMainWindowProcResume:
    Exit Function

ErrorMainWindowProc:
    iwcharEMessage "Error '" + Err.Description + "' occurred in (" _
     + App.Title + ")modMainModule2:MainWindowProc!"
    Resume ErrorMainWindowProcResume
End Function

0
 
VBDesignsCommented:
I'm sorry -- I made a mistake in the way I explained the procedure.  I don't take 'control' of the VB Message Handler -- I just don't use it at all (I use my own) -- when my app starts, I enter the above handler, and when the app has been shut down, I exit it.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now