為程序增加簡單的聲音提示(.net封裝API --PlaySound())
????????????????
????????????
using
?System;
using
?System.Runtime.InteropServices;
namespace
?tonysound?
{
????
public
?
class
?Sound?
????
{
????????
public
?
static
?
void
?Play(?
string
?strFileName,?PlaySoundFlags?soundFlags)?
????????
{
????????????PlaySound(?strFileName,?IntPtr.Zero,?soundFlags);
????????????
//
?passes?to?Playsound?the?filename?and?a?pointer
????????????
//
?to?the?Flag
????????}
????????[DllImport(
"
winmm.dll
"
)]?
//
inports?the?winmm.dll?used?for?sound
????????
private
?
static
?
extern
?
bool
?PlaySound(?
string
?szSound,?IntPtr?hMod,?PlaySoundFlags?flags?);
????}
????[Flags]?
//
enumeration?treated?as?a?bit?field?or?set?of?flags
????
public
?
enum
?PlaySoundFlags:?
int
?
????
{

????????SND_SYNC?
=
?
0x0000
,?
/**/
/*
?play?synchronously?(default)?
*/
????????SND_ASYNC?
=
?
0x0001
,?
/**/
/*
?play?asynchronously?
*/
????????SND_NODEFAULT?
=
?
0x0002
,?
/**/
/*
?silence?(!default)?if?sound?notfound?
*/
????????SND_LOOP?
=
?
0x0008
,?
/**/
/*
?loop?the?sound?until?nextsndPlaySound?
*/
????????SND_NOSTOP?
=
?
0x0010
,?
/**/
/*
?don't?stop?any?currently?playingsound?
*/
????????SND_NOWAIT?
=
?
0x00002000
,?
/**/
/*
?don't?wait?if?the?driver?is?busy?
*/
????????SND_FILENAME?
=
?
0x00020000
,?
/**/
/*
?name?is?file?name?
*/
????????SND_RESOURCE?
=
?
0x00040004
?
/**/
/*
?name?is?resource?name?or?atom?
*/
?
????}
?
}
posted on 2006-07-06 16:40 夢在天涯 閱讀(1342) 評論(0) 編輯 收藏 引用 所屬分類: Windows API 、DirectX

