Top-Themen

AppleEntwicklungHardwareInternetLinuxMicrosoftMultimediaNetzwerkeOff TopicSicherheitSonstige SystemeVirtualisierungWeiterbildungZusammenarbeit

Aktuelle Themen

Administrator.de FeedbackApache ServerAppleAssemblerAudioAusbildungAuslandBackupBasicBatch & ShellBenchmarksBibliotheken & ToolkitsBlogsCloud-DiensteClusterCMSCPU, RAM, MainboardsCSSC und C++DatenbankenDatenschutzDebianDigitiales FernsehenDNSDrucker und ScannerDSL, VDSLE-BooksE-BusinessE-MailEntwicklungErkennung und -AbwehrExchange ServerFestplatten, SSD, RaidFirewallFlatratesGoogle AndroidGrafikGrafikkarten & MonitoreGroupwareHardwareHosting & HousingHTMLHumor (lol)Hyper-VIconsIDE & EditorenInformationsdiensteInstallationInstant MessagingInternetInternet DomäneniOSISDN & AnaloganschlüsseiTunesJavaJavaScriptKiXtartKVMLAN, WAN, WirelessLinuxLinux DesktopLinux NetzwerkLinux ToolsLinux UserverwaltungLizenzierungMac OS XMicrosoftMicrosoft OfficeMikroTik RouterOSMonitoringMultimediaMultimedia & ZubehörNetzwerkeNetzwerkgrundlagenNetzwerkmanagementNetzwerkprotokolleNotebook & ZubehörNovell NetwareOff TopicOpenOffice, LibreOfficeOutlook & MailPapierkorbPascal und DelphiPeripheriegerätePerlPHPPythonRechtliche FragenRedHat, CentOS, FedoraRouter & RoutingSambaSAN, NAS, DASSchriftartenSchulung & TrainingSEOServerServer-HardwareSicherheitSicherheits-ToolsSicherheitsgrundlagenSolarisSonstige SystemeSoziale NetzwerkeSpeicherkartenStudentenjobs & PraktikumSuche ProjektpartnerSuseSwitche und HubsTipps & TricksTK-Netze & GeräteUbuntuUMTS, EDGE & GPRSUtilitiesVB for ApplicationsVerschlüsselung & ZertifikateVideo & StreamingViren und TrojanerVirtualisierungVisual StudioVmwareVoice over IPWebbrowserWebentwicklungWeiterbildungWindows 7Windows 8Windows 10Windows InstallationWindows MobileWindows NetzwerkWindows ServerWindows SystemdateienWindows ToolsWindows UpdateWindows UserverwaltungWindows VistaWindows XPXenserverXMLZusammenarbeit
GELÖST

Wecker programmieren

Frage Entwicklung C und C++

Mitglied: Michi262

Michi262 (Level 1) - Jetzt verbinden

02.12.2007, aktualisiert 03.12.2007, 10497 Aufrufe, 2 Kommentare

erstmal Hi@all

ich würde mir gerne einen Wecker programmieren. Leider kenn ich mich nocht nicht wirklich aus denn ich lerne gerade erst noch C++.

Also ich würde gerne einen Wecker programmiern egal mit welcher Programmiersprache. Er sollte in Etwa so aussehen wie auf dem Bild am ende. Wobei in den Fenster mit den Zahlen klicken möglich sein sollte. Als Alarmzeichen soll dann irgendein Wecksignal kommen, das als mp3 oder wav vorliegt.

Ist das Möglich?

Könne mir evtl. wer diesen Cod machen?

Danke schon mal im Vorraus

940d28c3f40aa3bff8ec117ae93494c9-wecker - Klicke auf das Bild, um es zu vergrößern
Mitglied: gnarff
02.12.2007 um 16:07 Uhr
Davon abgesehen, dass das Schlafen in Räumen mit laufenden Rechnern ein schlechtes Chi erzeugt, gesundheitsschädlich ist und außerdem der Erwerb eines Radioweckers sicher unaufwendiger wäre; und nicht zuletzt, weil DU ja eigentlich den Wecker selbst programmieren wolltest...hier der Sourcecode in C#:

01.
using System; 
02.
using System.Collections.Generic; 
03.
using System.ComponentModel; 
04.
using System.Data; 
05.
using System.Drawing; 
06.
using System.Text; 
07.
using System.Windows.Forms; 
08.
using System.Runtime.InteropServices; 
09.
 
10.
namespace MP3AlarmClock 
11.
12.
    public partial class Form1 : Form 
