Announcement

Collapse
No announcement yet.

Dialog with sound/beep

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

  • Dialog with sound/beep

    I am trying to get a modal ddt dialog box with a beep (like msgbox). I want to first show the dialog and when it's on-screen beep/sound. When I use
    Beep
    Dialog Show Modal
    I first have to wait on completion of beep/sound before dialog is shown. Is there a callback message that is sent right after the dialog is drawn to use? (using %WM_INITDIALOG still beeps before dialog is drawn...)


    -------------
    Kind regards,
    Peter.



    [This message has been edited by Peter Lameijn (edited March 27, 2000).]
    Regards,
    Peter

    "Simplicity is a prerequisite for reliability"

  • #2
    The 1st way that comes to mind is to use PostMessage() in the %WM_INITDIALOG handler to _post_ a user-defined message to yourself (ie, %WM_USER + 999&). When you get the user defined message, make the noise!

    Basically, using PostMessage() means that the message will appear after the queued (and possibly non-queued) messages have been handled.


    ------------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Peter --
      Another variant to use a timer.

      CallBack Function Dlg_CB
      If CbMsg = %WM_INITDIALOG Then SetTimer CbHndl, 1, 500, ByVal %NULL
      If CbMsg = %WM_TIMER Then Beep: KillTimer CbHndl, 1
      End Function

      If it's interesting to you, two monthes ago I posted on Source code forum a variant of PLAY/SOUND statement for PB/DLL(CC). (for PC w/o Sound Blaster)

      ------------------

      Comment


      • #4
        Thanks. I'll try both when I'm back in the office...



        [This message has been edited by Peter Lameijn (edited March 31, 2000).]
        Regards,
        Peter

        "Simplicity is a prerequisite for reliability"

        Comment


        • #5
          Tested it. With PostMessage, the message appears in the middle of the Dialog screen build-up (half a screen is showing...), but the timer approach functions well. The only question I still have: Is it allowed to use SetTimer to reload an existing timer (like below) with another value, or should KillTimer be used first (the documentation on SetTimer is a bit unclear at this point)
          Code:
          CallBack Function CBAbout ()
            Static hTimer As Long,Active As Long
            Select Case CbMsg
              Case %WM_INITDIALOG
                hTimer = SetTimer(hAbout, ByVal &H0000FEED, 10, ByVal %NULL)
              Case %WM_TIMER
                If Active = 0 Then
                  hTimer = SetTimer(hAbout, ByVal &H0000FEED, 4000, ByVal %NULL)
                  Active = 1
                  Beep
                Else
                  KillTimer %NULL, hTimer
                  Active = 0
                  Dialog End hAbout
                End If
              Case %WM_COMMAND
                Select Case CbCtl
                  Case %CMD_ABOUT_OK
                    KillTimer %NULL, hTimer
                    Dialog End hAbout
                    Active = 0
                End Select
           End Select
          End Function


          ------------------
          Kind regards,
          Peter.
          Regards,
          Peter

          "Simplicity is a prerequisite for reliability"

          Comment


          • #6
            Peter --
            You post fragment only and I'm afraid that you made some mistakes.
            Like minimum, in KillTimer. If hAbout = CbHndl then should be KillTimer hAbout, ...

            Like I understand Win32.hlp, to use a value, which returns SetTimer, is necessary for hWnd = 0 only.

            But reset - it seems to me - works w/o problems
            (SetTimer/KillTimer return expected values)

            Code:
               #Compile Exe
               #Register None
               #Dim All
               #Include "win32api.inc"
               CallBack Function hDlg_CB()
                  Static Active As Long
                  Select Case CbMsg
                     Case %WM_INITDIALOG
                        SetTimer CbHndl, 1, 1000, ByVal %NULL
                     Case %WM_TIMER
                        If Active = 0 Then
                           Beep: Active = 1
                           SetTimer CbHndl, 1, 5000, ByVal %NULL
                        End If
                        SetWindowText CbHndl, Time$
                     Case %WM_DESTROY
                        KillTimer CbHndl, 1
                  End Select
               End Function
              
               Function PbMain
                 Dim hDlg As Long
                 Dialog New 0, "Select Test", , , 500, 260, %WS_SYSMENU To hDlg
                 Control Add TextBox, hDlg, 101, "", 10, 120, 480,  110
                 Dialog Show Modal hDlg, Call hDlg_CB
               End Function
            ------------------

            Comment


            • #7
              From WIN32.HLP:
              An application can change a timer's time-out value by using SetTimer and can destroy a timer by using the KillTimer function. To use system resources efficiently, applications should destroy timers that are no longer necessary.


              ------------------
              Lance
              PowerBASIC Support
              mailto:[email protected][email protected]</A>
              Lance
              mailto:[email protected]

              Comment


              • #8
                This may solve your problem if you are interested in using a wav file instead of beep, assuming a sound card exists etc...

                PlaySound(ByVal lpWav, hInstance, %SND_MEMORY Or %SND_ASYNC)

                That will asynchronously play the sound.
                Maybe I'm confused as to what you are doing, if this is offbase then ignore it

                Otherwise play that just before you dialog, and it will continue on withthe dialog while the sound is playing.
                Code:
                This is my function to play wavs from resource files:
                '----------------------------------------------------------------------------------------
                Function PlayWavFromResource(hInstance As Long, WaveName As String, WaveType As String)Export As Long
                'Function PlayWavFromResource(hInstance As Long, WaveName As Asciiz, WaveType As Asciiz)Export As Long
                Local hRes As Long
                Local lpWav As Byte Ptr
                Local Wave1 As Asciiz * 10
                Local Wav1 As Asciiz * 10
                Wave1 = WaveName
                Wav1  = WaveType
                hRes = FindResource (hInstance, Wave1, Wav1)
                If hRes Then
                    lpWav = LockResource (LoadResource (hInstance, hRes))
                    If lpWav Then Function = PlaySound(ByVal lpWav, hInstance, %SND_MEMORY Or %SND_ASYNC)
                End If
                End Function
                ------------------
                Scott
                mailto:[email protected][email protected]</A>

                [This message has been edited by Scott Turchin (edited March 31, 2000).]
                Scott Turchin
                MCSE, MCP+I
                http://www.tngbbs.com
                ----------------------
                True Karate-do is this: that in daily life, one's mind and body be trained and developed in a spirit of humility; and that in critical times, one be devoted utterly to the cause of justice. -Gichin Funakoshi

                Comment

                Working...
                X