Jump to content

Create a MsgBox with buttons disabled for specific amount of time


Go to solution Solved by argumentum,

Recommended Posts

  • Moderators
5 minutes ago, argumentum said:

..you know, going down the rabbits hole, at trying to add "SetDlgItemText" to rename the buttons, might as well just have added the timer thing to your script. 😅

I would have :whistle:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

.. "SetWindowsHookEx" is the hooker, what comes to mind ? ( there's a good example for cognitive dissonance )
Look, choosing between little endian and big endian, I'd say am a middle of the endian kind of guy ( don't know much, other than copy'n'paste .This thing about thinking, is hard for me. But I feel I'm getting there )

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • Moderators
12 minutes ago, argumentum said:

.. "SetWindowsHookEx" is the hooker, what comes to mind ? ( there's a good example for cognitive dissonance )
Look, choosing between little endian and big endian, I'd say am a middle of the endian kind of guy ( don't know much, other than copy'n'paste .This thing about thinking, is hard for me. But I feel I'm getting there )

I'm no spring chicken, self taught starting with AutoIt and branched from there, if I can get things, I'm quite positive you can too.

I believe in you :cheer:

Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.

Link to comment
Share on other sites

  • Moderators

Hi,

I saw my UDF mentioned - here is a new Beta with a "Button TimeIn" functionality set by using a negative $iTimeOut parameter (look at the EMB produced by Case $hButton1):

<snip>

If anyone thinks this a useful addition to the UDF, please let me know. I am little concerned that you are limited to either a "Button TimeIn" or a "EMB TimeOut", but others might not see that as a problem.

M23

Edited by Melba23
Beta code removed

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

1 hour ago, Melba23 said:

I am little concerned that you are limited to either a "Button TimeIn" or a "EMB TimeOut"

Since this delay is an odd request, about an extra function: _ExtMsgButtonDelay($iDelayInSec, $ButtonsToDisable) ?
That way none of the functionality is lost.

or

Local $aTemp = StringSplit($iTimeOut, "/")
ReDim $aTemp[3]
$iTimeIn = Int(Abs($aTemp[2]))

and TimeOut/TimeIn, defaulting to "0/0".
At least that's what I did in mine to select the delay and optionally choose a button another than default "$iDelay/OpionalButtonNumber"

Edited by argumentum

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  • Moderators

argumentum,

Good points. I do not want to add an extra function so I have gone for the "colon-delimited parameter" method. See what you think:

<snip>

M23

Edited by Melba23
Beta code removed - see EMB thread for release

Public_Domain.png.2d871819fcb9957cf44f4514551a2935.png Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind

Open spoiler to see my UDFs:

Spoiler

ArrayMultiColSort ---- Sort arrays on multiple columns
ChooseFileFolder ---- Single and multiple selections from specified path treeview listing
Date_Time_Convert -- Easily convert date/time formats, including the language used
ExtMsgBox --------- A highly customisable replacement for MsgBox
GUIExtender -------- Extend and retract multiple sections within a GUI
GUIFrame ---------- Subdivide GUIs into many adjustable frames
GUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView items
GUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeView
Marquee ----------- Scrolling tickertape GUIs
NoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxes
Notify ------------- Small notifications on the edge of the display
Scrollbars ----------Automatically sized scrollbars with a single command
StringSize ---------- Automatically size controls to fit text
Toast -------------- Small GUIs which pop out of the notification area

 

Link to comment
Share on other sites

; Validate timeout value
    $iTimeOut = Abs(Int($vTimeOut))
    If StringInStr($vTimeOut, ":") Then
        Local $aRet = StringSplit($vTimeOut, ":")
        $iTimeIn = Abs(Int($aRet[2]))
    EndIf

With this we have both

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

  

Here's an updated example to show case use of the updated UDF here, the example uses custom text in each button of the message box

This example uses random function to jump into one of the three questions

If the users selects a wrong answer then the program will punish him by showing an message box with disabled button, and then the user will be required to wait until timeout is over :)

Edit: updated the example

nag_messagebox.au3:

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <MsgBox_Extn.au3>; https://www.autoitscript.com/forum/index.php?showtopic=211499&view=findpost&p=1530323

If _MsgBox_Extn_Version() < 4 Then Exit ConsoleWrite(@CRLF & 'Get the new version UDF from:' & @CRLF & _
        'https://www.autoitscript.com/forum/topic/211499-create-a-msgbox-with-buttons-disabled-for-specific-amount-of-time/#comment-1530323' & @CRLF)

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 339, 131, -1, -1)
Global $Label1 = GUICtrlCreateLabel("Welcome to the empty frame software :)", 72, 32, 191, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $MsgText, $MixButton, $anwser1, $anwser2
NagMsg() ; run function

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop

    EndSwitch
WEnd


Func NagMsg()
    Local $returned, $MixQuestion, $MixAnwser
    $MixQuestion = Random(1, 3, 1)
    $MixAnwser = Random(1, 2, 1)
    If $MixQuestion = '1' Then ; the var $anwser1 always holds the correct anwser !
        $MsgText = 'What is the easiest function newbie can learn in GUI?'
        $anwser1 = 'MessageBox'
        $anwser2 = "Function"
    ElseIf $MixQuestion = '2' Then
        $MsgText = 'What is the first two words every programmer learn?'
        $anwser1 = 'Hello World'
        $anwser2 = 'Message Box'
    ElseIf $MixQuestion = '3' Then
        $MsgText = 'What kernel are Windows based on?'
        $anwser1 = 'NT'
        $anwser2 = 'WIN_KERNEL'
    EndIf
    If $MixAnwser = '1' Then
        _MsgBox_Extn_SetButtonText($anwser1, $anwser2)
        $MixButton = $MB_YESNO
    Else
        _MsgBox_Extn_SetButtonText($anwser2, $anwser1)
        $MixButton = $MB_RETRYCANCEL
    EndIf

    $returned = _MsgBox_Extn(0, BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MixButton), 'Info', $MsgText, 0, $Form1)

    If $returned = $IDNO Or $returned = $IDRETRY Then
        $MsgText = 'You have selected a wrong anwser !' & @CRLF
        $MsgText &= 'Now this program will punish you' & @CRLF
        $MsgText &= 'by wasting 60 seconds of your life :D'
        _MsgBox_Extn_SetCallBackFunc(HaveMercy)
        ConsoleWrite('using "' & FuncName(_MsgBox_Extn_SetCallBackFunc()) & '()" as callback function.' & @CRLF)
        $returned = _MsgBox_Extn(60, BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_OK), 'Info', $MsgText, 0, $Form1)
        _MsgBox_Extn_SetCallBackFunc(Default) ; if you're not gonna use it anymore.
    EndIf
