Jump to content

AudBox


Wombat
 Share

Recommended Posts

I've started making tools for myself to lighten the work load while writing code.

 

This is one such tool I've made I thought others might like to use/fork for anything they may be working on.

AudBox is a combination of three functions into one.

  • MsgBox
  • SoundPlay
  • SoundSetWaveVolume
It shortens the code necessary to present a visual and audible notification to the user, with options for built-in defaults for fast coding as well as volume control over the audio.

 

The snippet is as follows:

 

#include-once

; #FUNCTION# =========================================================================================================
; Name...........: _AudBox
; Description ...: Creates a notification combination of MsgBox and SoundPlay with volume control
; Syntax.........: _AudBox($flg, $Title, $txt, [$timeout, [$guiHWND, [$Aud, [$wait, [ $Volume]]]]])
; Requirement(s).: v3.2.12.1 or higher
; Author ........: Wombat
; Example........; No
;=====================================================================================================================

Func _AudBox($flg, $Title, $txt, $timeout=0, $guiHWND='', $Aud=1, $wait=0, $Volume=0)

    Local $auFLAG, $auTITLE, $auTEXT, $auTIMEOUT, $auHWnd=$guiHWND, $auSOUND, $auWAIT, $MsgRet

    ;Set the flag

    If $flg='' Then
        $auFLAG=0
    Else
        $auFLAG=$flg
    EndIf

    ;Set the title

    Switch $Title
        Case 1
            $auTITLE="Windows Notification"
        Case 2
            $auTITLE=@ScriptName & " - Error!"
        Case 3
            $auTITLE=@ScriptName & " - Attention!"
        Case 4
            $auTITLE=@ScriptName & " - Done!"
        Case 5
            $auTITLE=@UserName & ", please contact an administrator!"
        Case Else
            If IsString($Title) Then
                $auTITLE=$Title
            Else
                If $Title=Default Then $auTITLE=@ScriptName

                If $Title='' Then $auTITLE=@ScriptName
            EndIf

    EndSwitch

    ;Set the text

    If $txt='' Then
        If Not @Compiled Then ConsoleWriteError("ERROR! - _AudBox() function was not provided with text" & @CRLF)
        Return SetError(1, 3, "No text provided")
    Else
        $auTEXT=$txt
    EndIf

    ;Set the timeout

    If $timeout=Default Then
        $auTIMEOUT=0
    Else
        $auTIMEOUT=$timeout
    EndIf

    ;Set the audio

    Switch $Aud
        Case 2
            $auSOUND = @WindowsDir & "\Media\Windows Error.wav"
        Case 3
            $auSOUND = @WindowsDir & "\Media\Windows Notify.wav"
        Case 4
            $auSOUND = @WindowsDir & "\Media\Windows Ding.wav"
        Case 5
            $auSOUND = @WindowsDir & "\Media\Windows User Account Control.wav"
        Case 6
            $auSOUND = @WindowsDir & "\Media\Windows Balloon.wav"
        Case 7
            $auSOUND = @WindowsDir & "\Media\Windows Default.wav"
        Case 8
            $auSOUND = @WindowsDir & "\Media\Windows Exclamation.wav"
        Case 9
            $auSOUND = @WindowsDir & "\Media\Windows Navigation Start.wav"
        Case Else
            $auSOUND=$Aud
    EndSwitch

    ;Set the wait behavior

    If $wait=Default Then
        $auWAIT=0
    Else
        $auWAIT=$wait
    EndIf

    ;Set volume

    If $Volume=Default Then
        SoundSetWaveVolume(15)
    Else
        SoundSetWaveVolume($Volume)
    EndIf

    SoundPlay($auSOUND, $auWAIT)
    $MsgRet = MsgBox($auFLAG, $auTITLE, $auTEXT, $auTIMEOUT, $auHWnd)
    Return $MsgRet

EndFunc

 

An example of it's use:

#include "AudBox.au3"

$test="This is a test"


;    _AudBox Parameters:
;
;   1.) MsgBox parameter FLAG
;   2.) MsgBox parameter TITLE
;   3.) MsgBox parameter TEXT
;   4.) MsgBox parameter TIMEOUT
;   5.) MsgBox parameter HWND
;
;   6.) SoundPlay parameter Audio file path
;   7.) SoundPlay parameter wait option
;   
;   8.) SoundSetWaveVolume parameter volume percent
;       
;   _AudBox(1, 2, 3, 4, 5, 6, 7, 8)



