Click here to Skip to main content
12,955,493 members (62,700 online)
Rate this:
 
Please Sign up or sign in to vote.
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 22-May-12 8: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 22-May-12 19:08pm
   
Excellent :-D
SAKryukov 22-May-12 19:44pm
   
Thank you, Espen.
--SA
losmac 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,559
CHill60 3,550
Maciej Los 3,153
ppolymorphe 2,030
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 22 May 2012
Copyright © CodeProject, 1999-2017
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