EndFunc   ;==>NagMsg

Func HaveMercy()
    If _MsgBox_Extn_SecCount() = 56 Then
        _MsgBox_Extn_SecCount(4)
        _MsgBox_Extn_SetMessageText('Nah, just kidding  =)')
    EndIf
EndFunc   ;==>HaveMercy

 

Edited by simplercoder000
Updated the example
Link to comment
Share on other sites

Ok, fixed. And added a callback function just to have your joke applied mercifully :lol:
You'll need the new version for this to even run.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#include <MsgBoxConstants.au3>
#include <MsgBox_Extn.au3> ; https://www.autoitscript.com/forum/index.php?showtopic=211499&view=findpost&p=1530323

If _MsgBox_Extn_Version() < 4 Then Exit ConsoleWrite(@CRLF & 'Get the new version UDF from:' & @CRLF & _
    'https://www.autoitscript.com/forum/topic/211499-create-a-msgbox-with-buttons-disabled-for-specific-amount-of-time/#comment-1530323' & @CRLF)

#Region ### START Koda GUI section ### Form=
Global $Form1 = GUICreate("Form1", 339, 131, -1, -1)
Global $Label1 = GUICtrlCreateLabel("Welcome to the empty frame software :)", 72, 32, 191, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

Global $MsgText, $MixButton, $anwser1, $anwser2
NagMsg() ; run function

While 1
    Switch GUIGetMsg()
        Case $GUI_EVENT_CLOSE
            GUIDelete()
            ExitLoop

    EndSwitch
WEnd


Func NagMsg()
    Local $returned, $MixQuestion, $MixAnwser, $punish
    $MixQuestion = Random(1, 3, 1)
    $MixAnwser = Random(1, 2, 1)
    If $MixQuestion = '1' Then ; the var $anwser1 always holds the correct anwser !
        $MsgText = 'What is the easiest function newbie can learn in GUI?'
        $anwser1 = 'MessageBox'
        $anwser2 = "Function"
        $MixButton = $MB_YESNO
    ElseIf $MixQuestion = '2' Then
        $MsgText = 'What is the first two words every programmer learn?'
        $anwser1 = 'Hello World'
        $anwser2 = 'Message Box'
        $MixButton = $MB_YESNO
    ElseIf $MixQuestion = '3' Then
        $MsgText = 'What kernel are Windows based on?'
        $anwser1 = 'NT'
        $anwser2 = 'WIN_KERNEL'
    EndIf
    If $MixAnwser = '1' Then
        _MsgBox_Extn_SetButtonText($anwser1, $anwser2)
        $MixButton = $MB_YESNO
    Else
        _MsgBox_Extn_SetButtonText($anwser2, $anwser1)
        $MixButton = $MB_RETRYCANCEL
    EndIf

    $returned = _MsgBox_Extn(1, BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MixButton), 'Info', $MsgText, 0, $Form1)

    If $returned = $IDNO Then
        $punish = 'yes'
    ElseIf $returned = $IDRETRY Then
        $punish = 'yes'
    EndIf
    If $punish = 'yes' Then
        $MsgText = 'You have selected a wrong anwser !' & @CRLF
        $MsgText &= 'Now this program will punish you' & @CRLF
        $MsgText &= 'by wasting 60 seconds of your life :D'
        _MsgBox_Extn_SetCallBackFunc(HaveMercy)
        ConsoleWrite('using "' & FuncName(_MsgBox_Extn_SetCallBackFunc()) & '()" as callback function.' & @CRLF)
        $returned = _MsgBox_Extn(60, BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_OK), 'Info', $MsgText, 0, $Form1)
        _MsgBox_Extn_SetCallBackFunc(Default) ; if you're not gonna use it anymore.
    EndIf
