Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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

1 solution

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
 
Share this answer
 
v2
Comments
Espen Harlinn 22-May-12 19:08pm    
Excellent :-D
Sergey Alexandrovich Kryukov 22-May-12 19:44pm    
Thank you, Espen.
--SA
Maciej Los 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)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900