Solved

idle time in vb

Posted on 1999-01-29
4
449 Views
Last Modified: 2012-05-04
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
Comment
Question by:bkunnath
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Tommy Hui
Comment Utility
Is this from within the same program, or is this from another program?
0
 
LVL 1

Expert Comment

by:rayford
Comment Utility
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
 
LVL 2

Accepted Solution

by:
VBDesigns earned 200 total points
Comment Utility
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
 
LVL 2

Expert Comment

by:VBDesigns
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now