Здравствуйте.
Не могу получить время отключения монитора.
Да и любые другие параметры.
Код:
program Project1;
{$APPTYPE CONSOLE}
uses
Winapi.Windows;
const
g: TGUID = '{3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E}'; // Отключать экран через
NO_SUBGROUP_GUID : TGUID = '{fea3413e-7e05-4911-9a71-700331f1c294}';
GUID_MONITOR_POWER_ON : TGUID = '{02731015-4510-4526-99e6-e5a17ebd1aea}';
GUID_VIDEO_SUBGROUP : TGUID = '{7516b95f-f776-4464-8c53-06167f40cc99}';
GUID_DISK_SUBGROUP : TGUID = '{0012ee47-9041-4b5d-9b77-535fba8b1442}';
GUID_SLEEP_SUBGROUP : TGUID = '{238C9FA8-0AAD-41ED-83F4-97BE242C8F20}';
ACCESS_SCHEME = 16;
ACCESS_SUBGROUP = 17;
ACCESS_INDIVIDUAL_SETTING = 18;
GUID_VIDEO_POWERDOWN_TIMEOUT : TGUID = '{3C0BC021-C8A8-4E07-A973-6B14CBCB2B7E}';
GUID_BATTERY_PERCENTAGE_REMAINING : TGUID = '{a7ad8041-b45a-4cae-87a3-eecbb468a9e1}';
GUID_POWER_SAVING_STATUS : TGUID = '{E00958C0-C213-4ACE-AC77-FECCED2EEEA5}';
GUID_POWERSCHEME_PERSONALITY : TGUID = '{245d8541-3943-4422-b025-13A784F679B7}';
GUID_MIN_POWER_SAVINGS : TGUID = '{8c5e7fda-e8bf-4a96-9a85-a6e23a8c635c}';
GUID_MAX_POWER_SAVINGS : TGUID = '{a1841308-3541-4fab-bc81-f71556f20b4a}';
GUID_TYPICAL_POWER_SAVINGS : TGUID = '{381b4222-f694-41f0-9685-ff5bb260df2e}';
function PowerSetActiveScheme(UserRootPowerKey : HKEY; CONST SchemeGuid : PGUID) : DWORD;
stdcall; external 'powrprof.dll' name 'PowerSetActiveScheme';
function PowerWriteACValueIndex(RootPowerKey :HKEY; CONST SchemeGuid : PGUID;
CONST SubGroupOfPowerSettingsGuid : PGUID; CONST PowerSettingGuid : PGUID;
AcValueIndex : DWORD): DWORD;
stdcall; external 'powrprof.dll' name 'PowerWriteACValueIndex';
function PowerReadACValueIndex(RootPowerKey : HKEY;
const SchemeGuid : PGUID; CONST SubGroupOfPowerSettingsGuid : PGUID;
const PowerSettingGuid : PGUID; AcValueIndex : LPDWORD): DWORD;
stdcall; external 'powrprof.dll' name 'PowerReadACValueIndex';
function PowerReadDCValueIndex(RootPowerKey : HKEY;
const SchemeGuid : PGUID; CONST SubGroupOfPowerSettingsGuid : PGUID;
const PowerSettingGuid : PGUID; AcValueIndex : LPDWORD): DWORD;
stdcall; external 'powrprof.dll' name 'PowerReadDCValueIndex';
function PowerEnumerate(RootPowerKey: HKEY;
const SchemeGuid: PGUID; const SubGroupOfPowerSettingsGuid: PGUID;
AccessFlags: DWORD; Index: ULONG;
Buffer: PUCHAR; BufferSize: PDWORD): DWORD;
stdcall; external 'powrprof.dll' name 'PowerEnumerate';
function PowerReadFriendlyName(
RootPowerKey: HKEY;
const SchemeGuid: PGUID; const SubGroupOfPowerSettingsGuid: PGUID;
const PowerSettingGuid: PGUID;
Buffer: Pointer; BufferSize: LPDWORD
): DWORD; stdcall; external 'powrprof.dll' name 'PowerReadFriendlyName';
function PowerGetActiveScheme(
UserRootPowerKey : HKEY;
ActivePolicyGuid : PGUID
): DWORD; stdcall; external 'powrprof.dll' name 'PowerGetActiveScheme';
procedure a;
var
ActivePolicyGuid, buffer: TGUID;
bufferSize, displayBufferSize : DWORD;
displayBuffer : array [0..255
// $FF
] of wChar; TimeOutMon : DWORD;
begin
TimeOutMon := 0;
if PowerGetActiveScheme(0, @ActivePolicyGuid) = 0 then
begin
bufferSize := sizeof(buffer);
if (ERROR_SUCCESS = PowerEnumerate(0, @ActivePolicyGuid, @GUID_VIDEO_SUBGROUP, ACCESS_INDIVIDUAL_SETTING, 0, @buffer, {LPDWORD}@(bufferSize))) then
begin
displayBufferSize := sizeof(displayBuffer);
if(ERROR_SUCCESS = PowerReadFriendlyName(0, @ActivePolicyGuid, @GUID_VIDEO_SUBGROUP, @buffer, @displayBuffer, {LPDWORD}@(displayBufferSize))) then
begin
Write(displayBuffer, ': ');
// New(dfg);
// if PowerWriteACValueIndex(0, @ActivePolicyGuid, @GUID_VIDEO_SUBGROUP, @{g}buffer, 60*25) = 0 then
//PowerSetActiveScheme(0, @ActivePolicyGuid);
if PowerReadACValueIndex(0, @ActivePolicyGuid, @GUID_VIDEO_SUBGROUP, @{g}buffer, @(TimeOutMon)) = ERROR_SUCCESS then
Write(TimeOutMon, ' Sec.')
else
Write('Error');
// Dispose(dfg);
if PowerReadDCValueIndex(0, @ActivePolicyGuid, @GUID_VIDEO_SUBGROUP, @{g}buffer, @(TimeOutMon)) = ERROR_SUCCESS then
Write(TimeOutMon, ' Sec.')
else
Write('Error');
end;
end;
end;
end;
begin
a;
Readln;
end.
PowerReadACValueIndex и ..DC.. доходит до них, возвращаю значения отличное от 0. Может я неправильно объявил функции(все), параметры, подсовываю не те переменные?
Может, кто занимался?
Подскажите пожалуйста.
Разобрался.
Забыл где вычитал, да ладно. Требовалось в фунции получение активной схемы 'out ... : PGUID'.