Solved

sleep mode

Posted on 2002-03-10
6
509 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
oracle global variables 4 68
Multiple image collision 13 74
Find and Replace Stream with 0s 8 61
TEMBEDDEDWB how can i change its user agent ? 8 55
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

813 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

10 Experts available now in Live!

Get 1:1 Help Now