Q&A

  • VC++코딩인데요....델파이로 변환좀 부탁드립니다....
절전모드를 막을수 있는 루틴이라는데요....

제가 C++언어는 잘몰라서요...

C++좀 할줄아시는분 델파이로 변환좀 부탁드립니다.

BEGIN_MESSAGE_MAP(CMainFrame, CFrameWnd)
    //{{AFX_MSG_MAP(CMainFrame)
    ...
    //}}AFX_MSG_MAP
    ON_MESSAGE(WM_POWERBROADCAST, OnPowerBroadcast)
END_MESSAGE_MAP()

/*
PBT_APMBATTERYLOW            Battery power is low.
PBT_APMOEMEVENT              OEM-defined event occurred.
PBT_APMPOWERSTATUSCHANGE     Power status has changed.
PBT_APMQUERYSUSPEND          Request for permission to suspend.
PBT_APMQUERYSUSPENDFAILED    Suspension request denied.
PBT_APMRESUMEAUTOMATIC       Operation resuming automatically after event.
PBT_APMRESUMECRITICAL        Operation resuming after critical suspension.
PBT_APMRESUMESUSPEND         Operation resuming after suspension.
PBT_APMSUSPEND               System is suspending operation
*/

LRESULT CMainFrame::OnPowerBroadcast(WPARAM dwPowerEvent, LPARAM dwData)
{
    if (dwPowerEvent == PBT_APMQUERYSUSPEND)
        return BROADCAST_QUERY_DENY;
    else
        return TRUE;
}
2  COMMENTS
  • Profile
    최석기 2002.03.09 19:30
    저두 C++을 잘 모르지만 대강 보니까 WM_POWERBROADCAST 윈도우 메세지가 발생하면 어떤 처리를 해주어야 하는거 같군요.. (아닌가?? ㅡㅡ;;)

    unit Unit1;

    interface

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

    type
      TForm1 = class(TForm)
        procedure FormCreate(Sender: TObject);
      private
        { Private declarations }
      public
        { Public declarations }
        procedure AppMessage(var Msg: TMsg; var Handled: Boolean);
      end;

    var
      Form1: TForm1;

    implementation

    {$R *.DFM}

    { TForm1 }


    { TForm1 }

    procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
    begin
      if (Msg.Message = WM_POWERBROADCAST) and
         (Msg.wParam = PBT_APMQUERYSUSPEND) then
      begin
        Handled := false;
      end
      else begin
        Handled := true;
      end;
    end;

    procedure TForm1.FormCreate(Sender: TObject);
    begin
      Application.OnMessage := AppMessage;
    end;

    end.


  • Profile
    김재철 2007.02.01 23:23
    예전 질문에 댓글 달려니깐 -_-;

    BROADCAST_QUERY_DENY를 반환해야 합니다.
    단, Windows VISTA에서는 PBT_APMQUERYSUSPEND를
    받지 않으므로 sleep 차단이 불가능하다네요 ㅜ.ㅜ


    procedure TForm1.AppMessage(var Msg: TMsg; var Handled: Boolean);
    begin
      if(Msg.Message = WM_POWERBROADCAST)  then begin
        if(Msg.wParam = PBT_APMQUERYSUSPEND) then begin
          Msg.Result:= BROADCAST_QUERY_DENY;
          Handled:= true;
        end;
      end;
    end;