Find Code:
All Words
Any of the Words
Exact Phrase
Home
:
Code
:
Forums
:
Submit
:
Mailing List
:
About
:
Contact
Code
All
VB.NET
ASP.NET
C#
VB Classic
ASP Classic
Snippets
Popular
Resources
Submit Code
Forums
Articles
Tips
Links
Books
Contest
Link to us
Prevent windows (both NT and 9x) going into suspen...
Author:
Merrion Computing
E-mail:
Click to e-mail author
Website:
http://www.merrioncomputing.com
Submitted:
4/18/2001
Version:
VB5
Compatibility:
VB5, VB6
Category:
Windows API
Views:
10059
Prevent windows (both NT and 9x) going into suspended mode.
Declarations:
Public oldProcAddress As Long Public Enum enPowerBroadcastType PBT_APMQUERYSUSPEND = &H0 PBT_APMQUERYSTANDBY = &H1 PBT_APMQUERYSUSPENDFAILED = &H2 PBT_APMQUERYSTANDBYFAILED = &H3 PBT_APMSUSPEND = &H4 PBT_APMSTANDBY = &H5 PBT_APMRESUMECRITICAL = &H6 PBT_APMRESUMESUSPEND = &H7 PBT_APMRESUMESTANDBY = &H8 End Enum Public Const BROADCAST_QUERY_DENY = &H424D5144 Public Const WM_POWER = &H48 Public Const WM_POWERBROADCAST = &H218 Public Const PWR_SUSPENDREQUEST = 1 Public Const GWL_WNDPROC = (-4) Public Const PWR_FAIL = (-1) Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public 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
Code:
'\\ In a .BAS file: '\\ --[VB_WindowProc]-------------------------------------------- '\\ 'typedef LRESULT (CALLBACK* WNDPROC)(HWND, UINT, WPARAM, LPARAM); '\\ Parameters: '\\ hwnd - window handle receiving message '\\ wMsg - The window message (WM_..etc.) '\\ wParam - First message parameter '\\ lParam - Second message parameter '\\ Note: '\\ When subclassing a window proc using this, set the eventhandler's '\\ hOldWndProc property to the window's previous window proc address. '\\ -------------------------------------------------------------------- '\\ You have a royalty free right to use, reproduce, modify, publish and mess with this code '\\ I'd like you to visit http://www.merrioncomputing.com for updates, but won't force you '\\ ------------------------------------------------------------------- Public Function VB_WindowProc(ByVal hWnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long On Local Error Resume Next Dim lRet As Long '\\ If its a power suspending broadcast, kill it... If wMsg = WM_POWER And wParam = PWR_SUSPENDREQUEST Then '\\ This is the message in Windows NT/2000 VB_WindowProc = PWR_FAIL ElseIf wMsg = WM_POWERBROADCAST And wParam = PBT_APMQUERYSUSPEND Then VB_WindowProc = BROADCAST_QUERY_DENY Else VB_WindowProc = CallWindowProc(oldProcAddress, hWnd, wMsg, wParam, lParam) End If End Function '\\ In your application main form: Private Sub Form_Load() oldProcAddress = SetWindowLong(Me.hWnd, GWL_WNDPROC, AddressOf VB_WindowProc) End Sub Private Sub Form_Unload(Cancel As Integer) Call SetWindowLong(Me.hWnd, GWL_WNDPROC, oldProcAddress) End Sub
Home
|
Forums
|
Submit
|
Books
|
Mailing List
|
Advertising
|
About
|
Contact
© 2023 A1VBCode. All rights reserved.
Legal disclaimer & terms of use
Privacy statement