Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 350
  • Last Modified:

Synchronize sound w/VB6 form

I'm working in VB6.  I need to synchronize the playing of a sound with a condition on a form.  The condition is whether or not an image is visible .  The problem is this;  When I evaluate for the condition, it's being done on one of the form's 'prep' events (load, initialize, paint, etc - I've tried lots).  Thus, the sound plays before the form is fully displayed.  Is there a way the form can completely display and then raise an event which evaluates the image (visible or not) and THEN plays the sound?
0
wjshore
Asked:
wjshore
1 Solution
 
Robberbaron (robr)Commented:
Ive used a single timer control to delay reprocessing a form (after user selection) until it has finished displaying.

it's interval is set to 50 milliseconds.

Private Sub cboHighlight_check()
    'routine to detect change of phase
    If cboHighlight.ListIndex <> mHighlightId Then
        mHighlightId = cboHighlight.ListIndex
        tmrPhaseChange.Enabled = True
    End If
End Sub

the timer then fires and form contents get redrawn.
0
 
peetmCommented:
Probably the best way to avoid modal/modeless problems with showing the form is to use an async playing for the sound i.e., play the sound AND continue loading/displaying the form at the same time.  If there's not a bucket load of stuff done in the form, it should appear more or less at the same instant as the sound does.

Use PlaySound with SND_SYNC

Public Const SND_SYNC = &H0          '  Play synchronously (default).
Public Const SND_ASYNC = &H1         '  Play asynchronously.

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Call PlaySound(Sound, App.hInstance, SND_ASYNC)
0
 
aikimarkCommented:
put your code in the Activate event.
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
"Is there a way the form can completely display..."

Here is how to make the form show itself before continuing with the rest of the Load event:

Private Sub Form_Load()
    ' force the form to show itself
    Me.Show
    DoEvents
   
    ' continue doing other stuff...
   
End Sub
0
 
peetmCommented:
>>"Here is how to make the form show itself before continuing with the rest of the Load event:"

As long as it's not been shown modally elsewhere, e.g., that will fail if elsewhere *this* form's being implicitly loaded via, say, someForm.Show vbModal
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now