Solved

idle time in vb

Posted on 1999-01-29
4
457 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
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

856 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