Solved

sleep mode

Posted on 2002-03-10
6
496 Views
Last Modified: 2010-04-05
I want my program to be able to verify if computer is in sleep mode, and if it is wake it up? how can i do this?
0
Comment
Question by:amaral_1
6 Comments
 
LVL 6

Expert Comment

by:Stuart_Johnson
ID: 6855356
Sleep mode?  Do you mean standby (suspend) or hibernate?  If so, I don't think this is possible as the system is powered down as far as I know.
0
 
LVL 17

Expert Comment

by:Wim ten Brink
ID: 6855659
Your application can get notified when it goes into sleep mode. It will receive the SC_SCREENSAVE message. I wished I had an example of it but can't find it right now.
0
 
LVL 2

Expert Comment

by:craig_capel
ID: 6855846
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, OleCtrls, SHDocVw;

type
  TForm1 = class(TForm)
    WebBrowser1: TWebBrowser;
    Button1: TButton;
  private
    { Private declarations }
     procedure WMSysCommand(var Msg : TWMSysCommand);
               message WM_SYSCOMMAND;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

 procedure TForm1.WMSysCommand(var Msg : TWMSysCommand);
 begin
   //trap the message and set its result to -1
   if (Msg.CmdType = SC_SCREENSAVE) then
     Msg.Result := -1
   else
     inherited;
 end;

end.

i tried that, but it did not seem to work - so if you know what to do to fix it
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 9

Expert Comment

by:ginsonic
ID: 6856422
listening
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6857425
Have a look at the WM_POWER and WM_POWERBROADCAST messages in the API help. Your application should get a WM_POWERBROADCAST with wparam = PBT_APMQUERYSUSPEND when your computer wants to go in to 'sleep' mode, if it responds with Msg.Result := BROADCAST_QUERY_DENY the power down should not happen. These values should be declared in the Windows unit.

Cheers,

Alan
0
 
LVL 3

Accepted Solution

by:
SteveWaite earned 75 total points
ID: 6859242
You can catch the POWERBROADCAST message with the following code.
Your program can catch going into sleep and set a variable then unset the variable (say) when coming out of sleep.

Regards,
Steve
-----------------

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs;

type
  TForm1 = class(TForm)
  private
    { Private declarations }
    procedure WMPowerBroadcast(var Msg: TMessage);
      message WM_POWERBROADCAST;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

procedure TForm1.WMPowerBroadcast(var Msg: TMessage);
const
  //BROADCAST_QUERY_DENY already declared with WM_POWERBROADCAST
  // the rest were not declared in my version of d5 pro
  BROADCAST_QUERY_ALLOW = -1;
  PBT_APMQUERYSUSPEND = $0000;
  PBT_APMBATTERYLOW = $0009;
  PBT_APMQUERYSTANDBY = $0001;
  PBT_APMQUERYSUSPENDFAILED = $0002;
  PBT_APMQUERYSTANDBYFAILED = $0003;
  PBT_APMSUSPEND = $0004;
  PBT_APMSTANDBY = $0005;
  PBT_APMRESUMECRITICAL = $0006;
  PBT_APMRESUMESUSPEND = $0007;
  PBT_APMRESUMESTANDBY = $0008;
  PBTF_APMRESUMEFROMFAILURE = $00000001;
  PBT_APMPOWERSTATUSCHANGE = $000A;
  PBT_APMOEMEVENT = $000B;
begin
  case Msg.wParam of
    PBT_APMBATTERYLOW:
      Msg.Result := BROADCAST_QUERY_ALLOW;
    PBT_APMQUERYSUSPEND:
      Msg.Result := BROADCAST_QUERY_DENY;
    // etc.
  else
    Msg.Result := BROADCAST_QUERY_DENY;  // deny everything else
  end;
end;

end.
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video discusses moving either the default database or any database to a new volume.
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now