Laden...

Ich hab ne Klasse geschrieben, wohin damit?

Erstellt von SimonKnight6600 vor 18 Jahren Letzter Beitrag vor 18 Jahren 11.584 Views
S
SimonKnight6600 Themenstarter:in
709 Beiträge seit 2005
vor 18 Jahren
Ich hab ne Klasse geschrieben, wohin damit?

Ich hab ne einfache Klasse geschrieben, die es ermöglicht, einen Windows Biepton auszugeben. Soll ich die Klasse an activesphere schicken? (Ist bei SourceForge als Admin eingetragen...)

1.549 Beiträge seit 2004
vor 18 Jahren

Nein du solt die klasse erst mal hier posten dann schauen die anderen sie sich an und entscheiden ob sie reinkommt

Wir Arbeiten eigendlich nicht wir nehmen nur das geld

S
SimonKnight6600 Themenstarter:in
709 Beiträge seit 2005
vor 18 Jahren

Ok, ist halt nur ne ganz kleine Klasse.

 
#region myCSHARP Library

// -----------------------------------------------------------------------------
// The contents of this file are subject to the GNU Lesser General Public Licens 
// (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
// [URL]http://www.gnu.org/copyleft/lesser.html[/URL]
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
// the specific language governing rights and limitations under the License.
//
// Copyright 2005 - myCSHARP Team - All Rights Reserved.
// Authors:
// - Schweiger Simon <simon.schweiger@tnr.at>
//
// Contributors: none
//
// Known Issues:
// - The BeepType Question does not run.
//
// You may retrieve the latest version of this file at the myCSHARP
// home page, located at [URL]http://mycsharp.sourceforge.net[/URL]
//
//------------------------------------------------------------------------------------
// Version: 1.0
// Description: Contains a method which can play the windows system sounds
//------------------------------------------------------------------------------------

#endregion

using System;
using System.Runtime.InteropServices;

namespace mycsharp.Media.Audio
{
	/// <summary>
	/// Contains a method which can play the windows system sounds
	/// </summary>
	public class Beep
	{
		[DllImport("User32.dll")]
		private static extern int MessageBeep(uint uType);
		
		private const uint MB_SIMPLE_BEEP = 1;
		private const uint MB_ICON_HAND = 0x00000010;
		private const uint MB_ICON_QUESTION = 0x00000020;
		private const uint MB_ICON_EXCLAMATION = 0x00000030;
		private const uint MB_ICON_ASTERISK = 0x00000040;
		
		public enum BeepType : uint
		{
			Simple = MB_SIMPLE_BEEP,
			Error = MB_ICON_HAND,
			Exclamation = MB_ICON_EXCLAMATION,
			Question = MB_ICON_QUESTION,
			Information = MB_ICON_ASTERISK
		}
		/// <summary>
		/// Plays a Windows sound
		/// </summary>
		/// <param name="beepType">The sound to play</param>
		/// <returns></returns>
		public static bool WindowsBeep(BeepType beepType)
		{
			return (MessageBeep((uint)beepType) != 0);
		}
		
	}
}


Was sagt ihr dazu?
PS:
Die Klasse wurde von einen Noob geschrieben 😁

N
4.644 Beiträge seit 2004
vor 18 Jahren

Selber geschrieben oder bei google "messagebeep c#" eingeben? 😉
Ich will Dir aber nicht zu nahe treten. 😉

S
SimonKnight6600 Themenstarter:in
709 Beiträge seit 2005
vor 18 Jahren
Wird die Klasse aufgenommen?

Den API Aufruf habe ich natürlich aus dem Netz 😄. Aber den Rest habe ich selber geschrieben. (Also die Methode WindowsBeep() 😁 )

EDIT:

Wird die Klasse jetzt aufgenommen?

1.549 Beiträge seit 2004
vor 18 Jahren

Jetzt wart mal eins nach dem anderen deine Klasse ist jetzt noch nicht mal 24 Stunden Gepostet aber ich hätte gegen eine Aufnahme nichts

Wir Arbeiten eigendlich nicht wir nehmen nur das geld

S
SimonKnight6600 Themenstarter:in
709 Beiträge seit 2005
vor 18 Jahren

Wer bestimmt eigentlich, ob die Klasse aufgenommen wird?

1.549 Beiträge seit 2004
vor 18 Jahren

Nicht jemand direkt sonder wir alle zusammen wenn niemand einen Grund hat die Klasse nicht aufzunehmen dann nehmen wir sie auf

Wir Arbeiten eigendlich nicht wir nehmen nur das geld

Q
992 Beiträge seit 2005
vor 18 Jahren

Habe ein paar Änderungen gemacht. Es muss auf jeden Fall noch Error-Handling rein(es gibt auch Leute ohne Soundkarte zum Beispiel).

Ich habe nochmal ein kleines Konstrukt dazu gebastelt. Dadurch kann man Beep-Töne mit Dauer und Frequenz über den PC-Speaker ausgeben.
Wird in einem neuen Thread gestartet, damit das nicht das gesamte Programm blockiert.

