Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

idle time in vb

Posted on 1999-01-29
4
Medium Priority
?
467 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 400 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…
Suggested Courses

719 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