Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

sleep mode

Posted on 2002-03-10
6
521 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
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

860 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