阻止windows关机

http://topic.csdn.net/t/20050528/12/4041955.html

http://download.csdn.net/down/2021631/huleidong

 

Attribute VB_Name = "mStopShutDown" Private Const GWL_WNDPROC = (-4) Private Const WM_ENDSESSION = &H16 Private Const WM_QUERYENDSESSION = &H11 Private WndProc As Long Private Declare Function CallWindowProc Lib "user32" Alias "CallWindowProcA" (ByVal lpPrevWndFunc As Long, ByVal hWnd As Long, ByVal Msg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Sub HookShutDown(ByVal hWnd As Long) If WndProc = 0 Then WndProc = SetWindowLong(hWnd, GWL_WNDPROC, AddressOf WindowProc) End If End Sub Public Sub UnHookShutDown(ByVal hWnd As Long) If WndProc <> 0 Then Call SetWindowLong(hWnd, GWL_WNDPROC, WndProc) WndProc = 0 End If End Sub Private Function WindowProc(ByVal hw As Long, ByVal uMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long If uMsg = WM_QUERYENDSESSION Then WindowProc = False '为0 Exit Function ElseIf uMsg = WM_ENDSESSION Then WindowProc = False '为0 Exit Function End If WindowProc = CallWindowProc(WndProc, hw, uMsg, wParam, lParam) End Function '主窗体代码: ' ' Private Sub Form_Load() ' Call HookShutDown(Me.hWnd) ' End Sub ' ' Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer) ' Call UnHookShutDown(Me.hWnd) ' End Sub

 

可以在用户点击关机时处理事情,关机执行程序。

你可能感兴趣的:(VB源码)