Jump to content

Recommended Posts

Posted

hello i want Close a MsgBox after 10s.

 

I have this code and it work but when i have wait 10 all close not just a GUI.

Opt("GUIOnEventMode", 1)

Global $MessageBoxForm1,$flag_to_Exit = False


; Your main script here
Call_Message() ; your custom message box called
; Your main script here

Exit ; End of your script

Func Call_Message()
    Local $countdown = 10
    $MessageBoxForm1 = GUICreate("MY Custom Messages Box", 355, 135, 192, 150,$WS_SYSMENU)
    $Label1 = GUICtrlCreateLabel("My custom text here.... Just add your personal messages", 32, 16, 270, 17)
    $Button1 = GUICtrlCreateButton("Button1", 88, 64, 161, 41, $WS_GROUP)
    GUICtrlSetOnEvent($Button1, "Click_to_Exit")
    GUISetState(@SW_SHOW)

    While 1
        if $countdown = 0 or $flag_to_Exit = True then
            GUIDelete($MessageBoxForm1)
            ExitLoop
        EndIf
        GUICtrlSetData($Button1,"OK ("&$countdown&")")
        $countdown -= 1
        Sleep(999)
    WEnd

EndFunc

How to exit loop without close all ?

 

THX

Posted

This code is incomplete and throws a lot of error messages.
Can you please provide a code that is ready to run? Makes debugging much easier ;)

My UDFs and Tutorials:

Spoiler

UDFs:
Active Directory (NEW 2024-07-28 - Version 1.6.3.0) - Download - General Help & Support - Example Scripts - Wiki
ExcelChart (2017-07-21 - Version 0.4.0.1) - Download - General Help & Support - Example Scripts
OutlookEX (2021-11-16 - Version 1.7.0.0) - Download - General Help & Support - Example Scripts - Wiki
OutlookEX_GUI (2021-04-13 - Version 1.4.0.0) - Download
Outlook Tools (2019-07-22 - Version 0.6.0.0) - Download - General Help & Support - Wiki
PowerPoint (2021-08-31 - Version 1.5.0.0) - Download - General Help & Support - Example Scripts - Wiki
Task Scheduler (2022-07-28 - Version 1.6.0.1) - Download - General Help & Support - Wiki

Standard UDFs:
Excel - Example Scripts - Wiki
Word - Wiki

Tutorials:
ADO - Wiki
WebDriver - Wiki

 

  • Developers
Posted
5 hours ago, AutoDEV said:

Im sorry but i have make mistake with post.