_AudBox(0, 2, $test, 10, Default, 2, 0, 100)

Exit
I use it in some of my scripts, maybe someone else will enjoy it.

Let me know if you see any mistakes/opportunities.

 

 

Changelog - 4/14/2015

 - Added Switch's where applicable.

Changelog - 4/13/2015

 - Added UDF information section to support easy calltip creation via the calltip manager in scite.

AudBox.au3

Edited by Wombat

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Things like...

If $Aud=1 Then $auSOUND=@WindowsDir & "\Media\chimes.wav"

        If $Aud=2 Then $auSOUND=@WindowsDir & "\Media\Windows Error.wav"

        If $Aud=3 Then $auSOUND=@WindowsDir & "\Media\Windows Notify.wav"

        If $Aud=4 Then $auSOUND=@WindowsDir & "\Media\Windows Ding.wav"

        If $Aud=5 Then $auSOUND=@WindowsDir & "\Media\Windows User Account Control.wav"

        If $Aud=6 Then $auSOUND=@WindowsDir & "\Media\Windows Balloon.wav"

        If $Aud=7 Then $auSOUND=@WindowsDir & "\Media\Windows Default.wav"

        If $Aud=8 Then $auSOUND=@WindowsDir & "\Media\Windows Exclamation.wav"

        If $Aud=9 Then $auSOUND=@WindowsDir & "\Media\Windows Navigation Start.wav"

You should use If,, elseIf 

Or a switch case block, otherwise you are making a lot of comparisons that are not needed.

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

Things like...

If $Aud=1 Then $auSOUND=@WindowsDir & "\Media\chimes.wav"

        If $Aud=2 Then $auSOUND=@WindowsDir & "\Media\Windows Error.wav"

        If $Aud=3 Then $auSOUND=@WindowsDir & "\Media\Windows Notify.wav"

        If $Aud=4 Then $auSOUND=@WindowsDir & "\Media\Windows Ding.wav"

        If $Aud=5 Then $auSOUND=@WindowsDir & "\Media\Windows User Account Control.wav"

        If $Aud=6 Then $auSOUND=@WindowsDir & "\Media\Windows Balloon.wav"

        If $Aud=7 Then $auSOUND=@WindowsDir & "\Media\Windows Default.wav"

        If $Aud=8 Then $auSOUND=@WindowsDir & "\Media\Windows Exclamation.wav"

        If $Aud=9 Then $auSOUND=@WindowsDir & "\Media\Windows Navigation Start.wav"

You should use If,, elseIf 

Or a switch case block, otherwise you are making a lot of comparisons that are not needed.

 

This is exactly why I posted it, feedback's what i needed. I agree a switch case block would be best here. Honestly the code was written quick and dirty and could use a little tlc.

Thanks for the comment.

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

I would suggest this approch:

Switch $Aud
    Case 2
        $auSOUND = @WindowsDir & "\Media\Windows Error.wav"
    Case 3
        $auSOUND = @WindowsDir & "\Media\Windows Notify.wav"
    Case 4
        $auSOUND = @WindowsDir & "\Media\Windows Ding.wav"
    Case 5
        $auSOUND = @WindowsDir & "\Media\Windows User Account Control.wav"
    Case 6
        $auSOUND = @WindowsDir & "\Media\Windows Balloon.wav"
    Case 7
        $auSOUND = @WindowsDir & "\Media\Windows Default.wav"
    Case 8
        $auSOUND = @WindowsDir & "\Media\Windows Exclamation.wav"
    Case 9
        $auSOUND = @WindowsDir & "\Media\Windows Navigation Start.wav"
    Case Else
        ; do something
EndSwitch

Signature beginning:
Please remember: "AutoIt"..... *  Wondering who uses AutoIt and what it can be used for ? * Forum Rules *
ADO.au3 UDF * POP3.au3 UDF * XML.au3 UDF * IE on Windows 11 * How to ask ChatGPT for AutoIt Codefor other useful stuff click the following button:

Spoiler

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

