Results 1 to 3 of 3

Thread: Inactivity shut down

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Oct 2001
    Posts
    79

    Inactivity shut down

    Why want my VB6 to shut down when the user has been inactive for a length of time, say 30 min. How can I do it?

  2. #2
    jim mcnamara
    Guest
    All 'activity' to an app comes to it via messages from the OS.
    If no messages are received then there is no activity.
    Trap the messages going to the app by subclassing.

    This example uses a Timer control which has limited duration.
    Check up on SetTimer and KillTimer api's for longer times.

    try something like this in a .BAS module

    Code:
    Public Declare Function SetWindowLong& Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long)
    Public Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hwnd As Long, ByVal msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
    Public Const GWL_WNDPROC = (-4)
    Public Const WM_PASTE = &H302
    Public WinProcOld As Long
    
    Public Function WinProc(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
        ' we got here because somebody created "activity"
        ResetTimer       
        WinProc = CallWindowProc(WinProcOld&, hwnd&, wMsg&, wParam&, lParam&)
    End Function
    
    Sub SubClassWnd(hwnd As Long)
        WinProcOld& = SetWindowLong(hwnd, GWL_WNDPROC, AddressOf WinProc)
    End Sub
    
    Sub UnSubclassWnd(hwnd As Long)
        SetWindowLong hwnd, GWL_WNDPROC, WinProcOld&
    End Sub
    Sub ResetTimer  ' restart the timer
        Form1!Timer1.Enabled = False
        Form1!Timer1.Timer = 30000
        Form1!Timer1.Timer.Enabled = True
    End Sub
    TO start the process in your Form load event add as the last line in the sub:

    Code:
    Call SubClassWnd(hwnd)
    In the timer event:
    Code:
    ' we got here because the timer expired
      Unload Me
      End
    In form unload:
    Code:
      '  do this or risk crashing the PC! 
      Call UnSubCLassWnd(hwnd)

  3. #3
    The picture isn't missing BuggyProgrammer's Avatar
    Join Date
    Oct 2000
    Location
    Vancouver, Canada
    Posts
    5,217
    subclassing in VB only works with its own process. you cannot subclass otehr windows outside your app.
    Remember, if someone's post was not helpful, you can always rate their post negatively .

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width