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?
wjshoreAsked:
Who is Participating?
 
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
 
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
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.