EndFunc   ;==>NagMsg

Func HaveMercy()
    If _MsgBox_Extn_SecCount() = 56 Then
        _MsgBox_Extn_SecCount(4)
        _MsgBox_Extn_SetMessageText('Nah, just kidding  =)')
    EndIf
EndFunc

Edit: added _MsgBox_Extn_SetMessageText() :D 

Edited by argumentum
better code ?

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

16 hours ago, argumentum said:

Ok, fixed. And added a callback function just to have your joke applied mercifully :lol:

Ops, I have made some typo mistakes in the example I have wrote, but no problem I'll update the example later, also my example are too poor I haven't even able to compare both returned values from message box at same time :p.

16 hours ago, argumentum said:

You'll need the new version for this to even run.

I always keep the I store UDF updated ;)

Edited by simplercoder000
Some typo fixes
Link to comment
Share on other sites

hey, I just learned that it can be up to 4 buttons ! ( BitOR($MB_CANCELTRYCONTINUE, $MB_HELP) )
So no new version number but that is something that I didn't think of.

We all learn by doing :) 

Edit: fixed.

Edited by argumentum
fixed oops

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

..so you know, there is also this:

;~ RegDelete("HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\DontShowMeThisDialogAgain", "MyProg")
;~ Exit

#include <MsgBoxConstants.au3>
#include <WinAPIDlg.au3>
Local $iResult = _WinAPI_MessageBoxCheck(BitOR($MB_TOPMOST, $MB_ICONINFORMATION, $MB_CANCELTRYCONTINUE, $MB_HELP), 'MyProg', '_WinAPI_MessageBoxCheck()', 'MyProg')
ConsoleWrite('Return: ' & $iResult & @CRLF)
Exit

 

Follow the link to my code contribution ( and other things too ).
FAQ - Please Read Before Posting.
autoit_scripter_blue_userbar.png

Link to comment
Share on other sites

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
 Share

×
×
  • Create New...