13.
    {        
14.
        [DllImport("winmm.dll")] 
15.
        private static extern long mciSendString(string strCommand, StringBuilder strReturn, int iReturnLength, IntPtr hwndCallback); 
16.
 
17.
        #region Private Variables 
18.
        // Private variables //////////////////////////////////////////////////////// 
19.
        string fileName; 
20.
        uint alarmTimeout; 
21.
        char theLetter; 
22.
        bool alarmInProgress; 
23.
        uint holdTime; 
24.
        #endregion 
25.
 
26.
        #region Constructors 
27.
        // Constructors ///////////////////////////////////////////////////////////// 
28.
        public Form1() 
29.
30.
            InitializeComponent(); 
31.
            fileName = ""; 
32.
            alarmInProgress = false; 
33.
34.
        #endregion 
35.
 
36.
        #region Private Methods 
37.
        // Private Methods ////////////////////////////////////////////////////////// 
38.
        private void playFile() 
39.
40.
            // Opens and play an MP3 file on repeat using MCI 
41.
            string Pcommand; 
42.
            Pcommand = "open \"" + fileName + "\" type mpegvideo alias MediaFile"; 
43.
            mciSendString(Pcommand, null, 0, IntPtr.Zero); 
44.
            Pcommand = "play MediaFile REPEAT"; 
45.
            mciSendString(Pcommand, null, 0, IntPtr.Zero); 
46.
        } // end playFile 
47.
 
48.
        private void stopFile() 
49.
50.
            // Stops and closes a media file being played using MCI 
51.
            string Pcommand = "stop MediaFile"; 
52.
            mciSendString(Pcommand, null, 0, IntPtr.Zero); 
53.
            Pcommand = "close MediaFile"; 
54.
            mciSendString(Pcommand, null, 0, IntPtr.Zero); 
55.
        } // end stopFile 
56.
        #endregion 
57.
 
58.
        #region Event Handlers 
59.
        // Event Handlers ////////////////////////////////////////////////////////// 
60.
        private void btnPlay_Click(object sender, EventArgs e) 
61.
62.
            // If the user clicks play, play some music 
63.
            playFile(); 
64.
        } // end btnPlay_Click 
65.
 
66.
        private void btnBrowse_Click(object sender, EventArgs e) 
67.
68.
            // Set up our file open dialog box 
69.
            OpenFileDialog myFD = new OpenFileDialog(); 
70.
            myFD.DefaultExt = "mp3"; 
71.
            myFD.Multiselect = false; 
72.
            myFD.CheckPathExists = true; 
73.
            myFD.CheckFileExists = true; 
74.
            myFD.AddExtension = true; 
75.
            myFD.ValidateNames = true; 
76.
            myFD.Title = "Find the file you want to wake up to"; 
77.
 
78.
            // Show the user the dialog.  If the user clicks on "Cancel" 
79.
            // we'll do nothing and keep the previous file selection, if any. 
80.
            if (myFD.ShowDialog() == DialogResult.OK) 
81.
82.
                fileName = myFD.FileName; 
83.
                txtFileName.Text = fileName; 
84.
            } // end if 
85.
        } // end btnBrowse_Click 
86.
 
87.
        private void btnStop_Click(object sender, EventArgs e) 
88.
89.
            // If the user clicks "Stop," we stop the music. 
90.
            stopFile(); 
91.
        } // end btnStop_Click 
92.
 
93.
        private void btnSetAlarm_Click(object sender, EventArgs e) 
94.
95.
            // If the user hasn't specified a file name, we can't play anything 
96.
            // can we?  So we'll just point out that they need to tell us what to 
97.
            // play and abort setting the alarm. 
98.
            if (txtFileName.Text == "") 
99.
100.
                MessageBox.Show("Please choose a file to play!"); 
101.
                return; 
102.
            } // end if 
103.
                         
104.
            // First we'll set up our alarm settings 
105.
            alarmTimeout = (uint)numericUpDown1.Value;  // get user's timeout value 
106.
            Random r = new Random(); 
107.
            theLetter = Convert.ToChar(r.Next(0x41, 0x5B)); // Choose a new random letter 
108.
                                                            // that will stop the alarm. 
109.
 
110.
            // Don't let the user change any settings once the alarm is set. 
111.
            btnSetAlarm.Enabled = false; 
112.
            btnCancel.Enabled = true; 
113.
            txtFileName.Enabled = false; 
114.
            btnBrowse.Enabled = false; 
115.
            dateTimePicker1.Enabled = false; 
116.
            numericUpDown1.Enabled = false; 
117.
             
118.
            // Finally, start the timer. 
119.
            timer1.Start(); 
120.
        } // end btnSetAlarm_Click 
121.
 
122.
        private void timer1_Tick(object sender, EventArgs e) 
123.
124.
            // Every second, we'll check and see if it's time for the alarm 
125.
            if ((dateTimePicker1.Value.Hour == DateTime.Now.Hour) && 
126.
                (dateTimePicker1.Value.Minute == DateTime.Now.Minute) && 
127.
                (dateTimePicker1.Value.Second == DateTime.Now.Second)) 
128.
129.
                // If it is and the program is minimized, restore it. 
130.
                if (this.WindowState == FormWindowState.Minimized) 
131.
132.
                    this.WindowState = FormWindowState.Normal; 
133.
                    this.ShowInTaskbar = true; 
134.
                } // end if 
135.
 
136.
                // Make our tray icon show a little balloon message, just for fun. 
137.
                notifyIcon1.BalloonTipText = "WAKE UP!"; 
138.
                notifyIcon1.ShowBalloonTip(5000); 
139.
 
140.
                // Set flag and show labels to tell the user how to stop the alarm. 
141.
                alarmInProgress = true; 
142.
                label5.Visible = true; 
143.
                lblButton.Visible = true; 
144.
                lblButton.Text = theLetter.ToString(); 
145.
                lblTimeout.Visible = true; 
146.
                lblTimeout.Text = "for " + alarmTimeout.ToString() + " seconds to" + 
147.
                                    " stop alarm."; 
148.
 
149.
                // Stop the alarm timer.  We don't care what time it is now that 
150.
                // our alarm time has passed. 
151.
                timer1.Stop(); 
152.
 
153.
                playFile(); // Start the music! 
154.
 
155.
                holdTime = alarmTimeout;    // Set how many seconds left for our keypress 
156.
 
157.
                // Disable anything that would let the user cheat and end the 
158.
                // alarm by clicking cancel, stop, or the red "X" 
159.
                btnCancel.Enabled = false; 
160.
                btnPlay.Enabled = false; 
161.
                btnStop.Enabled = false; 
162.
                this.ControlBox = false; 
163.
                btnBrowse.Enabled = false; 
164.
 
165.
                // Set focus to our program so the user doesn't have to mess with 
166.
                // the mouse. 
167.
                this.Focus(); 
168.
            } // end if 
169.
        } // end timer1_Tick 
170.
 
171.
        private void btnCancel_Click(object sender, EventArgs e) 
172.
173.
            // If cancel alarm is clicked, we open up the settings 
174.
            // and stop our timer. 
175.
            dateTimePicker1.Enabled = true; 
176.
            numericUpDown1.Enabled = true; 
177.
            btnSetAlarm.Enabled = true; 
178.
            btnCancel.Enabled = false; 
179.
            txtFileName.Enabled = true; 
180.
            btnBrowse.Enabled = true; 
181.
            timer1.Stop(); 
182.
        } // end btnCancel_Click 
183.
 
184.
        private void Form1_KeyDown(object sender, KeyEventArgs e) 
185.
186.
            // If the user presses a key and our alarm is in progress, 
187.
            if (alarmInProgress) 
188.
189.
                // See if it's the magic key 
190.
                if (e.KeyValue == theLetter) 
191.
192.
                    timerTimeout.Start();   // if so, start the timer for alarm stoppage 
193.
                } // end if 
194.
            } // end if 
195.
        } // end Form1_KeyDown 
196.
 
197.
        private void Form1_KeyUp(object sender, KeyEventArgs e) 
198.
199.
            // If the alarm is in progress and the user lets up a key 
200.
            if (alarmInProgress) 
201.
202.
                // see if it's the magic key 
203.
                if (e.KeyValue == theLetter) 
204.
205.
                    // If so, stop the timer and reset the timeout. 
206.
                    timerTimeout.Stop(); 
207.
                    holdTime = alarmTimeout; 
208.
                    lblTimeout.Text = "for " + holdTime.ToString() + " seconds to" + 
209.
                                " stop alarm."; 
210.
                } // end if 
211.
            } // end if 
212.
        } // end Form1_KeyUp 
213.
 
214.
        private void timerTimeout_Tick(object sender, EventArgs e) 
215.
216.
            // This function is for our timeout timer.  It decrements holdTime 
