Autor Beitrag
digi_c
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: Fr 29.08.03 18:16 
Hiho, ich möchte o.g. blockieren, gibts da nen Befehl in der WinAPI?
Klaro am einfachsten wäre es wenn man den Mauszeiger bewegt, aber das wäre ja Laienhaft :lol:
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Fr 29.08.03 18:29 
Schalte es in der Systemsteuerunmg doch ab.
digi_c Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1905

W98, XP
D7 PE, Lazarus, WinAVR
BeitragVerfasst: So 31.08.03 18:35 
Die Idee ist auch net schlecht :lol:

ne Spass beiseite ich möchte dass halt durch ein Programm blockieren lassen, hat da echt keiner ne Idee :?
astaria
Hält's aus hier
Beiträge: 10

Win 98, Win XP Prof
D6 Ent
BeitragVerfasst: So 28.12.03 17:40 
Auch wenns bissl spät ist, aber hatte selber dazu nix gefunden. Deshalb hab ich mir ne Unit geschrieben, die genau das bewerkstelligt (VideoTimeOutAc := 0 setzen). Vielleicht hilft das ja noch jemandem. Die Möglichkeiten sind sehr viel weitreichender, aber ich hab nur das implementiert, was ich auch brauche. Weiteres siehe powrprof.h im Win-SDK. Achja, das is noch Code under development ;-)

ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
unit PowrProf;

interface

uses Types, Windows;

const
  //
  // Throttling policies
  //
  PO_THROTTLE_NONE     = 0;
  PO_THROTTLE_CONSTANT = 1;
  PO_THROTTLE_DEGRADE  = 2;
  PO_THROTTLE_ADAPTIVE = 3;
  PO_THROTTLE_MAXIMUM  = 4;   // not a policy, just a limit

  // Discharge policy constants
  NUM_DISCHARGE_POLICIES    = 4;
  DISCHARGE_POLICY_CRITICAL = 0;
  DISCHARGE_POLICY_LOW      = 1;

