|
-
Nov 3rd, 2005, 12:24 AM
#1
Thread Starter
Hyperactive Member
Does c# have any alert features
Hi again. Does c# have any kind of built in alert like a blinker, or sound ?
-
Nov 3rd, 2005, 12:26 AM
#2
Re: Does c# have any alert features
I believe the ability to play sounds was introduced in .NET 2. Where it is I'm not sure (will have to dig out the reference).
What do you mean by blinker? Like flashing the taskbar button? That can be achieved by using an API call (FlashWindowEx).
-
Nov 3rd, 2005, 12:35 AM
#3
Re: Does c# have any alert features
.NET 2.0 has the SoundPlayer and SystemSounds classes, but you can play sounds in .NET 1.x using the PlaySound API. There are numerous examples on the forums, but I'd suggest following the Mentalis.org link in my signature as they have a couple of ready-made classes to simplify the process. I'd be interested to know if the advice given so far doesn't cover what you were after as your question is a tiny bit unclear.
-
Nov 3rd, 2005, 12:49 AM
#4
Re: Does c# have any alert features
Beep:
Code:
Console.Beep();
Console.Beep(int frequency, int duration);
Flash window title/task bar button
Code:
using System.Runtime.InteropServices;
struct FLASHWINFO
{
public int cbSize;
public IntPtr hWnd;
public int dwFlags;
public int uCount;
public int dwTimeout;
}
[DllImport("user32")] private static extern int FlashWindowEx (
ref FLASHWINFO pwfi
);
const int FLASHW_STOP = 0;
const int FLASHW_CAPTION = 0x1;
const int FLASHW_TRAY = 0x2;
const int FLASHW_ALL = 0x3;
const int FLASHW_TIMER = 0x4;
const int FLASHW_TIMERNOFG = 0xC;
private void button1_Click (object sender, EventArgs e)
{
FLASHWINFO flashInfo = new FLASHWINFO();
flashInfo.cbSize = Marshal.SizeOf(flashInfo);
flashInfo.hWnd = this.Handle;
flashInfo.dwFlags = FLASHW_ALL;
flashInfo.uCount = 5;
flashInfo.dwTimeout = 0;
FlashWindowEx(ref flashInfo);
}
-
Nov 10th, 2005, 08:00 AM
#5
Thread Starter
Hyperactive Member
Re: Does c# have any alert features
Sorry I didnt explain what I was looking for. All I want is to generate some kind of beeping noise or blinker when the user makes an error. At present I'm inputting all the user errors in a message box. Is there a way to create a beeping noise or some kind of other attraction that will get the user attention?
Jennifer
-
Nov 10th, 2005, 08:03 AM
#6
Thread Starter
Hyperactive Member
Re: Does c# have any alert features
Penagate: Do you have to add any reference to use the Console.Beep? Cause I've been trying to use it but its not being recognized.
-
Nov 10th, 2005, 08:23 AM
#7
Re: Does c# have any alert features
Sorry, should have mentioned Console.Beep() is part of .NET 2.0, but not earlier unfortunately.
Wyat sort of "blinker" do you have in mind? A flashing icon or something? You can achieve that simply by using a timer and toggling the visibility state of an image on every tick event.
-
Nov 10th, 2005, 09:00 AM
#8
Thread Starter
Hyperactive Member
Re: Does c# have any alert features
The code you posted for the window task bar blinker worked fine. I think I will use that. about the beeping noise, Is there any way I could do this? I'm using .net 2003. I saw in the msdn library:
using System.Runtime.InteropServices;
public class Win32{
[DllImport("coredll.dll", CharSet=CharSet.Auto)]
public static extern bool sndPlaySound(String lpszSoundname, uint fuSound);
}
// ref
Win32.sndPlaySound("Alarm1",0);
But its not loading the coredll.dll. I tried downloading it from http://www.dll-files.com/dllindex/dl....shtml?coredll but for some reason its not loading on my framework. Does anyone know what is the problem?
Jennifer
-
Nov 10th, 2005, 09:14 AM
#9
Re: Does c# have any alert features
I don't know what that function is but you should instead use, as jmcilhinney mentioned, the PlaySound() API function which is shipped with Windows and located in "winmm.dll".
Code:
using System.Runtime.InteropServices;
[DLLImport("winmm")] static extern int PlaySoundW (
[MarshalAs(UnmanagedType.LPWStr)] string pszName,
IntPtr hModule,
uint dwFlags
)
// Usage
const uint SND_FILENAME = 0x20000;
PlaySound("c:\somewhere\mySound.wav", IntPtr.Zero, SND_FILENAME);
You can also use the constant SND_LOOP to play a sound repeatedly - it will loop until you call PlaySound() again with the pszSound parameter set to NULL.
Code:
const uint SND_LOOP = 0x8;
// Start:
PlaySound("c:\somewhere\mySound.wav", IntPtr.Zero, SND_FILENAME | SND_LOOP);
// Stop:
PlaySound(null, IntPtr.Zero, SND_FILENAME | SND_LOOP);
HTH
-
Nov 10th, 2005, 10:39 AM
#10
Thread Starter
Hyperactive Member
Re: Does c# have any alert features
-
Nov 10th, 2005, 10:46 AM
#11
Re: Does c# have any alert features
Any time 
BTW, sorry if I made some syntax mistakes in my example, I'm uninstalling my beta of C# at the moment to install the final Express 2005 version
-
Nov 10th, 2005, 04:49 PM
#12
Re: Does c# have any alert features
With regards to Console.Beep, just be aware that it plays a sound using the PC speaker and not the sound card. You're not using that now anyway but I just thought I'd point that out.
-
Nov 10th, 2005, 07:37 PM
#13
Frenzied Member
Re: Does c# have any alert features
Does c# have any kind of built in alert like a blinker, or sound ?
If you want a blinker, check out the ErrorProvider . It doesn't support sound, but the visual and tooltip are nice.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|