217.
            // which keeps track of how much longer the user has to hold down the 
218.
            // magic key to stop the alarm. 
219.
            holdTime--; 
220.
            lblTimeout.Text = "for " + holdTime.ToString() + " seconds to" + 
221.
                                " stop alarm."; 
222.
 
223.
            // If they've held it down long enough, stop the music, stop the timer, 
224.
            // and re-enable all controls. 
225.
            if (holdTime == 0) 
226.
227.
                stopFile(); 
228.
                alarmInProgress = false; 
229.
                timerTimeout.Stop(); 
230.
                dateTimePicker1.Enabled = true; 
231.
                numericUpDown1.Enabled = true; 
232.
                btnSetAlarm.Enabled = true; 
233.
                btnCancel.Enabled = false; 
234.
                lblTimeout.Visible = false; 
235.
                lblButton.Visible = false; 
236.
                label5.Visible = false; 
237.
                btnCancel.Enabled = true; 
238.
                btnPlay.Enabled = true; 
239.
                btnStop.Enabled = true; 
240.
                txtFileName.Enabled = true; 
241.
                this.ControlBox = true; 
242.
                btnBrowse.Enabled = true; 
243.
            } // end if 
244.
        } // end timerTimeout_Tick 
245.
 
246.
        private void Form1_FormClosing(object sender, FormClosingEventArgs e) 
247.
248.
            stopFile(); 
249.
        } // end Form1_FormClosing 
250.
 
251.
        private void Form1_Resize(object sender, EventArgs e) 
252.
253.
            // If the user minimizes the window, pop up a bubble from our tray icon 
254.
            // and let them know what is going on. 
255.
            if (this.WindowState == FormWindowState.Minimized) 
256.
257.
                notifyIcon1.BalloonTipText = "Your alarm clock is now hidden, but your alarm\n" + 
258.
                                            "will remain set.  Double-click the alarm clock icon\n" + 
259.
                                            "to make adjustments.  Mouse over the icon to see\n" + 
260.
                                            "current alarm status."; 
261.
                notifyIcon1.ShowBalloonTip(3000); 
262.
                this.ShowInTaskbar = false; 
263.
            } // end if 
264.
        } // end Form1_Resize 
265.
 
266.
        private void notifyIcon1_DoubleClick(object sender, EventArgs e) 
267.
268.
            // If the user double clicks the tray icon, be sure our window is visible 
269.
            // and shown in the task bar. 
270.
            this.WindowState = FormWindowState.Normal; 
271.
            this.ShowInTaskbar = true; 
272.
        } // end notifyIcon1_DoubleClick 
273.
 
274.
        private void notifyIcon1_MouseMove(object sender, MouseEventArgs e) 
275.
276.
            // If the user moves the mouse over the tray icon, show a balloon 
277.
            // detailing current status. 
278.
            if (btnSetAlarm.Enabled) 
279.
280.
                notifyIcon1.BalloonTipText = "No alarm is set."; 
281.
                notifyIcon1.ShowBalloonTip(3000); 
282.
            } // end if 
283.
            else 
284.
285.
                notifyIcon1.BalloonTipText = "Alarm is set for:\n" + 
286.
                                    dateTimePicker1.Value.TimeOfDay.ToString(); 
287.
                notifyIcon1.ShowBalloonTip(3000); 
288.
            }// end else 
289.
        } // end notifyIcon1_MouseMove 
290.
        #endregion 
291.
 
292.
    } // end class 
293.
} // end namespace

saludos
gnarff
Bitte warten ..
Mitglied: Michi262
03.12.2007 um 15:29 Uhr
ok. vielen vielen Dank.
Ist echt nett von dir.

Mit freundlichen Grüßen
Michi262
Bitte warten ..
Neuester Wissensbeitrag
Internet

Unbemerkt - Telekom Netzumschaltung! - BNG - Broadband Network Gateway

(3)

Erfahrungsbericht von ashnod zum Thema Internet ...

Heiß diskutierte Inhalte
Windows Server
Outlook Verbindungsversuch mit Exchange (15)

Frage von xbast1x zum Thema Windows Server ...

Grafikkarten & Monitore
Tonprobleme bei Fernseher mit angeschlossenem Laptop über HDMI (11)

Frage von Y3shix zum Thema Grafikkarten & Monitore ...

Microsoft Office
Keine Updates für Office 2016 (11)

Frage von Motte990 zum Thema Microsoft Office ...