Braun
Ich habe hierzu einmal ein kleines Beispielprojekt erstellt.
Form1
mit Timer1-Control, sevCommand3-Schaltfläche (Style WinXP und ButtonType "OK") und folgendem Code:
Option Explicit
Dim nCount As Long
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
' Zähler erhöhen und in Caption der Form anzeigen
nCount = nCount + 1
Me.Caption = CStr(nCount)
' Form2 modal öffnen
Load Form2
Form2.Show vbModal
Timer1.Enabled = True
End Sub Form2
mit Timer1-Control, sevTextBox (Format=rsDate und ShowButton=True), sevCommand-Schaltfläche (Style = WinXP und ButtonType=Close) und folgendem Code:
Option Explicit
' Benötigte API-Deklarationen
Private Declare Function SetCursorPos Lib "user32" ( _
ByVal x As Long, _
ByVal y As Long) As Long
Private Declare Function GetWindowRect Lib "user32" ( _
ByVal hwnd As Long, _
lpRect As RECT) As Long
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Private Declare Sub mouse_event Lib "user32" _
( _
ByVal dwFlags As Long, _
ByVal dx As Long, _
ByVal dy As Long, _
ByVal cButtons As Long, _
ByVal dwExtraInfo As Long)
Private Const MOUSE_LEFT = 0
Private Const MOUSEEVENTF_LEFTDOWN = &H2
Private Const MOUSEEVENTF_LEFTUP = &H4
' benötigte API-Deklaration
Private Declare Function WaitForSingleObject Lib "kernel32" ( _
ByVal hHandle As Long, _
ByVal dwMilliseconds As Long) As Long
' Ewartet wird die Zeitangabe in Millisekunden!
' z.B. 1000 für 1 Sekunde
Private Function Wait(ByVal mSek As Long)
WaitForSingleObject -1, mSek
End Function
Private Sub Command1_Click()
Unload Me
End Sub
Private Sub Form_Load()
Timer1.Interval = 250
Timer1.Enabled = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
' und Maus wieder wegbewegen
Dim R As RECT
GetWindowRect Form1.hwnd, R
SetCursorPos R.Left + 100, R.Top + 50
End Sub
Private Sub Timer1_Timer()
Timer1.Enabled = False
' Fokus in TextBox setzen
sevText1.SetFocus
' Maus auf CommandButton positionieren
Dim R As RECT
GetWindowRect Command1.hwnd, R
SetCursorPos R.Left + 25, R.Top + 10
DoEvents
Wait 200
' Mausklick simulieren
Call mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
DoEvents
' kurz warten
Wait 500
Call mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
End Sub Bevor ich das Beispielprojekt gestartet habe, habe ich einen Screenshot der Speicher- und Prozessor-Auslastung erstellt (siehe Anlage Bild1)
Jetzt habe ich das Beispielprojekt eine komplette Stunde lang laufen lassen. Die Form2 wurde hierbei mehr als 2.000 mal aufgerufen und wieder geschlossen.
Anschließend habe ich wieder einen Screenshot der Speicher- und Prozessor-Auslastung erstellt (siehe Anlage Bild2)
Wie Du unschwer erkennen kannst, hat sich hier so gut wie nichts verändert. Es kam zu keinerlei Probleme!
_________________________
Professionelle Entwicklerkomponenten
www.tools4vb.de |