우선 아래의 네임스페이스를 추가한다.
using System.Reflection;
using System.IO;
아래와 같이 해 주면 프로그램이 시작되는 폴더를 받아올수 있습니다.
string fullAppName = Assembly.GetExecutingAssembly().GetName().CodeBase;
string fullAppPath = Path.GetDirectoryName(fullAppName);
즉 현재 실행중인 프로그램의 전체 경로를 구하고
그 값에서 폴더정보를 얻는다.
'Compact Framework'에 해당되는 글 2건
- 2006/10/19 hancem Compat Framework에서 프로그램 실행중인 폴더 얻기
- 2006/09/27 hancem Compact Framework 에서 소리내기
using System;
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.IO;
public class Sound{
private byte[] m_soundBytes;
private string m_fileName;
private enum Flags {
SND_SYNC = 0x0000, /* play synchronously (default) */
SND_ASYNC = 0x0001, /* play asynchronously */
SND_NODEFAULT = 0x0002, /* silence (!default) if sound not found */
SND_MEMORY = 0x0004, /* pszSound points to a memory file */
SND_LOOP = 0x0008, /* loop the sound until next sndPlaySound */
SND_NOSTOP = 0x0010, /* don't stop any currently playing sound */
SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
SND_ALIAS = 0x00010000, /* name is a registry alias */
SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */
SND_FILENAME = 0x00020000, /* name is file name */
SND_RESOURCE = 0x00040004 /* name is resource name or atom */
}
[DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]
private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags);
[DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]
private extern static int WCE_PlaySoundBytes (byte[] szSound, IntPtr hMod, int flags);
public Sound (string fileName) { m_fileName = fileName; }
public Sound(Stream stream) {
// read the data from the stream
m_soundBytes = new byte [stream.Length];
stream.Read(m_soundBytes, 0,(int)stream.Length);
}
public void Play () {
// if a file name has been registered, call WCE_PlaySound,
// otherwise call WCE_PlaySoundBytes
if (m_fileName != null)
WCE_PlaySound(m_fileName, IntPtr.Zero,
(int) (Flags.SND_ASYNC | Flags.SND_FILENAME));
else
WCE_PlaySoundBytes (m_soundBytes, IntPtr.Zero,
(int) (Flags.SND_ASYNC | Flags.SND_MEMORY));
}
}
Sound sound =
new Sound(Assembly.GetExecutingAssembly).GetManifestResourceStream("SoundSample.chimes.wav"));
sound.Play();
}
using System.Runtime.InteropServices;
using System.Diagnostics;
using System.Threading;
using System.IO;
public class Sound{
private byte[] m_soundBytes;
private string m_fileName;
private enum Flags {
SND_SYNC = 0x0000, /* play synchronously (default) */
SND_ASYNC = 0x0001, /* play asynchronously */
SND_NODEFAULT = 0x0002, /* silence (!default) if sound not found */
SND_MEMORY = 0x0004, /* pszSound points to a memory file */
SND_LOOP = 0x0008, /* loop the sound until next sndPlaySound */
SND_NOSTOP = 0x0010, /* don't stop any currently playing sound */
SND_NOWAIT = 0x00002000, /* don't wait if the driver is busy */
SND_ALIAS = 0x00010000, /* name is a registry alias */
SND_ALIAS_ID = 0x00110000, /* alias is a predefined ID */
SND_FILENAME = 0x00020000, /* name is file name */
SND_RESOURCE = 0x00040004 /* name is resource name or atom */
}
[DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]
private extern static int WCE_PlaySound(string szSound, IntPtr hMod, int flags);
[DllImport("CoreDll.DLL", EntryPoint="PlaySound", SetLastError=true)]
private extern static int WCE_PlaySoundBytes (byte[] szSound, IntPtr hMod, int flags);
public Sound (string fileName) { m_fileName = fileName; }
public Sound(Stream stream) {
// read the data from the stream
m_soundBytes = new byte [stream.Length];
stream.Read(m_soundBytes, 0,(int)stream.Length);
}
public void Play () {
// if a file name has been registered, call WCE_PlaySound,
// otherwise call WCE_PlaySoundBytes
if (m_fileName != null)
WCE_PlaySound(m_fileName, IntPtr.Zero,
(int) (Flags.SND_ASYNC | Flags.SND_FILENAME));
else
WCE_PlaySoundBytes (m_soundBytes, IntPtr.Zero,
(int) (Flags.SND_ASYNC | Flags.SND_MEMORY));
}
}
위와 같은 클래스로 사용할 수 있습니다.private void btnEmbedded_Click(object sender, System.EventArgs e) {
사용 방법은 예를 들어..
Sound sound =
new Sound(Assembly.GetExecutingAssembly).GetManifestResourceStream("SoundSample.chimes.wav"));
sound.Play();
}
private void btnFile_Click(object sender, System.EventArgs e) {
Sound sound = new Sound ("Program Files\\SoundSample\\chord.wav");
sound.Play();
}
위와 같은 방법으로 사용할 수 있습니다.
원문 : http://www.devpia.com/Forum/BoardView.aspx?no=153&ref=153&forumname=MOBILE_LEC&stype=MBL&KeyW=%b4%e5%b3%dd&KeyR=title (새 창으로 열기)






46666
45
81










댓글을 달아 주세요