|
-
January 26th, 2010, 12:23 AM
#1
app auto close
greeting,
how EXE can close by itself , if no activity on a certain period of time.
thnks
cyrus
-
January 26th, 2010, 12:58 AM
#2
Re: app auto close
To close it, obviously use Unload Me for each form, but to test for inactivity, that is where the fun comes in.
You must have a Timer on your form, testing a Boolean variable. Then, for each control on your form, you have to set that variable to True / False whenever any event happens. Here is a very basic example :
Code:
Option Explicit
Private blnActive As Boolean
Private Sub Command1_Click()
blnActive = True
End Sub
Private Sub Command1_KeyDown(KeyCode As Integer, Shift As Integer)
blnActive = True
End Sub
Private Sub Command1_KeyPress(KeyAscii As Integer)
blnActive = True
End Sub
Private Sub Command1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Command1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Form_Click()
blnActive = True
End Sub
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
blnActive = True
End Sub
Private Sub Form_KeyPress(KeyAscii As Integer)
blnActive = True
End Sub
Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Text1_Change()
blnActive = True
End Sub
Private Sub Text1_Click()
blnActive = True
End Sub
Private Sub Text1_KeyDown(KeyCode As Integer, Shift As Integer)
blnActive = True
End Sub
Private Sub Text1_KeyPress(KeyAscii As Integer)
blnActive = True
End Sub
Private Sub Text1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Text1_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
blnActive = True
End Sub
Private Sub Timer1_Timer()
Static intCount As Integer
If Not blnActive Then
intCount = intCount + 1
Label1.Caption = intCount
If intCount >= 20 Then
Unload Me
End If
Else
intCount = 0
Label1.Caption = intCount
End If
End Sub
It may not be 100% correct, but it should give you a good start.
-
January 26th, 2010, 02:37 AM
#3
Re: app auto close
Little by little one goes far
Keep moving.......!
Nothing is impossible !
-
January 26th, 2010, 05:56 AM
#4
Re: app auto close
Hello,
Would it really be a bad idea using the GetInputState function of user32 ?
It :
determines whether there are mouse-button or keyboard messages in the calling thread's message queue.
It needs then a timer and a static variable (to retrieve the time T1 each time there is an activity). You decide to close if The Time T2 - Time T1 >= accepted delay.
You would that way save to attach code to every control ...
-
January 26th, 2010, 09:35 AM
#5
Re: app auto close
Not bad, but seems tricky, to me.
You'd have to interrogate GetInputState() very often because messages are consumed very fast, so you might miss the time, them being in the message queue, thinking there was no activity and closing.
I suppose you might have to subclass the window, so as every message is running over your own WindowProc where you can always reset the timeout-counter.
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
|