Autor Beitrag
JustusJonas
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Do 09.12.04 12:11 
Hallo Leute,

gibt es eine Möglichkeit festzustellen, ob der Computer gesperrt bzw. entsperrt wurde?
Konnte leider nix finden! :(

Danke schon mal für die Hilfe!

Greetz
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Do 09.12.04 13:31 
Ich wüßte jetzt nichts. Wozu brauchst du denn das?
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Do 09.12.04 13:42 
Ich hab ein kleines Tool für WinAmp geschrieben. Neben anderen (für mich) nützlichen Funktionen möchte ich, dass das Programm den WinAmp pausiert, wenn der Rechner gesperrt wird und wieder play macht, wenn der Rechner wieder entsperrt wird. Deshalb muss ich das ja irgendwie abprüfen!

Greetz
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Do 09.12.04 17:31 
Zitat:

WM_WTSSESSION_CHANGE

The WM_WTSSESSION_CHANGE message notifies applications of changes in session state.

The window receives this message through its WindowProc function.





LRESULT CALLBACK WindowProc(
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam
);
Parameters
hWnd
[in] Handle to the window.
uMsg
[in] Specifies the message.
wParam
[in] Status code describing the reason the session state change notification was sent. This parameter can be one of the following values. Value Meaning
WTS_CONSOLE_CONNECT A session was connected to the console session.
WTS_CONSOLE_DISCONNECT A session was disconnected from the console session.
WTS_REMOTE_CONNECT A session was connected to the remote session.
WTS_REMOTE_DISCONNECT A session was disconnected from the remote session.
WTS_SESSION_LOGON A user has logged on to the session.
WTS_SESSION_LOGOFF A user has logged off the session.
WTS_SESSION_LOCK A session has been locked.
WTS_SESSION_UNLOCK A session has been unlocked.
WTS_SESSION_REMOTE_CONTROL A session has changed its remote controlled status. To determine the status, call GetSystemMetrics and check the SM_REMOTECONTROL metric.

lParam
[in] The identifier of the session.
Return Values
The return value is ignored.

Remarks
This message is sent only to applications that have registered to receive this message by calling WTSRegisterSessionNotification.

Examples of how applications can respond to this message include releasing or acquiring console-specific resources, determining how a screen is to be painted, or triggering console animation effects.

Requirements
Client: Included in Windows XP.
Server: Included in Windows Server 2003.
Header: Declared in Winuser.h; include Windows.h.


See Also
WTSRegisterSessionNotification, WTSUnRegisterSessionNotification

_________________
Im Nachhinein ist man immer ein Schlauch!
"Dream as if you'll live forever, live as if you'll die today!" James Dean
JustusJonas Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 222



BeitragVerfasst: Fr 10.12.04 08:22 
Danke schon mal, ich glaub wir sind auf dem richtigen Weg. Kann damit aber nicht so wirklich viel mit anfangen! :(
Kann mir jemamd noch ein wenig weiterhelfen?

Greetz
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Fr 10.12.04 09:05 
hmm warte mal das funktioniert glaub doch nicht so, wie ich mir das dachte. *grübel*

ich schau mal später danach muss jetzt arbeiten...

_________________
Im Nachhinein ist man immer ein Schlauch!
"Dream as if you'll live forever, live as if you'll die today!" James Dean
BenBE
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 8721
Erhaltene Danke: 191

Win95, Win98SE, Win2K, WinXP
D1S, D3S, D4S, D5E, D6E, D7E, D9PE, D10E, D12P, DXEP, L0.9\FPC2.0
BeitragVerfasst: Fr 10.12.04 09:16 
So wie ich Windows kenne, sendet er die wahrscheinlich nur an das Application.Handle, nicht an alle Forms. Bin mir da aber nicht sicher, müsste das selber erst ausprobieren.

_________________
Anyone who is capable of being elected president should on no account be allowed to do the job.
Ich code EdgeMonkey - In dubio pro Setting.
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Fr 10.12.04 09:43 
pack mal nen label auf die form und bau die form zu dem hier:


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:
unit UfrmMain;

interface

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

type
  TfrmMain = class(TForm)
    Label1: TLabel;
    procedure FormCreate(Sender: TObject);
  private
    { Private-Deklarationen }
    FintLockedCount : integer;
    procedure WndProc(var Message: TMessage); override;
  public
    { Public-Deklarationen }
  end;

var
  frmMain: TfrmMain;

implementation

{$R *.dfm}

procedure TfrmMain.WndProc(var Message: TMessage);
begin
   Case Message.Msg of
      WTS_SESSION_LOCK:
            begin
               inc(FintLockedCount);
               label1.caption := 'Die Session wurde bereits ' + IntToStr(FintLockedCount) + ' mal gesperrt.';
            end;
   end;
   inherited;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
   FintLockedCount := 0;
end;

end.



und dann wirst du sehen, dass session nicht in dem sinne gebraucht wird: öffne ein anderes programm oder hol ein anderes nach vorne und WTS_SESSION_LOCK wurde gesendet.

gruß

_________________
Im Nachhinein ist man immer ein Schlauch!
"Dream as if you'll live forever, live as if you'll die today!" James Dean
rochus
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 416

Win XP Prof, Fedora Core 4, SuSE 7.0
D7 Ent, D2005 Pers
BeitragVerfasst: Fr 10.12.04 11:34 
Okay, ich hab's dir kurz Programmiert:

da die Windows.pas von Borland ziemlich alt ist, muss man die WTSxyz Funktionen von hand einbaun, du brauchst aber nur die beiden + 2 Konstanten:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
unit simpleWTS;

interface

uses
   Windows;

function WTSRegisterSessionNotification(hWnd: HWND; dwFlags: DWORD): BOOL; stdcall;
function WTSUnRegisterSessionNotification(hWND: HWND): BOOL; stdcall;

const
   NOTIFY_FOR_ALL_SESSIONS  = 1;
   NOTIFY_FOR_THIS_SESSIONS = 0;
   
implementation

function WTSRegisterSessionNotification; external 'wtsapi32.dll' name 'WTSRegisterSessionNotification';
function WTSUnRegisterSessionNotification; external 'wtsapi32.dll' name 'WTSUnRegisterSessionNotification';

end.



in deiner Form sieht das dann so aus:

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:
   TfrmMain = class(TForm)
      label1 : TLabel;
      procedure FormCreate(Sender: TObject);
      private
         FintLockedCount : Integer;
         procedure WndProc(var Message: TMessage); override;
      public         
   end;

{ .... }


procedure TfrmMain.WndProc(var Message: TMessage);
begin
   Case Message.Msg of
      WM_WTSSESSION_CHANGE:
            begin
               if Message.WParam = WTS_SESSION_LOCK then begin
                  inc(FintLockedCount);                  
               end;
               if Message.WParam = WTS_SESSION_UNLOCK then begin
                  label1.caption := 'Die Session wurde bereits ' + IntToStr(FintLockedCount) + ' mal gesperrt.';               
               end;
            end;
   end;
   inherited;
end;

procedure TfrmMain.FormCreate(Sender: TObject);
begin
   WTSRegisterSessionNotification(handle,NOTIFY_FOR_ALL_SESSIONS);
   FintLockedCount := 0;   
end;


Achtung: funktioniert nur unter Windows XP, weil erst da die WTSxyz funktionen drin sind.
viel spaß!

_________________
Im Nachhinein ist man immer ein Schlauch!
"Dream as if you'll live forever, live as if you'll die today!" James Dean