Click here to Skip to main content
11,409,801 members (60,434 online)
Rate this: bad
good
Please Sign up or sign in to vote.
here is the situation guys:

I am developing an alarm clock for myself. An alarm clock that can wake me up in the morning with a song i choose and which automatically shutdown the computer after the song finishes.

So my problem is:

#How can i let my alarm to perform that 'shutdown operation' just after the song has stopped(finished)#
Posted 22-May-12 9:31am

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You can use the function ExitWindowsEx through P/Invoke:
http://msdn.microsoft.com/en-us/library/windows/desktop/aa376868%28v=vs.85%29.aspx[^],
http://www.pinvoke.net/default.aspx/user32.exitwindowsex[^].

If you need to learn P/Invoke, please see:
http://en.wikipedia.org/wiki/P/Invoke[^],
http://msdn.microsoft.com/library/en-us/vcmxspec/html/vcmg_PlatformInvocationServices.asp[^].

This CodeProject article can also be useful:
Essential P/Invoke[^].

Detection of the end of a song could be more tricky; and it depends on what do you use for a player. For example, if you use AxWindowsMediaPlayer, you can handle the event PlayStateChange:
http://msdn.microsoft.com/en-us/library/windows/desktop/dd562388%28v=vs.85%29.aspx[^],
http://msdn.microsoft.com/en-us/library/windows/desktop/dd562460%28v=vs.85%29.aspx[^].

With WPF, you would handle the event System.Windows.Controls.MediaElement.MediaEnded:
http://msdn.microsoft.com/en-us/library/system.windows.controls.mediaelement.mediaended%28v=vs.100%29.aspx[^].

—SA
  Permalink  
v2
Comments
Espen Harlinn at 22-May-12 19:08pm
   
Excellent :-D
SAKryukov at 22-May-12 19:44pm
   
Thank you, Espen.
--SA
losmac at 23-May-12 12:06pm
   
I agree with you, Espen. +5!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 229
1 OriginalGriff 140
2 Maciej Los 138
3 Sascha Lefévre 120
4 BillWoodruff 60
0 Sergey Alexandrovich Kryukov 8,771
1 OriginalGriff 6,905
2 Maciej Los 3,390
3 Abhinav S 3,248
4 Peter Leow 3,059


Advertise | Privacy | Mobile
Web01 | 2.8.150414.5 | Last Updated 22 May 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100