Technorati label: Access, sound
There are three methods. One is to use the playsound function in winmm. It seems that only wav files can be played, the other is to use ShellExecute, and the other is to use a media player in the Microsoft Office 11.0 Object Library. I only use the first one, and the last two are temporarily recorded here for memo.
First, use the playsound function in winmm.
- Declare function apisndplaysound lib "winmm" alias "sndplaysounda" (byval filename as string, byval snd_async as long) as long
- Function playsound (swavfile as string)
- If apisndplaysound (swavfile, 1) = 0 then
- Msgbox "the sound did not play! "
- End if
- End Function
You can call the above function during actual playback:
- Playsound ("C:/Windows/Media/chimes. wav ")
Second: Use ShellExecute. From
Here
- Private declare function ShellExecute lib "shell32.dll" alias "shellexecutea" (byval hwnd as long, byval lpoperation as string, byval lpfile as string, byval lpparameters as string, byval lpdirectory as string, byval nshowcmd as long) as long
- Private declare function findwindow lib "USER32" alias "find0000wa" (byval lpclassname as string, byval lpwindowname as string) as long
- Private declare function postmessage lib "USER32" alias "postmessagea" (byval hwnd as long, byval wmsg as long, byval wparam as long, lparam as any) as long
- Private const wm_close = & h10' close
- Available 'lpoperation parameters: open, print, find, release E, and edit
- 'Nshowcmd parameter window mode type declaration
- Private const sw_hide = 0
- Private const sw_shownormal = 1
- Private const sw_showminimized = 2
- Private const sw_showmaximized = 3
- Private const sw_shownoactivate = 4
- Private const sw_show = 5
- Private const sw_minimize = 6
- Private const sw_showminnoactive = 7
- Private const sw_showna = 8
- Private const sw_restore = 9
- Private sub command0_click ()
- 'Open and play
- ShellExecute me. hwnd, "open", "dj-i said I love you dj", "", "d:/kugoo", sw_hide
- End sub
- Private sub commandementclick ()
- 'Close
- Dim hwnd as long
- Hwnd = findwindow (vbnullstring, "Windows Media Player ")
- Postmessage hwnd, wm_close, 0 &, 0 &
- End sub
Third: Use a media player. View
Here