Solved

sleep mode

Posted on 2002-03-10
6
525 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Comparing dates in Delphi. Greater than/ Less than 3 290
Intraweb download file link ? 1 167
oracle global variables 4 79
Delphi 2 77
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

740 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