AW: Text sekündlich bei Loop anzeigen lassen
11.03.2022 23:46:07
volti
Hallo Nico,
hier eine Idee, wie Du mit einer MsgBox einen CountDown erzeugen kannst.
Code:
Option Explicit
Private Declare PtrSafe Function FindWindowA Lib "user32" ( _
ByVal lpClassName As String, ByVal lpWindowName As String) As LongPtr
Private Declare PtrSafe Function KillTimer Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr) As Long
Private Declare PtrSafe Function SetTimer Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal nIDEvent As LongPtr, _
ByVal uElapse As Long, ByVal lpTimerFunc As LongPtr) As LongPtr
Private Declare PtrSafe Function MessageBoxA Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal lpText As String, ByVal lpCaption As String, _
ByVal wType As Long) As Long
Private Declare PtrSafe Function SetDlgItemTextA Lib "user32" ( _
ByVal hDlg As LongPtr, ByVal nIDDlgItem As Long, ByVal lpString As String) As Long
Private Declare PtrSafe Function GetDlgItemTextA Lib "user32" ( _
ByVal hDlg As LongPtr, ByVal nIDDlgItem As Long, _
ByVal lpString As String, ByVal nMaxCount As Long) As Long
Private Declare PtrSafe Function PostMessageA Lib "user32" ( _
ByVal hWnd As LongPtr, ByVal wMsg As Long, _
ByVal wParam As LongPtr, ByVal lParam As LongPtr) As Long
Private Const WM_CLOSE = &H10
Private hTimer As LongPtr
Private gsCaption As String
Sub CountDownEx()
'Anzeigen einer MsgBox mit CountDown
hTimer = SetTimer(0&, 0&, 1000, AddressOf SetMsgText)
gsCaption = "CountDown"
MessageBoxA Application.hWnd, "Ende in 5 Sekunden", gsCaption, vbExclamation Or vbModeless
KillTimer 0&, hTimer
End Sub
Private Sub SetMsgText()
Dim i As Integer, sArr() As String, hDlg As LongPtr
Dim sText As String * 255
hDlg = FindWindowA("#32770", gsCaption)
GetDlgItemTextA hDlg, 65535, sText, 255
sArr = Split(Left$(sText, InStr(sText, vbNullChar) - 1))
For i = 0 To UBound(sArr)
If Val(sArr(i)) > 0 Then
sArr(i) = sArr(i) - 1
DoEvents
If sArr(i) < 1 Then PostMessageA hDlg, WM_CLOSE, 0&, 0&
SetDlgItemTextA hDlg, 65535, ByVal Join$(sArr)
End If
Next i
End Sub
_________________________
viele Grüße aus Freigericht 😊
Karl-Heinz