Preventing Our Windows from Suspending in VC++ 6.0
-
Hi all! I`ve been searching for VC++ 6.0 code/application that preventing our Windows from suspending but I haven`t found it yet. What I have found is a code in VB language that works perfectly. Any helps, please? Thank you so very much! :)
-
Hi all! I`ve been searching for VC++ 6.0 code/application that preventing our Windows from suspending but I haven`t found it yet. What I have found is a code in VB language that works perfectly. Any helps, please? Thank you so very much! :)
[quote] What I have found is a code in VB language that works perfectly. [/quote] If you were to point us at the VB code we could probably translate it. Probably it works by replying to the WM_POWER message where wParam is APM_QUERYSUSPEND or something? '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd
-
[quote] What I have found is a code in VB language that works perfectly. [/quote] If you were to point us at the VB code we could probably translate it. Probably it works by replying to the WM_POWER message where wParam is APM_QUERYSUSPEND or something? '--8<------------------------ Ex Datis: Duncan Jones Merrion Computing Ltd
:) Hi! It`s a very good luck, coz I got the code from your site (www.merrioncomputing.com)! Nice code guys! Here`s the code:
'**IN A MODULE** Option Explicit 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 '\\ 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 '\\ eventhandlerhOldWndProc 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 '\\
-
Hi all! I`ve been searching for VC++ 6.0 code/application that preventing our Windows from suspending but I haven`t found it yet. What I have found is a code in VB language that works perfectly. Any helps, please? Thank you so very much! :)
It's SO much easier to do this in VC than in VB. If you use MFC, simply hook up a virtual function override for WindowProc (with ClassWizard), and put this code in it:
if( message == WM_POWERBROADCAST )
{
switch( wParam )
{
case PBT_APMQUERYSUSPEND:
{
return BROADCAST_QUERY_DENY;
}
}
}There ya go, done! If you don't use MFC, simply put a case for WM_POWERBROADCAST in your already existing WindowProc. Chris Richardson
Terrain Software -
It's SO much easier to do this in VC than in VB. If you use MFC, simply hook up a virtual function override for WindowProc (with ClassWizard), and put this code in it:
if( message == WM_POWERBROADCAST )
{
switch( wParam )
{
case PBT_APMQUERYSUSPEND:
{
return BROADCAST_QUERY_DENY;
}
}
}There ya go, done! If you don't use MFC, simply put a case for WM_POWERBROADCAST in your already existing WindowProc. Chris Richardson
Terrain SoftwareYeap! It`s so MUCH easier. Just a less-than-a-minute work. Great thanks, Chris Richardson! Both MFC and non-MFC work fine. Thanks to Duncan, too. Hoping this thread useful for the community. Regards.:cool: