Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sleep mode

Posted on 2002-03-10
6
Medium Priority
?
570 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
[X]
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
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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 225 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: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

688 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