Einzelnen Beitrag anzeigen

hathor
(Gast)

n/a Beiträge
 
#20

AW: Routine gesucht, die feststellt, ob Monitor an oder aus.

  Alt 28. Apr 2013, 10:25
GetDevicePowerState von '\\.\LCD'

Delphi-Quellcode:
function GetDevicePowerState(hDevice:DWORD;var pfOn:BOOL):BOOL; stdcall; external kernel32;
function CheckMonitorState:Boolean;
var
      Hwnd:THandle;
      Stat:LongBool;
begin
      Hwnd:=CreateFile('\\.\LCD' , 0, 0, nil, OPEN_EXISTING, 0, 0);
      if Hwnd <> INVALID_HANDLE_VALUE then GetDevicePowerState(Hwnd,Stat);
      Result:=Stat;
      CloseHandle(Hwnd);
end;

//Beispiele
procedure TForm1.FormCreate(Sender: TObject);
begin
    if CheckMonitorState then Caption:='Monitor ONelse Caption:='Monitor OFF';
end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
    if CheckMonitorState then Panel1.Color:= clGreen else Panel1.Color:= clRed;
end;
  Mit Zitat antworten Zitat