Lost Password?

Go Back   CodeCall Programming Forum > Software Development > C# Programming

Unregistered, Check out the Coder Battles in the Announcement and Game forums.

C# Programming C# (pronounced C-sharp) is a new object oriented language from Microsoft and is derived from C and C++. It also borrows a lot of concepts from Java too including garbage collection.

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-29-2007, 09:12 AM
Chan Chan is offline
Programming Professional
 
Join Date: Jun 2006
Posts: 204
Credits: 1
Rep Power: 10
Chan is on a distinguished road
Default Computer Sound

How can I add sounds to my program? I want to make a beep like I hear when the computer is first turned on. Anyone know how this is done using .NET language and C#?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Sponsored Links
  #2 (permalink)  
Old 06-29-2007, 09:39 AM
v0id's Avatar   
v0id v0id is offline
Super Moderator
 
Join Date: Apr 2007
Location: Denmark
Posts: 2,578
Last Blog:
CherryPy(thon)
Credits: 55
Rep Power: 28
v0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of lightv0id is a glorious beacon of light
Send a message via MSN to v0id
Default

Not all computers make that sound.
Those computers there do probably uses different frequencies though.

If you just want to make a simple "beep", the standard "beep" of the computer, you can simply output '\a'. It will produce a single "beep."
Code:
Console.WriteLine("\a");
If you want to be more specific about the frequency of the "beep"/tone, you have to use some library. I don't know if C#'s have some library for it. If it hasn't you can always access the speakers through the speaker port (0x61).

<edit>
I found this thread, on another forum regarding the same problem.
It might be useful for you.

Make a Beep - .NET C#
</edit>

Last edited by v0id; 06-29-2007 at 09:41 AM. Reason: I found some information...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 06-30-2007, 11:46 AM
Chan Chan is offline
Programming Professional
 
Join Date: Jun 2006
Posts: 204
Credits: 1
Rep Power: 10
Chan is on a distinguished road
Default

Bingo! The link is what I needed. Thank you!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 06-30-2007, 12:36 PM
dirkfirst dirkfirst is offline
Programming Professional
 
Join Date: May 2006
Posts: 338
Credits: 0
Rep Power: 11
dirkfirst is on a distinguished road
Default

You can also play wav files and other sound formats:

Code:
C#

dialog1.Filter = "Wav Files (*.wav)|*.wav";

C#

using System.Windows.Forms;

namespace WinSound
{
    public partial cl*** Form1 : Form
    {
        private TextBox textBox1;
        private Button button1;

        public Form1()  //constructor
        {
            InitializeComponent();
        }

        [System.Runtime.InteropServices.DllImport("winmm.DLL", EntryPoint = "PlaySound", SetLastError = true)]
        private static extern bool PlaySound(string szSound, System.IntPtr hMod, PlaySoundFlags flags);

        [System.Flags] 
        public enum PlaySoundFlags : int
        {
            SND_SYNC = 0x0000,
            SND_ASYNC = 0x0001, 
            SND_NODEFAULT = 0x0002, 
            SND_LOOP = 0x0008, 
            SND_NOSTOP = 0x0010,
            SND_NOWAIT = 0x00002000, 
            SND_FILENAME = 0x00020000, 
            SND_RESOURCE = 0x00040004 
        }

        private void button1_Click (object sender, System.EventArgs e)
        {
            OpenFileDialog dialog1 = new OpenFileDialog(); 

            dialog1.Title = "Browse to find sound file to play";
            dialog1.InitialDirectory = @"c:\";
            dialog1.Filter = "Wav Files (*.wav)|*.wav";
            dialog1.FilterIndex = 2;
            dialog1.RestoreDirectory = true;

            if(dialog1.ShowDialog() == DialogResult.OK) 
            { 
                textBox1.Text = dialog1.FileName;
                PlaySound (dialog1.FileName, new System.IntPtr(), PlaySoundFlags.SND_SYNC);
            } 
        }
    }
}
How to: Use Platform Invoke to Play a Wave File (C#)
__________________
DirkFirst
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows XP Tricks & Tips!!!!..new ones. pranky Tutorials 9 08-23-2008 03:22 PM
Computer won't start up. kool Computer Hardware 3 08-28-2007 10:18 AM
need help with simple C++ TicTacToe game with AI flupke1 C and C++ 11 08-14-2007 10:27 AM
Sounds and Sound Loop Resources TVDinner Website Design 0 03-10-2007 08:20 AM
Computer Bug: the first littlefranciscan Computer Software/OS 5 02-19-2007 08:58 PM


All times are GMT -5. The time now is 03:00 AM.

Contest Stats

Xav ........ 1322.18
MeTh0Dz|Reb0rn ........ 1053.7
morefood2001 ........ 879.43
John ........ 877.37
marwex89 ........ 869.98
WingedPanther ........ 830.24
Brandon W ........ 735.07
chili5 ........ 309.39
Steve.L ........ 239.84
dcs ........ 216.02

Contest Rules

CodeCall Goal

Goal: 100,000 Posts
Complete: 82%

Ads