|
Hello,
I'm building an application which has an option to play a sound with the extern PlaySound method.
With the code below the PlaySound method is working
<br />
string fileName = @"C:\Documents and Settings\User\My documents\Visual Studio 2005\Projects\Alarm\Alarm\Resources\attention.wav";<br />
PlaySound(fileName, 0, 1);<br />
If I execute the program on an other computer the path will be different. So I need an function that will get the .wav file from my folder Resources. The standard way to access an embedded resource is to use the Assembly class's GetManifestResource* methods. But I can't get it to work properly.
This is proberly a very stupid question but i'm just a beginner and can't figure it out.
Can someone please help me out?
Thanks
|
|
|
|
|
JustRonald wrote: But I can't get it to work properly.
JustRonald wrote: but i'm just a beginner and can't figure it out.
If you are getting some error message you need to post that along with the relevant code. Read the first post in the forum titled "How to get an answer to your question".
led mike
|
|
|
|
|
There's an example here[^]
The only problem I've found is you need to specify the file's location as
"yournamespace.Resources.filename.ext"
e.g.
GetManifestResourceStream("My_App.Resources.new.wav");
Edit: You needto use Winmm.dll not Coredll.dll
Improved solution/example below
Dave
modified on Monday, March 3, 2008 2:51 PM
|
|
|
|
|
|
I thought this was something interesting that I could maybe use so I've had a play and the example below works (ringin.wav from C:\Windows\Media added to resources and BuildAction property set to Embedded Resource).
using System;
using System.IO;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
Load += new EventHandler(Form1_Load);
}
void Form1_Load(object sender, EventArgs e)
{
Stream wave = Assembly.GetExecutingAssembly().
GetManifestResourceStream(
MethodBase.GetCurrentMethod().
DeclaringType.Namespace + ".Resources." + "ringin.wav");
Byte[] waveData = new Byte[wave.Length];
wave.Read(waveData, 0, (int)wave.Length);
PlaySound(waveData, IntPtr.Zero, SoundFlags.SND_ASYNC | SoundFlags.SND_MEMORY);
}
enum SoundFlags
{
SND_SYNC = 0x0000,
SND_ASYNC = 0x0001,
SND_MEMORY = 0x0004,
SND_NODEFAULT = 0x0002,
SND_LOOP = 0x0008,
SND_NOSTOP = 0x0010,
SND_NOWAIT = 0x00002000,
SND_FILENAME = 0x00020000,
SND_RESOURCE = 0x00040004
}
[DllImport("winmm.dll")]
static extern bool PlaySound(byte[] pszSound, IntPtr hmod, SoundFlags fdwSound);
}
}
I've used SoundFlags.SND_ASYNC as it's in the load event but if you want it in FormClosing for example use SoundFlags.SND_SYNC
Dave
|
|
|
|
|
Hi Ronald,
there are some ways to solve your problem:
1. you can distribute your wav file in a specific subfolder of your application, e.g. Sounds. Then you just set the filename variable to the following value:
string filename = Application.StartupPath + @"Sounds\attention.wav";
Don't forget to include using System.Windows.Forms. or type the namespace with the Application.StartupPath
2. You add the audio file as manifest into your exe. Then you need to call the following function:
System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(typeof(Program), "attention.wav")
Note that you get a System.IO.Stream , so maybe need to save it in a temporary file and then call your PlaySound method (I don't know if your function supports a stream object as a parameter)
So, these are the ways, I retrieved quickly from my mind at 23:17 (German time)
PS: In the second solution I wrote typeof(Program). Program is a class generated by VisualStudio when you create a new project, so I used this here
I hope I could help you
_____________________________
The force of .NET is with me!
|
|
|
|
|
Does anyone know/have any control like calender, but only show month and year. So the user only need to select the month and date. I'm in a hurry and don't want to create my own control. tHanks.
|
|
|
|
|
If you don't have the day in the date, then the whole calendar paradigm doesn't work. In this case, you're better off with 2 combos. One for month and one for year.
|
|
|
|
|
Thank for the quick reply. But I'm hoping to find somebody who have made control consisting of two combobox , one for month and one for year.
|
|
|
|
|
To be honest, it'll take you longer to wait for the reply than it would to code it yourself. It's effectively two databound combos, so why not do it yourself.
|
|
|
|
|
Well, good idea. I'm starting to doing it by myself. It isn't as hard as I thought it will be.
|
|
|
|
|
Yulianto. wrote: I'm starting to doing it by myself. It isn't as hard as I thought it will be.
That's the spirit.
|
|
|
|
|
|
fellas
i was wondering if i could pull something out of a text file at a given index, i can pull a certain amount of char's like this code, i want to pull a full line like you would when pulling something out of a list box like selecteditems(0) and so fore
TextReader myFile= new StreamReader("file.txt");
string index = myFile.ReadToEnd().Remove(51);
that will remove the first 51 chars, which is the length of the first line but how would i do second and third line or if they were longer than 51 chars
anybody got any ideas
thanks for any help
j2s
|
|
|
|
|
using (System.IO.StreamReader sr = new System.IO.StreamReader(@"c:\data.txt"))
{
sr.BaseStream.Position = 5;
sr.Read();
MessageBox.Show(sr.ReadLine());
}
Why don't you store the lines in string[] or something, so that you read the file once.
string[] lines = System.IO.File.ReadAllLines(@"c:\data.txt");
Eslam Afifi
modified on Monday, March 3, 2008 12:22 PM
|
|
|
|
|
how to add database fields to a crystal report in .net 2005
in code instead open Window field explorer and menu database expert
|
|
|
|
|
Hello,
I have a question regarding a row selection of the datagridview control.
How can I prevent that the user can click on another row than the row where my current cell is (in editing mode)
So I have a row with 4 cell's for example, the row is selected, and the first cell is in editing mode.
When I click another row other than the one I'm editing, the focus goes to this other row.
How can I prevent that in code?
Thank you!
Greetings
|
|
|
|
|
use this, to know about editing mode
DGV[ColumnIndex, RowIndex].IsInEditMode
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Thank you,
I can figure out if the cell is in edit mode, but if this is true, I may not be able to select other rows than the row where my editing cell is in .. ?
Is there a way I can do that?
Thanks
|
|
|
|
|
there are vary events that can be use, try
CellLeave and CellEnter
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
I've used this events, and with those, I can capture if I clicked on the other row etc.
But how can I prevent that the row I've clicked is not selected?
I've tried:
if (e.RowIndex != previous_line)
{
// There may not be clicked
MessageBox.Show("You are already editing a machine");
grid_machines.Rows[previous_line].Selected = true;
}
this results in the previous line, which is now selected again, but the arrow on the rowheader is still on the 'new' clicked row. So my old line is selected, but the new line has the editing arrow..?
Thank you
|
|
|
|
|
write
dataGridView1.SelectedCells = null;
or
dataGridView1.SelectedRows = null;
before select the previous row
hope it will work
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Those properties are get only, not set?
I understand what you mean though.
Would it be possible to override the event where the 'selection' of the row happens?
So that I look for my conditions, if it's false, then select the new clicked row ...?
Thank you
|
|
|
|
|
ooppss...i didnt check them, but here is working one
DGV.ClearSelection();
TVMU^P[[IGIOQHG^JSH`A#@`RFJ\c^JPL>;"[,*/|+&WLEZGc`AFXc!L
%^]*IRXD#@GKCQ`R\^SF_WcHbORY87??6?N8?BcRAV\Z^&SU~%CSWQ@#2
W_AD`EPABIKRDFVS)EVLQK)JKSQXUFYK[M`UKs*$GwU#(QDXBER@CBN%
Rs0~53%eYrd8mt^7Z6]iTF+(EWfJ9zaK-i?TV.C\y<p?jxsg-b$f4ia>
--------------------------------------------------------
128 bit encrypted signature, crack if you can
|
|
|
|
|
Hi all,
When I double click on a ListViewItem, I don't want the checked property
of the item to change. By default, this does happen and I can't see a way
of disabling this behaviour.
Thanks in advance.
amit
|
|
|
|