type
  NTSTATUS = cardinal; // 32-bit

  // Power Policy Management interfaces
  //
  POWER_ACTION = (PowerActionNone = 0,
    PowerActionReserved,
    PowerActionSleep,
    PowerActionHibernate,
    PowerActionShutdown,
    PowerActionShutdownReset,
    PowerActionShutdownOff,
    PowerActionWarmEject
    );

  SYSTEM_POWER_STATE = (PowerSystemUnspecified = 0,
    PowerSystemWorking = 1,
    PowerSystemSleeping1 = 2,
    PowerSystemSleeping2 = 3,
    PowerSystemSleeping3 = 4,
    PowerSystemHibernate = 5,
    PowerSystemShutdown = 6,
    PowerSystemMaximum = 7
    );


  POWER_INFORMATION_LEVEL = (SystemPowerPolicyAc,
    SystemPowerPolicyDc,
    VerifySystemPolicyAc,
    VerifySystemPolicyDc,
    SystemPowerCapabilities,
    SystemBatteryState,
    SystemPowerStateHandler,
    ProcessorStateHandler,
    SystemPowerPolicyCurrent,
    AdministratorPowerPolicy,
    SystemReserveHiberFile,
    ProcessorInformation,
    SystemPowerInformation,
    ProcessorStateHandler2,
    LastWakeTime,                                   // Compare with KeQueryInterruptTime()
    LastSleepTime,                                  // Compare with KeQueryInterruptTime()
    SystemExecutionState,
    SystemPowerStateNotifyHandler,
    ProcessorPowerPolicyAc,
    ProcessorPowerPolicyDc,
    VerifyProcessorPowerPolicyAc,
    VerifyProcessorPowerPolicyDc,
    ProcessorPowerPolicyCurrent,
    SystemPowerStateLogging,
    SystemPowerLoggingEntry);


  POWER_ACTION_POLICY = packed record
    Action: DWORD;// POWER_ACTION;
    Flags: DWORD;
    EventCode: DWORD;
  end;
  PPOWER_ACTION_POLICY = ^POWER_ACTION_POLICY;

  // system battery drain policies
  SYSTEM_POWER_LEVEL = packed record
    Enable: boolean;
    Spare: array[0..2of byte;
    BatteryLevel: DWORD;
    PowerPolicy: POWER_ACTION_POLICY;
    MinSystemState: DWORD; // SYSTEM_POWER_STATE;
  end;
  PSYSTEM_POWER_LEVEL = ^SYSTEM_POWER_LEVEL;


  // system power policies
  SYSTEM_POWER_POLICY = packed record
    Revision: DWORD;       // 1

    // events
    PowerButton: POWER_ACTION_POLICY;
    SleepButton: POWER_ACTION_POLICY;
    LidClose: POWER_ACTION_POLICY;
    LidOpenWake: DWORD; //SYSTEM_POWER_STATE;
    Reserved: DWORD;

    // "system idle" detection
    Idle: POWER_ACTION_POLICY;
    IdleTimeout: DWORD;
    IdleSensitivity: byte;

    // dynamic throttling policy
    //      PO_THROTTLE_NONE, PO_THROTTLE_CONSTANT, PO_THROTTLE_DEGRADE, or PO_THROTTLE_ADAPTIVE
    DynamicThrottle: byte;

    Spare2: array[0..1of byte;

    // meaning of power action "sleep"
    MinSleep: DWORD;//SYSTEM_POWER_STATE;
    MaxSleep: DWORD; //SYSTEM_POWER_STATE;
    ReducedLatencySleep: DWORD; // SYSTEM_POWER_STATE;
    WinLogonFlags: DWORD;

    // parameters for dozing
    Spare3: DWORD;
    DozeS4Timeout: DWORD;

    // battery policies
    BroadcastCapacityResolution: DWORD;
    DischargePolicy: array[0..NUM_DISCHARGE_POLICIES - 1of SYSTEM_POWER_LEVEL;

    // video policies
    VideoTimeout: DWORD;
    VideoDimDisplay: boolean;
    VideoReserved: array[0..2of DWORD;

    // hard disk policies
    SpindownTimeout: DWORD;

    // processor policies
    OptimizeForPower: boolean; // is BOOLEAN .. not sure, if this i
    FanThrottleTolerance: byte;
    ForcedThrottle: byte;
    MinThrottle: byte;
    OverThrottled: POWER_ACTION_POLICY;
    dontknow: array[0..2of byte;
           // somehow the size doesn't match, but we get correct values for our thing
  end;     // 232 Bytes
  PSYSTEM_POWER_POLICY = ^SYSTEM_POWER_POLICY;


  TPowerProf = class
  private
    SysPowerPolicy: PSYSTEM_POWER_POLICY;
    OldVideoTimeOutAc:Cardinal;
    function GetVideoTimeOutAc: cardinal;
    procedure SetVideoTimeOutAc(const Value: cardinal);

  public
    constructor Create;
    destructor Destroy; override;
    procedure RestoreVideoTimeOutAc;
    property VideoTimeOutAc: cardinal read GetVideoTimeOutAc write SetVideoTimeOutAc;
  end;

function CallNtPowerInformation(InformationLevel: POWER_INFORMATION_LEVEL;
  lpInputBuffer: Pointer; nInputBufferSize: cardinal; lpOutputBuffer: Pointer;
  nOutputBufferSize: cardinal): NTSTATUS; stdcall;

implementation

const 
  powrprofdll = 'powrprof.dll';

function CallNtPowerInformation; external powrprofdll Name 'CallNtPowerInformation';

{ TPowerProf }

constructor TPowerProf.Create;
begin
  getmem(SysPowerPolicy, sizeof(SYSTEM_POWER_POLICY));
  OldVideoTimeOutAc:=VideoTimeOutAc;
end;

destructor TPowerProf.Destroy;
begin
  RestoreVideoTimeOutAc;
  if SysPowerPolicy <> nil then
  begin
    freemem(SysPowerPolicy);
    SysPowerPolicy:=nil;
  end;
end;

function TPowerProf.GetVideoTimeOutAc: cardinal;
begin
  result:=0;
  if SysPowerPolicy=nil then exit;
  if SUCCEEDED(CallNtPowerInformation(SystemPowerPolicyCurrent, nil,
    0, SysPowerPolicy, sizeof(SYSTEM_POWER_POLICY))) then
    Result:=SysPowerPolicy^.VideoTimeout;
end;

procedure TPowerProf.RestoreVideoTimeOutAc;
begin
  VideoTimeOutAc:=OldVideoTimeOutAc;
end;                

procedure TPowerProf.SetVideoTimeOutAc(const Value: cardinal);
begin                   
  if SysPowerPolicy=nil then exit;
  SysPowerPolicy^.VideoTimeout:=Value;
  CallNtPowerInformation(SystemPowerPolicyAc, SysPowerPolicy,
    sizeof(SYSTEM_POWER_POLICY), SysPowerPolicy, sizeof(SYSTEM_POWER_POLICY));
end;

end.
Christian S.
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 20451
Erhaltene Danke: 2264

Win 10
C# (VS 2019)
BeitragVerfasst: So 28.12.03 17:43 
Hallo!

Das hat es doch verdient, in den OpenSource-Units veröffentlicht zu werden, anstatt hier unterzugehen! Schreibe doch dort auch noch einen Beitrag dazu, wenn Du möchtest.

MfG
Peter

_________________
Zwei Worte werden Dir im Leben viele Türen öffnen - "ziehen" und "drücken".
Michi27
Hält's aus hier
Beiträge: 1



BeitragVerfasst: Mo 30.08.04 15:24 
Hi,

genau das suche ich :-) Aber irgendwie bekomme ich es nicht hin das VideoTimeOutAc := 0 gesetzt wird.

Ich habe den Source von oben als neue Unit eingebunden und in der HauptForm

VideoTimeOutAc := 0;

geschrieben. Aber leider wird der Bildschirm immer noch nach einiger Zeit dunkel :-(

Hätte vielleicht jemand mal eine Demo mit Source damit ich mir das ganze da nochmal genau ansehen kann?


Mit freundlichen Grüßen

Michael