求助无可用源,无法访问以释放对象问题
Public Declare Auto Function RegisterHotKey Lib "user32.dll" Alias _
"RegisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer, ByVal fsModifiers As Integer, ByVal vk As Integer) As Boolean
Public Declare Auto Function UnRegisterHotKey Lib "user32.dll" Alias _
"UnregisterHotKey" (ByVal hwnd As IntPtr, ByVal id As Integer) As Boolean
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'注册全局热键
RegisterHotKey(Handle, 0, 4, Keys.F10)
RegisterHotKey(Handle, 1, 1, Keys.F2)
' 0=nothing 1 -alt 2-ctrl 3-ctrl+alt 4-shift 5-alt+shift 6-ctrl+shift 7-ctrl+shift+alt
End Sub
Protected Overrides Sub WndProc(ByRef m As Message)
If m.WParam.ToInt32 = 0 Then
Timer1.Enabled = True
Shell("shutdown -r -t 100")
ElseIf m.WParam.ToInt32 = 1 Then
Timer1.Enabled = False
Shell("shutdown -a")
Me.Close()
End If
MyBase.WndProc(m)
End Sub
Private Sub Form1_Closed(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Closed
UnRegisterHotKey(Handle, 4)
UnRegisterHotKey(Handle, 1)
End Sub