There are still errors in your code! Use au3check to check your code! (install the full SciTE4AutoIt3 so au3check will run every time you press F5/Run.

5 hours ago, AutoDEV said:

Can you reply with one code or exemple argumentum ?

Are you seriously begging a member to answer? Please don't! Just try to make use of the information available and post your code again when there are no errors anymore and still not working, and I am sure someone  will help.

Jos

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Posted

You can try something like this here:

 

#include <WindowsConstants.au3>
#include <GUIConstantsEx.au3>

Global $MessageBoxForm1,$flag_to_Exit = False


; Your main script here
Call_Message() ; your custom message box called
; Your main script here

MsgBox("", "Test", "Done")

Exit ; End of your script

Func Call_Message()
    Local $countdown = 10, $fTimer = TimerInit(), $fDiff
    $MessageBoxForm1 = GUICreate("MY Custom Messages Box", 355, 135, 192, 150,$WS_SYSMENU, $WS_EX_COMPOSITED)
    $Label1 = GUICtrlCreateLabel("My custom text here.... Just add your personal messages", 32, 16, 270, 17)
    $Button1 = GUICtrlCreateButton("OK (" & $countdown & ")" , 88, 64, 161, 41, $WS_GROUP)
    GUISetState(@SW_SHOW)

    While 1
        Switch GUIGetMsg()
            Case $GUI_EVENT_CLOSE, $Button1
                GUIDelete($MessageBoxForm1)
                Return 0
        EndSwitch
        $fDiff = $countdown * 1000 - TimerDiff($fTimer)
        If Mod(Int($fDiff), 1000) > 900 Then GUICtrlSetData($Button1,"OK ("& Round($fDiff / 1000, 0) &")")
        If $fDiff < 0 Then
            GUIDelete($MessageBoxForm1)
            Return 1
        EndIf
    WEnd

EndFunc

 

Or as an alternative:

;Coded by UEZ build 2023-04-29 beta

#include <Timers.au3>
#include <WinAPIConstants.au3>
#include <WinAPIGdi.au3>
#include <WinAPIProc.au3>
#include <WinAPISys.au3>
#include <WindowsConstants.au3>

Const $HCBT_CREATEWND = 3, $HCBT_DESTROYWND = 4, $HCBT_ACTIVATE = 5, $g_iFlagDefault = BitOR($MB_TOPMOST, $MB_ICONINFORMATION)
Global $g_hMsgBoxHook, $g_hSubMsgBox, $g_idTImer, $g_sBtn1_Txt = "Close", $g_sBtn2_Txt, $g_sBtn3_Txt
Global $g_Timeout = 0

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 _TimerProc($hwnd, $iMsg, $wParam, $lParam)
    If $g_Timeout <= 1 Then
        WinClose($hwnd)
    Else
        $g_Timeout -= 1
        _WinAPI_SetDlgItemText($hWnd, $IDOK + 1, $g_sBtn1_Txt & " [" & $g_Timeout & "]")
    EndIf
EndFunc   ;==>_TimerProc

Func _CBTHookProc($nCode, $wParam, $lParam)
    If $nCode < 0 Then Return _WinAPI_CallNextHookEx($g_hMsgBoxHook, $nCode, $wParam, $lParam)
    Local Const $hHWND = HWnd($wParam)
    Switch $nCode
        Case $HCBT_ACTIVATE
            If _WinAPI_GetClassName($hHWND) = "#32770" Then
                If $g_Timeout Then $g_idTImer = _Timer_SetTimer($hHWND, 1000, "_TimerProc")
                _WinAPI_SetDlgItemText($wParam, $IDOK, $g_Timeout ? $g_sBtn1_Txt & " [" & $g_Timeout & "]" : $g_sBtn1_Txt)
            EndIf
        Case $HCBT_DESTROYWND
            If _WinAPI_GetClassName($hHWND) = "#32770" Then _Timer_KillTimer($hHWND, $g_idTImer)
    EndSwitch
    Return _WinAPI_CallNextHookEx($g_hMsgBoxHook, $nCode, $wParam, $lParam)
EndFunc   ;==>_CBTHookProc

Func MsgBoxEx($sText, $sTitle = Default, $iTimeout = 0, $iFlag = Default, $sBtn_Txt = Default, $hParentHWND = "")
    If $sBtn_Txt <> Default Then $g_sBtn1_Txt = $sBtn_Txt
    If $iFlag = Default Then $iFlag = $g_iFlagDefault
    $g_Timeout = $iTimeout
    $g_MsgProc = DllCallbackRegister("_CBTHookProc", "int", "uint;wparam;lparam")
    Local Const $hThreadID = _WinAPI_GetCurrentThreadId()
    $g_hMsgBoxHook = _WinAPI_SetWindowsHookEx($WH_CBT, DllCallbackGetPtr($g_MsgProc), Null, $hThreadID)
    If $sTitle = Default Then $sTitle = "Information"
    Local Const $iReturn = MsgBox($iFlag, $sTitle, $sText, $iTimeout, $hParentHWND)
    _WinAPI_UnhookWindowsHookEx($g_hMsgBoxHook)
    DllCallbackFree($g_MsgProc)
    Return $iReturn
EndFunc   ;==>MsgBoxEx

ConsoleWrite(MsgBoxEx("This is a test", "Information", 5) & @CRLF)

 

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...