C++ Programmer's Cookbook

{C++ 基础} {C++ 高级} {C#界面,C++核心算法} {设计模式} {C#基础}

为程序增加简单的声音提示(.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  */  
    }
 
}


特点就是简单小巧,只能在windows上用啊.

posted on 2006-07-06 16:40 梦在天涯 阅读(1299) 评论(0)  编辑 收藏 引用 所属分类: Windows APIDirectX


只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   知识库   博问   管理


公告

EMail:itech001#126.com

导航

统计

  • 随笔 - 461
  • 文章 - 4
  • 评论 - 746
  • 引用 - 0

常用链接

随笔分类

随笔档案

收藏夹

Blogs

c#(csharp)

C++(cpp)

Enlish

Forums(bbs)

My self

Often go

Useful Webs

Xml/Uml/html

搜索

  •  

积分与排名

  • 积分 - 1783942
  • 排名 - 5

最新评论

阅读排行榜