Click here to Skip to main content
15,894,740 members
Home / Discussions / C#
   

C#

 
GeneralRe: Sending an email message through windows C#... Pin
Dennis C. Dietrich31-Dec-04 6:36
Dennis C. Dietrich31-Dec-04 6:36 
GeneralRe: Sending an email message through windows C#... Pin
new_phoenix31-Dec-04 6:47
new_phoenix31-Dec-04 6:47 
GeneralRe: Sending an email message through windows C#... Pin
Heath Stewart31-Dec-04 6:57
protectorHeath Stewart31-Dec-04 6:57 
GeneralRe: Sending an email message through windows C#... Pin
new_phoenix31-Dec-04 7:57
new_phoenix31-Dec-04 7:57 
GeneralRe: Sending an email message through windows C#... Pin
Heath Stewart31-Dec-04 8:10
protectorHeath Stewart31-Dec-04 8:10 
GeneralRe: Sending an email message through windows C#... Pin
Heath Stewart1-Jan-05 7:06
protectorHeath Stewart1-Jan-05 7:06 
GeneralMicrophone Input Level Indicator Pin
GTWebb31-Dec-04 3:50
GTWebb31-Dec-04 3:50 
GeneralRe: Microphone Input Level Indicator Pin
Heath Stewart31-Dec-04 7:44
protectorHeath Stewart31-Dec-04 7:44 
Have you looked at the Windows Multimedia[^] SDK? If you know how to P/Invoke native functions and declare structs and constants for proper marshaling it isn't too difficult (though the older APIs are a little more cumbersome to use). Read Consuming Unmanaged DLL Functions[^] and Marshaling Data with Platform Invoke[^] in the .NET Framework SDK for more information.

I threw together this simple example that shows how to handle callbacks for mixer devices. In a real-world scenario you'd want to enumerate the devices and allow the user to select one, or select a default one for them (typically 0). I also didn't take the time to check the Message.LParam property for the actual data, which you'd use to tell OnPaint what to draw for a level indicator. This should give you a pretty good start, however. Compile it and run it and start recording your voice. You should see messages being output to the console (compile with csc.exe /t:exe, not /t:winexe or you won't see console output).
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Windows.Forms;
 
public class Levels : Control
{
  int mixerId = -1;
  IntPtr hmx;
 
  const int CALLBACK_WINDOW = 0x00010000;
  const int MIXER_OBJECTF_MIXER = 0x0;
  const int MM_MIXM_CONTROL_CHANGE = 0x03d1;
 
  [DllImport("winmm.dll")]
  [return: MarshalAs(UnmanagedType.U4)]
  static extern int mixerOpen(out IntPtr phmx,
    [MarshalAs(UnmanagedType.U4)] int uMxId,
    IntPtr dwCallback, IntPtr dwInstance,
    [MarshalAs(UnmanagedType.U4)] int fdwOpen);
 
  [DllImport("winmm.dll")]
  [return: MarshalAs(UnmanagedType.U4)]
  static extern int mixerClose(IntPtr hmx);
 
  public Levels()
  {
    SetStyle(ControlStyles.AllPaintingInWmPaint |
      ControlStyles.UserPaint | ControlStyles.ResizeRedraw, true);
    SetStyle(ControlStyles.Selectable, false);
  }
 
  protected override void OnHandleCreated(EventArgs e)
  {
    base.OnHandleCreated(e);
 
    if (hmx != IntPtr.Zero)
      mixerClose(hmx);
 
    if (mixerId >= 0)
    {
      int result = mixerOpen(out hmx, mixerId, Handle, IntPtr.Zero,
        CALLBACK_WINDOW | MIXER_OBJECTF_MIXER);
      if (result != 0) throw new Win32Exception(result);
    }
  }
 
  protected override void WndProc(ref Message m)
  {
    base.WndProc(ref m);
 
    if (m.Msg == MM_MIXM_CONTROL_CHANGE)
    {
      Console.WriteLine("{0}: Received a message.", DateTime.Now);
    }
  }
 
  public int MixerId
  {
    get { return mixerId; }
    set { mixerId = value; }
  }
}
 
class Test : Form
{
  static void Main()
  {
    Application.Run(new Test());
  }
 
  Test()
  {
    Levels c = new Levels();
    Controls.Add(c);
    c.Location = new Point(8, 8);
    c.MixerId = 0;
  }
}
Hope this helps.

This posting is provided "AS IS" with no warranties, and confers no rights.

Software Design Engineer
Developer Division Sustained Engineering
Microsoft

[My Articles] [My Blog]
GeneralRe: Microphone Input Level Indicator Pin
GTWebb2-Jan-05 12:04
GTWebb2-Jan-05 12:04 
GeneralCardinal Splines Pin
thepersonof30-Dec-04 23:59
thepersonof30-Dec-04 23:59 
GeneralRe: Cardinal Splines Pin
Heath Stewart31-Dec-04 7:59
protectorHeath Stewart31-Dec-04 7:59 
Generalload data's from a xml file into a dataset for a single field alone Pin
dhol30-Dec-04 23:59
dhol30-Dec-04 23:59 
GeneralRe: load data's from a xml file into a dataset for a single field alone Pin
Heath Stewart31-Dec-04 6:52
protectorHeath Stewart31-Dec-04 6:52 
GeneralRe: load data's from a xml file into a dataset for a single field alone Pin
dhol31-Dec-04 16:58
dhol31-Dec-04 16:58 
GeneralAdding dll to the workspace Pin
Md Saleem Navalur30-Dec-04 23:21
Md Saleem Navalur30-Dec-04 23:21 
GeneralRe: Adding dll to the workspace Pin
Heath Stewart31-Dec-04 6:38
protectorHeath Stewart31-Dec-04 6:38 
GeneralRe: Adding dll to the workspace Pin
Md Saleem Navalur31-Dec-04 21:29
Md Saleem Navalur31-Dec-04 21:29 
GeneralRe: Adding dll to the workspace Pin
Heath Stewart31-Dec-04 22:49
protectorHeath Stewart31-Dec-04 22:49 
Questionhow to lock a method in class Pin
ting66830-Dec-04 22:11
ting66830-Dec-04 22:11 
AnswerRe: how to lock a method in class Pin
Robert Rohde30-Dec-04 22:19
Robert Rohde30-Dec-04 22:19 
AnswerRe: how to lock a method in class Pin
Heath Stewart31-Dec-04 6:26
protectorHeath Stewart31-Dec-04 6:26 
GeneralRe: how to lock a method in class Pin
ting6682-Jan-05 15:13
ting6682-Jan-05 15:13 
GeneralRe: how to lock a method in class Pin
Heath Stewart2-Jan-05 21:18
protectorHeath Stewart2-Jan-05 21:18 
GeneralRe: how to lock a method in class Pin
ting6683-Jan-05 14:49
ting6683-Jan-05 14:49 
GeneralRe: how to lock a method in class Pin
Heath Stewart3-Jan-05 18:47
protectorHeath Stewart3-Jan-05 18:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.