Solved

idle time in vb

Posted on 1999-01-29
4
460 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 15

Expert Comment

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

Expert Comment

by:rayford
ID: 1471206
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
ID: 1471207
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
ID: 1471208
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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
VB6 Compile Compatibility Issue 4 131
vb6 connector to SQL Server 2 42
Access Object Property from VBA Module in Excel 2010 2 45
Collapse and expand table in Word 2010 2 161
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

751 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