My contribution (my own projects): * Debenu Quick PDF Library - UDF * Debenu PDF Viewer SDK - UDF * Acrobat Reader - ActiveX Viewer * UDF for PDFCreator v1.x.x * XZip - UDF * AppCompatFlags UDF * CrowdinAPI UDF * _WinMergeCompare2Files() * _JavaExceptionAdd() * _IsBeta() * Writing DPI Awareness App - workaround * _AutoIt_RequiredVersion() * Chilkatsoft.au3 UDF * TeamViewer.au3 UDF * JavaManagement UDF * VIES over SOAP * WinSCP UDF * GHAPI UDF - modest begining - comunication with GitHub REST APIErrorLog.au3 UDF - A logging Library * Include Dependency Tree (Tool for analyzing script relations) * Show_Macro_Values.au3 *

 

My contribution to others projects or UDF based on  others projects: * _sql.au3 UDF  * POP3.au3 UDF *  RTF Printer - UDF * XML.au3 UDF * ADO.au3 UDF SMTP Mailer UDF * Dual Monitor resolution detection * * 2GUI on Dual Monitor System * _SciLexer.au3 UDF * SciTE - Lexer for console pane

Useful links: * Forum Rules * Forum etiquette *  Forum Information and FAQs * How to post code on the forum * AutoIt Online Documentation * AutoIt Online Beta Documentation * SciTE4AutoIt3 getting started * Convert text blocks to AutoIt code * Games made in Autoit * Programming related sites * Polish AutoIt Tutorial * DllCall Code Generator * 

Wiki: Expand your knowledge - AutoIt Wiki * Collection of User Defined Functions * How to use HelpFile * Good coding practices in AutoIt * 

OpenOffice/LibreOffice/XLS Related: WriterDemo.au3 * XLS/MDB from scratch with ADOX

IE Related:  * How to use IE.au3  UDF with  AutoIt v3.3.14.x * Why isn't Autoit able to click a Javascript Dialog? * Clicking javascript button with no ID * IE document >> save as MHT file * IETab Switcher (by LarsJ ) * HTML Entities * _IEquerySelectorAll() (by uncommon) * IE in TaskSchedulerIE Embedded Control Versioning (use IE9+ and HTML5 in a GUI) * PDF Related:How to get reference to PDF object embeded in IE * IE on Windows 11

I encourage you to read: * Global Vars * Best Coding Practices * Please explain code used in Help file for several File functions * OOP-like approach in AutoIt * UDF-Spec Questions *  EXAMPLE: How To Catch ConsoleWrite() output to a file or to CMD *

I also encourage you to check awesome @trancexx code:  * Create COM objects from modules without any demand on user to register anything. * Another COM object registering stuffOnHungApp handlerAvoid "AutoIt Error" message box in unknown errors  * HTML editor

winhttp.au3 related : * https://www.autoitscript.com/forum/topic/206771-winhttpau3-download-problem-youre-speaking-plain-http-to-an-ssl-enabled-server-port/

"Homo sum; humani nil a me alienum puto" - Publius Terentius Afer
"Program are meant to be read by humans and only incidentally for computers and execute" - Donald Knuth, "The Art of Computer Programming"
:naughty:  :ranting:, be  :) and       \\//_.

Anticipating Errors :  "Any program that accepts data from a user must include code to validate that data before sending it to the data store. You cannot rely on the data store, ...., or even your programming language to notify you of problems. You must check every byte entered by your users, making sure that data is the correct type for its field and that required fields are not empty."

Signature last update: 2023-04-24

Link to comment
Share on other sites

Original post edited to include switches and a change-log to better track edits.

Attached script also updated.

Just look at us.
Everything is backwards; everything is upside down. Doctors destroy health. Lawyers destroy justice. Universities destroy knowledge. Governments destroy freedom. The major media destroy information and religions destroy spirituality. ~ Michael Ellner


The internet is our one and only hope at a truly free world, do not let them take it from us...

Link to comment
Share on other sites

Something you might want to think about.

Switch $Title
        Case 1
            $auTITLE="Windows Notification"
        Case 2
            $auTITLE=@ScriptName & " - Error!"
        Case 3
            $auTITLE=@ScriptName & " - Attention!"
        Case 4
            $auTITLE=@ScriptName & " - Done!"
        Case 5
            $auTITLE=@UserName & ", please contact an administrator!"
        Case Else
            If IsString($Title) Then
                $auTITLE=$Title
            Else
                If $Title=Default Then $auTITLE=@ScriptName

                If $Title='' Then $auTITLE=@ScriptName ; This '' is a string, so should really be processed in the If condition rather than the else condition
            EndIf

    EndSwitch

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

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

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...