프로그래밍언어/VB.NET

타이머소스

부산딸랑이 2013. 1. 24. 06:19

mports System.IO.Stream

Imports System.Windows.Forms
Imports System.Runtime.InteropServices
Imports System.Text

Public Class Form1



<DllImport("winmm.dll")> _
Private Shared Function mciSendString(ByVal strCommand As String, ByVal strReturn As StringBuilder, ByVal iReturnLength As Integer, ByVal hwndCallback As IntPtr) As Long
End Function

Private Declare Function ExitWindowsEx Lib "user32.dll" (ByVal uFlags As Long, ByVal dwReserved As Long) As Long


Dim second As Integer

Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
second = second - 1
Label1.Text = second & "초 후 종료"
If second = 0 Then

ExitWindowsEx(8, 0)
Timer1.Enabled = False
End If
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
second = combobox1.Text
Timer1.Interval = 1000
Timer1.Enabled = True
Shell("shutdown -s")

End Sub

Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick
second = second - 1
Label1.Text = second & "초 후 알림"
If second = 0 Then
Timer2.Enabled = False

mciSendString("open """ & "C:\Windows\Media\flourish.mid" & """ type mpegvideo alias MediaFile", Nothing, 0, IntPtr.Zero)
mciSendString("play MediaFile", Nothing, 0, IntPtr.Zero)
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Shell("shutdown -a")
mciSendString("stop MediaFile", Nothing, 0, IntPtr.Zero)
Timer1.Enabled = False
Timer2.Enabled = False
Label1.Text = "정지"
End Sub

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

second = ComboBox1.Text
Timer2.Interval = 1000
Timer2.Enabled = True

End Sub


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load



End Sub

Private Sub ComboBox1_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles ComboBox1.KeyUp
If e.KeyCode = Keys.Enter Then
Button3_Click(sender, e)
End If
End Sub
End Class