Click here to Skip to main content
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 OriginalGriff 304
1 Maciej Los 285
2 Sergey Alexandrovich Kryukov 255
3 Shweta N Mishra 216
4 PIEBALDconsult 174
0 OriginalGriff 7,660
1 Sergey Alexandrovich Kryukov 7,072
2 DamithSL 5,604
3 Manas Bhardwaj 4,986
4 Maciej Los 4,760


Advertise | Privacy | Mobile
Web01 | 2.8.1411023.1 | Last Updated 22 May 2012
Copyright © CodeProject, 1999-2014
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