Ich möchte gerne einen Countdown in das Ok Button hinzufügen, das die vorgebene Zeit herunter zählt. Man könnte dies natürlich mit einer eigen gebastelten GUI realisieren, aber will ich nicht.
Das habe ich soweit zusammen gebastelt, funktioniert leider nicht und meine Augen fallen gerade zu:
AutoIt
#include <WindowsConstants.au3>
#include <WinAPIConstants.au3>
#include <WinAPISys.au3>
#include <WinAPIProc.au3>
#include <Timers.au3>
Global $tagCWPSTRUCT = "long lParam;long wParam;uint message;hwnd hwnd"
Global $HCBT_ACTIVATE = 5, $g_hMsgBoxHook, $g_hMod, $g_hThreadID, $g_hSubMsgBox, $g_SubMsgBox, $g_lPrevWnd, $g_BtnID, $g_HWND, $g_idTImer
Global $g_Time = 5
Func _WinAPI_SetDlgItemText($hDlg, $nIDDlgItem, $lpString) ;https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-setdlgitemtextw
Local $aRet = DllCall("user32.dll", "int", "SetDlgItemText", "hwnd", $hDlg, "int", $nIDDlgItem, "str", $lpString)
If @error Then Return SetError(@error, @extended, 0)
Return $aRet[0]
EndFunc ;==>_WinAPI_SetDlgItemText
Func _SubMsgBoxProc($hwnd, $iMsg, $wParam, $lParam)
Switch $iMsg
Case $WM_SHOWWINDOW
Case $WM_TIMER
_WinAPI_SetDlgItemText($g_BtnID, $IDOK, "OK [" & $g_Time & "]")
$g_Time -= 1
If $g_Time < 0 Then
_Timer_KillTimer($g_idTImer, $g_HWND)
_WinAPI_SetWindowLong($hwnd, $GWL_WNDPROC, $g_lPrevWnd)
EndIf
Return 0
Case $WM_DESTROY
_Timer_KillTimer($g_idTImer, $g_HWND)
;_WinAPI_SetWindowLong($hwnd, $GWL_WNDPROC, $g_lPrevWnd)
EndSwitch
Return _WinAPI_CallWindowProc($g_lPrevWnd, $hWnd, $iMsg, $wParam, $lParam)
EndFunc
Func _CBTHookProc($nCode, $wParam, $lParam)
If $nCode < 0 Then Return _WinAPI_CallNextHookEx($g_hMsgBoxHook, $nCode, $wParam, $lParam)
Local $tCWP = DllStructCreate($tagCWPSTRUCT, $lParam)
Switch $nCode
Case $HCBT_ACTIVATE
$g_HWND = HWnd($wParam)
If _WinAPI_GetClassName($g_HWND) = "#32770" Then
$g_idTImer = _Timer_SetTimer($g_HWND, 1000)
$g_BtnID = HWnd($wParam) ;_WinAPI_GetDlgItem($wParam, 1)
_WinAPI_SetDlgItemText($g_BtnID, $IDOK, "OK [" & $g_Time & "]")
$g_lPrevWnd = _WinAPI_SetWindowLong($g_HWND, $GWL_WNDPROC, DllCallbackGetPtr($g_SubMsgBox))
EndIf
EndSwitch
Return _WinAPI_CallNextHookEx($g_hMsgBoxHook, $nCode, $wParam, $lParam)
EndFunc
$g_SubMsgBox = DllCallbackRegister("_SubMsgBoxProc", "long", "hwnd;uint;wparam;lparam")
$g_MsgProc = DllCallbackRegister("_CBTHookProc", "int", "uint;wparam;lparam")
$g_hMod = _WinAPI_GetModuleHandle(0)
$g_hThreadID = _WinAPI_GetCurrentThreadId()
$g_hMsgBoxHook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($g_MsgProc), Null, $g_hThreadID)
MsgBox(0, "Test", "This is a test message box!")
_WinAPI_UnhookWindowsHookEx($g_hMsgBoxHook)
_WinAPI_UnhookWindowsHookEx($g_lPrevWnd)
DllCallbackFree($g_SubMsgBox)
DllCallbackFree($g_MsgProc)
Alles anzeigen
Könnt ihr den Fehler sehen?