|
-
Oct 4th, 2000, 03:31 AM
#1
Thread Starter
Hyperactive Member
I want to write into my application a way to shut itself down (not the PC) if it hasn't been used for a set period of time, does anyone know how this can be done?
Thanks in advance for any help provided.
VB 6 Enterprise Edition SP4
ADO, SQL 7/2000, ASP and some JavaScript

>> Life goes on, but for how long? <<
If you can smile when things go wrong, you have someone in mind to blame
-
Oct 4th, 2000, 03:37 AM
#2
transcendental analytic
Code:
'In declarations
Private Declare Function ExitWindowsEx Lib "user32" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long
Enum exitmode
Shutdown = 0
Restart = 1
Suspend = 2
End Enum
'In code
Sub ExitWindows(how As exitmode)
Const EWX_LOGOFF = 0
Const EWX_SHUTDOWN = 1
Const EWX_REBOOT = 2
Const EWX_FORCE = 4
Select Case how
Case 0
t& = ExitWindowsEx(EWX_SHUTDOWN, 0)
Case 1
t& = ExitWindowsEx(EWX_REBOOT Or EXW_FORCE, 0)
Case 2
SetSystemPowerState 1, 1
End Select
End Sub
Well here's for the shut down part, but for checking any activity, i guess mouse movement is enough? You could use Getcursorpos and check if it has changed...
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Oct 4th, 2000, 03:43 AM
#3
Thread Starter
Hyperactive Member
Thanks but I've got that one and it shuts down the PC, which is not what I want. I just want to close my application.
Thanks in advance for any help provided.
VB 6 Enterprise Edition SP4
ADO, SQL 7/2000, ASP and some JavaScript

>> Life goes on, but for how long? <<
If you can smile when things go wrong, you have someone in mind to blame
-
Oct 4th, 2000, 06:02 AM
#4
PowerPoster
Here is a simple solution and the program will automatically terminal after 1hour:
Code:
Option Explicit
Private tCnt As Long
Private xForm As Form
Private Sub Form_Load()
Timer1.Interval = 60000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
If tCnt > 60 Then
For Each xForm In Forms
Unload Me
Next
End
Else
tCnt = tCnt + 1
End If
End Sub
-
Oct 4th, 2000, 06:11 AM
#5
Thread Starter
Hyperactive Member
Right, but won't this shut down even if someone is still using it. Is there not a way to check the last time the application was used????
Thanks in advance for any help provided.
VB 6 Enterprise Edition SP4
ADO, SQL 7/2000, ASP and some JavaScript

>> Life goes on, but for how long? <<
If you can smile when things go wrong, you have someone in mind to blame
-
Oct 4th, 2000, 07:16 AM
#6
Addicted Member
Hi, why don't you merge the two ideas together...
Make tCnt a Global scope then you can check for mouse positions changes, keyboard input or even form loads to reset the count in tCnt. This will make the application shut down after 1 hour of stand still... You can also change the delay but you surely already knew this one :-)
-
Oct 4th, 2000, 08:02 PM
#7
PowerPoster
Juz look like this
Code:
'Module file
Option Explicit
Global tCnt as Long
Public RESET_COUNTER ()
tCnt = 0
End Sub
'Form
Option Explicit
Private xForm As Form
Private Sub Form_Load()
Timer1.Interval = 60000
Timer1.Enabled = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RESET_COUNTER
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RESET_COUNTER
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RESET_COUNTER
End Sub
Private Sub Timer1_Timer()
If tCnt > 60 Then
For Each xForm In Forms
Unload Me
Next
End
Else
tCnt = tCnt + 1
End If
End Sub
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|