Hallo!
Ich möchte mit VoiceRecorder etwas übers mikro aufnehmen. Mit folgender Klasse funktioniert das auch schon ganz gut, nur wenn ich die Methode Show() aufrufe, werden mir diese "standard" -buttons angezeigt, mit welchen ich dann die aufnahme starten und beenden kann.
Nun möchte ich aber, dass ich die Aufnahme selber starte, also per klick auf einen eigenen Button. Ich hätte mir gedacht dies mit SendMessage(...) zu machen, nur gibts das in C# anscheinend nicht.
Hat jemand eine Idee wie ich das sonst machen könnte?
Vielen Dank!
Daniel
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89:
| using System; using System.Data; using System.Runtime.InteropServices;
namespace xxx { public class VoiceRecorder { #region API prototypes [DllImport("voicectl.dll", EntryPoint = "VoiceRecorder_Create")] private unsafe static extern IntPtr VoiceRecorder_Create(CM_VOICE_RECORDER* voicerec);
[DllImport("coredll.dll", EntryPoint = "GetForegroundWindow")] private unsafe static extern IntPtr GetForegroundWindow(); #endregion
[StructLayout(LayoutKind.Sequential)] public unsafe struct CM_VOICE_RECORDER { public int cb; public wndStyle dwStyle; public int xPos; public int yPos; public IntPtr hwndParent; public int id; public char* lpszRecordFileName; }
public enum wndStyle : uint { VRS_NO_OKCANCEL = 0x0001, VRS_NO_NOTIFY = 0x0002, VRS_MODAL = 0x0004, VRS_NO_OK = 0x0008, VRS_NO_RECORD = 0x0010, VRS_PLAY_MODE = 0x0020, VRS_NO_MOVE = 0x0040, VRS_RECORD_MODE = 0x0080, VRS_STOP_DISMISS = 0x0100 }
private unsafe CM_VOICE_RECORDER _VoiceRec; private IntPtr _hRecorder; private string wavFile = "\\file.wav";
private IntPtr _Hwnd = (IntPtr)0;
public IntPtr Hwnd { get { return _Hwnd; } set { _VoiceRec.hwndParent = value; _Hwnd = value; } }
public unsafe VoiceRecorder() { _hRecorder = new IntPtr(); char[] temp = new char[32];
this.Hwnd = GetForegroundWindow();
Buffer.BlockCopy(wavFile.ToCharArray(), 0, temp, 0, 2 * wavFile.Length);
fixed (char* lpszFileName = temp) { _VoiceRec = new CM_VOICE_RECORDER();
_VoiceRec.hwndParent = _Hwnd; _VoiceRec.dwStyle = wndStyle.VRS_NO_MOVE | wndStyle.VRS_RECORD_MODE; _VoiceRec.cb = (int)Marshal.SizeOf(_VoiceRec); _VoiceRec.xPos = -1; _VoiceRec.yPos = -1; _VoiceRec.lpszRecordFileName = lpszFileName;
} }
public unsafe void Show() { fixed (CM_VOICE_RECORDER* _VoiceRecPtr = &_VoiceRec) { _hRecorder = VoiceRecorder_Create(_VoiceRecPtr); } } } } |