Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. System Admin
  4. Preventing Our Windows from Suspending in VC++ 6.0

Preventing Our Windows from Suspending in VC++ 6.0

Scheduled Pinned Locked Moved System Admin
c++algorithmsquestion
5 Posts 3 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cahya Dewanta
    wrote on last edited by
    #1

    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! :)

    D C 2 Replies Last reply
    0
    • C Cahya Dewanta

      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! :)

      D Offline
      D Offline
      Duncan Edwards Jones
      wrote on last edited by
      #2

      [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

      C 1 Reply Last reply
      0
      • D Duncan Edwards Jones

        [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

        C Offline
        C Offline
        Cahya Dewanta
        wrote on last edited by
        #3

        :) 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 '\\

        1 Reply Last reply
        0
        • C Cahya Dewanta

          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! :)

          C Offline
          C Offline
          Chris Richardson
          wrote on last edited by
          #4

          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

          C 1 Reply Last reply
          0
          • C Chris Richardson

            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

            C Offline
            C Offline
            Cahya Dewanta
            wrote on last edited by
            #5

            Yeap! 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:

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups