Solved

background music

Posted on 2002-03-18
9
339 Views
Last Modified: 2011-09-20
How to add background midi/wav files music that will run automaticlly in an application startup?(using visual basic 6)
0
Comment
Question by:kyokugenryu
  • 5
  • 3
9 Comments
 
LVL 18

Expert Comment

by:deighton
ID: 6877258
chuck on a Windows Media Player control (via components) then

Private Sub Form_Load()
MediaPlayer1.filename = "c:\program files\messenger\test.wav"
End Sub
0
 
LVL 3

Expert Comment

by:shankarkrupa
ID: 6877370
Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

public sub Form_Load()
'PathandName = {Your wave file path}
Comd = "Open " & PathandName & " Type WaveAudio Alias hai"

mciSendString Comd, "", 0, 0

mciSendString "play hai", "", 0, 0

end sub

That is all...If you are using a midifile, then you should use the word 'sequencer' instead of waveaudio after the Type keyword...So, it should be:

Comd = "Open " & PathandName & " Type sequencer Alias hai"

that is all....

S Krupa Shankar
0
 
LVL 3

Expert Comment

by:shankarkrupa
ID: 6877372
Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

public sub Form_Load()
'PathandName = {Your wave file path}
Comd = "Open " & PathandName & " Type WaveAudio Alias hai"

mciSendString Comd, "", 0, 0

mciSendString "play hai", "", 0, 0

end sub

That is all...If you are using a midifile, then you should use the word 'sequencer' instead of waveaudio after the Type keyword...So, it should be:

Comd = "Open " & PathandName & " Type sequencer Alias hai"

that is all....

S Krupa Shankar
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:shankarkrupa
ID: 6877375
I am sorry, I am sorry, I did not see the "answer" radio button checked....Very, very sorry...I did not intend to propose this as an answer, but as only a comment...Sorry..

S Krupa Shankar
0
 

Author Comment

by:kyokugenryu
ID: 6923664
sorry for slow replying.
I'm new in VB6, can anyone show me the simple way to create a blank program that will run this 123.mid file automaticaly when the program executes?
let's say the 123.mid is in c:\midi folder.TQ
0
 
LVL 3

Expert Comment

by:shankarkrupa
ID: 6926196
Okay!

Start Visual Basic.
Select Standard EXE (Just press enter after it asks you what file to create?)
Then, in the code widow, press the follwing things (press the F7 function key to go to the code window, or alternatively, Alt->view->code)

Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As
String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long)
As Long

public sub Form_Load()
mciSendString "Open c:\midi folder\123.mid Type sequencer Alias hai", "", 0, 0
mciSendString "play hai", "", 0, 0
end sub

That is all...Now press the F5 key...You can hear that...

S Krupa Shankar
0
 

Author Comment

by:kyokugenryu
ID: 6929210
I get compile error in this line:

Public Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long

any mistake in this line? could you correct it?
as a reward i increase the points to this question....TQ
0
 
LVL 3

Accepted Solution

by:
shankarkrupa earned 50 total points
ID: 6929330
Maybe you are doing it in a form....

It is a rule that these api declarations should not be declared as PUBLIC inside a form.

So, just change it to private.

So, that line should be like this:

Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As
String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long)
As Long


That is all.

S Krupa Shankar
0
 

Author Comment

by:kyokugenryu
ID: 6934733
Thanks friend..
0

Featured Post

Active Directory Webinar

We all know we need to protect and secure our privileges, but where to start? Join Experts Exchange and ManageEngine on Tuesday, April 11, 2017 10:00 AM PDT to learn how to track and secure privileged users in Active Directory.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question