■ PlaySound API 함수를 선언하는 방법을 보여준다.
▶ 예제 코드 (C#)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 |
using System; using System.Runtime.InteropServices; #region 사운드 재생하기 - PlaySound(soundName, moduleName, flag) /// <summary> /// 사운드 재생하기 /// </summary> /// <param name="soundName">사운드명</param> /// <param name="moduleName">모듈명</param> /// <param name="flag">플래그</param> /// <returns>처리 결과</returns> [DllImport("winmm", CharSet = CharSet.Auto)] private extern static int PlaySound(string soundName, IntPtr moduleName, int flag); #endregion #region 플래그 - Flag /// <summary> /// 플래그 /// </summary> private enum Flag { /// <summary> /// SND_SYNC /// </summary> /// <remarks>play synchronously (default)</remarks> SND_SYNC = 0x0000, /// <summary> /// SND_ASYNC /// </summary> /// <remarks>play asynchronously</remarks> SND_ASYNC = 0x0001, /// <summary> /// SND_NODEFAULT /// </summary> /// <remarks>silence (!default) if sound not found</remarks> SND_NODEFAULT = 0x0002, /// <summary> /// SND_MEMORY /// </summary> /// <remarks>soundName points to a memory file</remarks> SND_MEMORY = 0x0004, /// <summary> /// loop the sound until next PlaySound /// </summary> SND_LOOP = 0x0008, /// <summary> /// SND_NOSTOP /// </summary> /// <remarks>don't stop any currently playing sound</remarks> SND_NOSTOP = 0x0010, /// <summary> /// SND_NOWAIT /// </summary> /// <remarks>don't wait if the driver is busy</remarks> SND_NOWAIT = 0x00002000, /// <summary> /// SND_ALIAS /// </summary> /// <remarks>name is a registry alias</remarks> SND_ALIAS = 0x00010000, /// <summary> /// SND_ALIAS_ID /// </summary> /// <remarks>alias is a predefined ID</remarks> SND_ALIAS_ID = 0x00110000, /// <summary> /// SND_FILENAME /// </summary> /// <remarks>name is file name</remarks> SND_FILENAME = 0x00020000, /// <summary> /// SND_RESOURCE /// </summary> /// <remarks>name is resource name or atom</remarks> SND_RESOURCE = 0x00040004 } #endregion |