티스토리 뷰
How do I beep the computer's speaker in a Windows Form application
이것 이외의 다른 방법은...
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace Usecase
{
/// <summary>
/// 사운드
/// </summary>
public class WPlaySound
{
[DllImport("winmm.dll", EntryPoint="PlaySound",CharSet=CharSet.Auto)]
private static extern int PlaySound(String pszSound, int hmod, int falgs);
public enum SND
{
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 pre d ID */
SND_FILENAME ? ? ? ?= 0x00020000, /* name is file name */
SND_RESOURCE ? ? ? ?= 0x00040004, /* name is resource name or atom */
SND_PURGE ? ? ? ?= 0x0040, ?/* purge non-static events for task */
SND_APPLICATION ? ? ? ?= 0x0080 ?/* look for application specific association */
}
/// <summary>
/// Wave 파일 재생
/// </summary>
/// <param name="pszSound">파일 경로</param>
public static void PlaySound(String pszSound)
{
if(File.Exists(pszSound))
{
PlaySound(pszSound,0,(int) (SND.SND_ASYNC | SND.SND_FILENAME |
SND.SND_NOWAIT));
}
}
/// <summary>
/// 시스템 사운드 이벤트 HKEY_CURRENT_USERAppEventsSchemesApps.Default
/// </summary>
/// <param name="pszSound">이벤트 이름</param>
public static void PlaySoundEvent(String pszSound)
{
PlaySound(pszSound,0,(int) (SND.SND_ASYNC | SND.SND_ALIAS | SND.SND_NOWAIT));
}
}
}
There is no Windows Form function to beep your computer's speaker. But you can just invoke the Win32 API MessageBeep. |
using System.Runtime.InteropServices; |
... |
[DllImport("user32.dll")] |
public static extern int MessageBeep(uint n); |
private void button2_Click(object sender, System.EventArgs e) |
{ |
MessageBeep(0x0); |
} |
Another method (suggested by msauper@sauper.com on microsoft.public.dotnet.framework.windowsforms) |
Reference the VB.NET runtime support and just use the Beep() method. |
The method is in: |
Microsoft.Visual Basic.NET Runtime |
The method is: |
Microsoft.VisualBasic.Interaction.Beep(); |
이것 이외의 다른 방법은...
using System;
using System.Runtime.InteropServices;
using System.IO;
namespace Usecase
{
/// <summary>
/// 사운드
/// </summary>
public class WPlaySound
{
[DllImport("winmm.dll", EntryPoint="PlaySound",CharSet=CharSet.Auto)]
private static extern int PlaySound(String pszSound, int hmod, int falgs);
public enum SND
{
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 pre d ID */
SND_FILENAME ? ? ? ?= 0x00020000, /* name is file name */
SND_RESOURCE ? ? ? ?= 0x00040004, /* name is resource name or atom */
SND_PURGE ? ? ? ?= 0x0040, ?/* purge non-static events for task */
SND_APPLICATION ? ? ? ?= 0x0080 ?/* look for application specific association */
}
/// <summary>
/// Wave 파일 재생
/// </summary>
/// <param name="pszSound">파일 경로</param>
public static void PlaySound(String pszSound)
{
if(File.Exists(pszSound))
{
PlaySound(pszSound,0,(int) (SND.SND_ASYNC | SND.SND_FILENAME |
SND.SND_NOWAIT));
}
}
/// <summary>
/// 시스템 사운드 이벤트 HKEY_CURRENT_USERAppEventsSchemesApps.Default
/// </summary>
/// <param name="pszSound">이벤트 이름</param>
public static void PlaySoundEvent(String pszSound)
{
PlaySound(pszSound,0,(int) (SND.SND_ASYNC | SND.SND_ALIAS | SND.SND_NOWAIT));
}
}
}
'Application > C#' 카테고리의 다른 글
A simple Multi-Threaded Server Client Instant Messenger Application (1) | 2008.01.28 |
---|---|
MyDownloader: A Multi-thread C# Segmented Download Manager (15) | 2008.01.28 |
폼 새창 로드시 포커스 문제? (0) | 2008.01.28 |
Playing AVI Files using DirectX 9 with C# and .NET (29) | 2008.01.28 |
Some Cool Tips for .NET (0) | 2007.01.01 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
TAG
- Assembly
- humor
- wallpaper
- Life News
- Linux
- 야마꼬툰
- diary
- Military
- 프리랜서로 살아남는 법
- Mabinogi
- Information Processor
- Web Programming
- Reverse Engineering
- Network Inspector
- network
- win32
- USB Lecture
- 3D Engine
- console
- Tech News
- 짤방 및 아이콘
- 나비효과
- medical
- 막장로그
- Embedded System
- WDB
- cartoon
- C#
- BadCode
- Battle
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함