Announcement

Collapse
No announcement yet.

Get rid of beep on msgbox

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Get rid of beep on msgbox

    I heard that certain messagebox flags will produce a beep or noise when a messagebox is shown.
    I see on internet examples where messagebeep is used icw messagebox while i want to get rid of the beep.
    I am on XP in a virtual pc and sounds are already off and i still get beeps.

    ?
    hellobasic

  • #2
    Seems to happen under VPC thus no big deal unless you have common info about this matter?
    hellobasic

    Comment


    • #3
      It is normal for a message box to generate a sound - the actual sound depending upon the icon / type of message and user's sound setup.
      Here is a code that shows one way of avoiding the beep..
      http://www.powerbasic.com/support/pb...ad.php?t=35785
      Rgds, Dave

      Comment


      • #4
        Thanks for the info, a simple wrapper could help here..

        In short: there will be no beep if %MB_USERICON is set.
        To set a similar or custom icon check out lpszIcon in the MSGBOXPARAMS structure.
        lpszIcon = %IDI_INFORMATION set's the information icon.
        See LoadIcon() for valid stock icons.
        hellobasic

        Comment


        • #5
          This simple example shows what Edwin said:

          Code:
          #Compile Exe
          Function PBMain () As Long
          MsgBox "No Beep?",  %MB_UserIcon, "Test
          End Function
          But this right justifies the text, because it saves space for the user icon.

          I read the post Dave referenced. So, I'm wondering if that is a more DDT way to do it ... plus that reference didn't tell me how to use one of my own icons (from a resource file, or *.ico file)....
          Last edited by Gary Beene; 7 Sep 2009, 10:18 AM.

          Comment


          • #6
            And then you can substitute a sound of your own, like one of these examples. The first option reads a text string (forum post from some time ago). The second plays a system sound.


            Code:
            'Compilable Example:
            #Compile Exe
            #Dim All
            #Include "Win32API.inc"
            Global hDlg As Dword
            Function PBMain() As Long
               Dialog New Pixels, 0, "Test Code",300,300,200,200, %WS_OverlappedWindow To hDlg
               Control Add Button, hDlg, 100,"Read Text", 50,10,100,20
               Control Add Button, hDlg, 200,"System Sound", 50,40,100,20
               Dialog Show Modal hDlg Call DlgProc
            End Function
            CallBack Function DlgProc() As Long
               If Cb.Msg = %WM_Command And Cb.Ctl = 100 And Cb.CtlMsg = %BN_Clicked Then
                  ReadText "Hello, a message is about to arrive!"
                  MsgBox "Message", %MB_UserIcon, "Test"
               End If
               If Cb.Msg = %WM_Command And Cb.Ctl = 200 And Cb.CtlMsg = %BN_Clicked Then
                  PlaySystemSound
                  MsgBox "Message", %MB_UserIcon, "Test"
               End If
            End Function
            
            Sub PlaySystemSound
            'For example, to play the mail sound, use this:
            Local SoundFile As Asciiz * %Max_Path, iReturn As Long
            SoundFile = "MailBeep"
            iReturn = sndPlaySound(SoundFile, %SND_ASYNC)   'play once, in background
            End Sub
            
            
            Sub ReadText (sText$)
                Local oSp As Dispatch
                Set oSp = New Dispatch In "SAPI.SpVoice"
                If IsFalse IsObject(oSp) Then Exit Sub
                Local vRes As Variant
                Local vTxt As Variant
                Local vTime As Variant
                vTxt = sText$
                Object Call oSp.Speak(vTxt) To vRes
                vTime = -1 As Long
                Object Call oSp.WaitUntilDone(vTime) To vRes
            End Sub

            Comment


            • #7
              plus that reference didn't tell me how to use one of my own icons (from a resource file, or *.ico file)....
              MessageBoxIndirect()
              Michael Mattias
              Tal Systems (retired)
              Port Washington WI USA
              [email protected]
              http://www.talsystems.com

              Comment


              • #8
                Here's another quick solution:
                Code:
                #Compile Exe
                Function PBMain () As Long
                 MsgBox "No Beep? - no space for icon either!",  %MB_ICONMASK, "Test"
                End Function
                I've now modified the sample in the Source Code forum to be a more direct replacement for PB's MsgBox. Has the same functionality / format but without the beeps
                http://www.powerbasic.com/support/pb...ad.php?t=35785

                That sample now includes code for using your own icon from a resource file. (Couldn't see a simple way to use an icon loaded from a file..)
                Rgds, Dave

                Comment

                Working...
                X