Results 1 to 13 of 13

Thread: Does c# have any alert features

  1. #1

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Does c# have any alert features

    Hi again. Does c# have any kind of built in alert like a blinker, or sound ?

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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).

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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);
    }

  5. #5

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    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

  6. #6

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    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.

  7. #7
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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.

  8. #8

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    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

  9. #9
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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

  10. #10

    Thread Starter
    Hyperactive Member drattansingh's Avatar
    Join Date
    Sep 2005
    Posts
    395

    Re: Does c# have any alert features

    thanks hon

  11. #11
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    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

  12. #12
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  13. #13
    Frenzied Member Mike Hildner's Avatar
    Join Date
    Jul 2002
    Location
    Des Moines, NM
    Posts
    1,690

    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
  •  



Click Here to Expand Forum to Full Width