So und nun schlagt mich ob meines schlechten Stils.

Grüße Christoph


#region myCSHARP Library

// -----------------------------------------------------------------------------
// The contents of this file are subject to the GNU Lesser General Public Licens
// (the "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
// [URL]http://www.gnu.org/copyleft/lesser.html[/URL]
//
// Software distributed under the License is distributed on an "AS IS" basis,
// WITHOUT WARRANTY OF ANY KIND, either expressed or implied. See the License for
// the specific language governing rights and limitations under the License.
//
// Copyright 2005 - myCSHARP Team - All Rights Reserved.
// Authors:
// - Schweiger Simon <simon.schweiger@tnr.at>
//
// Contributors: none
//
// Known Issues:
// - The BeepType Question does not run.
//
// You may retrieve the latest version of this file at the myCSHARP
// home page, located at [URL]http://mycsharp.sourceforge.net[/URL]
//
//------------------------------------------------------------------------------------
// Version: 1.0
// Description: Contains a method which can play the windows system sounds
//------------------------------------------------------------------------------------

#endregion

using System;
using System.Runtime.InteropServices;
using System.Threading;

namespace mycsharp.Media.Audio
{
	/// <summary>
	/// Contains a method which can play the windows system sounds
	/// </summary>
	public class BeepOutput
	{
		[DllImport("User32.dll")]
		private static extern int MessageBeep(uint uType);

		[DllImport("Kernel32.dll")]
		private static extern bool Beep(uint freq,uint length);

		
		private static uint _freq;
		private static uint _length;
        
		private const uint MB_SIMPLE_BEEP = 1;
		private const uint MB_ICON_HAND = 0x00000010;
		private const uint MB_ICON_QUESTION = 0x00000020;
		private const uint MB_ICON_EXCLAMATION = 0x00000030;
		private const uint MB_ICON_ASTERISK = 0x00000040;
        
		public enum BeepType : uint
		{
			Simple = MB_SIMPLE_BEEP,
			Error = MB_ICON_HAND,
			Exclamation = MB_ICON_EXCLAMATION,
			Question = MB_ICON_QUESTION,
			Information = MB_ICON_ASTERISK
		}
		/// <summary>
		/// Plays a Windows sound
		/// </summary>
		/// <param name="beepType">The sound to play</param>
		/// <returns></returns>
		public static bool WindowsBeep(BeepType beepType)
		{
			return (MessageBeep((uint)beepType) != 0);
		}


		/// <summary>
		/// Plays a Beep using the PC-Speaker
		/// </summary>
		/// <param name="freq">The frequency in Hz</param>
		/// <param name="length">The length in ms</param>
		public static void WindowsBeep(uint freq,uint length)
		{
			_freq = freq;
			_length = length;
                     
			Thread NewThread = new Thread(new ThreadStart(Beepshort));
			NewThread.Start();
		}

		private static void Beepshort()
		{
			Beep(_freq,_length);
		}
        
	}
}

S
SimonKnight6600 Themenstarter:in
709 Beiträge seit 2005
vor 18 Jahren

Original von Quallo
Habe ein paar Änderungen gemacht. Es muss auf jeden Fall noch Error-Handling rein(es gibt auch Leute ohne Soundkarte zum Beispiel).

Wenn jemand keine Soundkarte hat, wird der Sound über den PC-Sneaker ausgegeben. (Allerdings nur der Standardbeepton)

S
SimonKnight6600 Themenstarter:in
709 Beiträge seit 2005
vor 18 Jahren

Wie stehts eigentlich mit dem Performance von try... catch? Giltet hier die Devise "Je mehr desto besser"? Denn eine Fehlerbehandlung müsste schon her, es könnte ja interne Fehler geben...

1.549 Beiträge seit 2004
vor 18 Jahren

Ich denke bei so einer kleinen klasse von der man im Normalfall nur eine Instanz hat macht es wirklich noch nichts aus

Wir Arbeiten eigendlich nicht wir nehmen nur das geld

S
SimonKnight6600 Themenstarter:in
709 Beiträge seit 2005
vor 18 Jahren

Danke für die Info!
(Ich weiß, das weicht jetzt wieder völlig vom Thema ab, aber ich will dafür keinen neune Thread aufmachen)
Wie funktioniert das eigentlich jetzt mit Sourceforge? Quallo hat die Klasse ja ein wenig "getunt". Die Klassen werden hochgeladen, und wenn jemand eine Verbesserung machen mächte (z.B. das try - catch einfügen) macht er die Änderungen über das Versionssystem und jedes Monat wird die Dll neu compiliert.
Momentan ist das CVS ja noch ziemlich leer. (Keine Klassen hochgeladen) Wenn die Klassen hochgeladen werden, kann jeder sie verbessern. (Kleine Verbesserungen zu machen ist leichter, als eine eigene Klasse zu schreiben). Kann man als Mitentwickler auch seine Klassen hochladen?

mfg.
SimonKnight6600
(Ich weíß, dass sind jetzt viele Fragen, aber vieleicht helfen sie auch anderen 😉)