VB 6 codes
New to VB and programming
I have inserted a picture of apple. Now I want to be able click on the picture of apple and it should load a sound. Can someone provide me the code.
I am using VB6.
Thanks in advance
Web Development
New to VB and programming
I have inserted a picture of apple. Now I want to be able click on the picture of apple and it should load a sound. Can someone provide me the code.
I am using VB6.
Thanks in advance
by martinwalke
Hi,
To play a sound you either need to resort to API calls or use the MCI (Media control) OCX control.
Using the API is often easier providing that's all you want to do.
Add a reference to the PlaySound API to your code by using the API viwer tool provided with VB6.
Remember that if you add the API reference to the form code add Private to the start of it otherwise it will default to public. If you add the reference to a module then you won't need the private part.
(Private) Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
This call takes 3 params - the first is the filename, the second should be 0 and the third is a value for controlling the sound. IT's probably better at this point to refer to the MSDN description of this API call to check the values of that flag but as a starting point use 1 (async - return straight away from call).
IN your VB code in the picture1_click event simply add:
PlaySound "c:\mysoundfile.wav", 0, 1
That should do it.
This discussion is closed to new replies.
Sort by Trending