Einzelnen Beitrag anzeigen

EWeiss
(Gast)

n/a Beiträge
 
#5

Re: Formfenster soll wenn es inaktiv ist auf eingabe reagier

  Alt 4. Okt 2006, 21:22
Hier noch ein Beispiel!

Copy/Paste

Delphi-Quellcode:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    btnHook: TButton;
    edWndToHook: TEdit;
    lvMain: TListView;
    procedure btnHookClick(Sender: TObject);
  private
    { Private declarations }

  protected
    procedure _WMCopyData(var Msg: TWMCopyData); message WM_COPYDATA;

  public
    { Public declarations }
  end;

var
  Form1: TForm1;

  function InstallHook(DWThreadID: DWORD): boolean; stdcall external 'HookDLL.dll';

implementation

{$R *.dfm}

procedure TForm1.btnHookClick(Sender: TObject);


begin
  if not InstallHook(0) then // nicht dwThreadID übergeben, sondern 0, weil ALLE Applikationen gehookt werden sollen.
     raise Exception.Create('Error installing hook');

end;


procedure TForm1._WMCopyData(var Msg: TWMCopyData);
var
  aMsg: ^tagMsg;
begin
  aMsg := Msg.CopyDataStruct.lpData;

  with lvMain.Items.Add do
  begin
    Caption := IntToStr(aMsg^.time);
    SubItems.Add(IntToStr(aMsg^.message));
    SubItems.Add(IntToStr(aMsg^.wParam));
    SubItems.Add(IntToStr(aMsg^.lParam));
  end;
end;

end.
Unit1.dfm

Delphi-Quellcode:
object Form1: TForm1
  Left = 342
  Top = 107
  Width = 585
  Height = 263
  Caption = 'Form1'
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'MS Sans Serif'
  Font.Style = []
  OldCreateOrder = False
  PixelsPerInch = 96
  TextHeight = 13
  object btnHook: TButton
    Left = 8
    Top = 8
    Width = 97
    Height = 25
    Caption = 'Hook this window'
    TabOrder = 0
    OnClick = btnHookClick
  end
  object edWndToHook: TEdit
    Left = 112
    Top = 10
    Width = 321
    Height = 21
    TabOrder = 1
    Text = 'notepad'
  end
  object lvMain: TListView
    Left = 8
    Top = 40
    Width = 417
    Height = 177
    Columns = <
      item
        Caption = 'Time'
      end
      item
        Caption = 'Message'
        Width = 100
      end
      item
        Caption = 'wParam'
        Width = 100
      end
      item
        Caption = 'lParam'
        Width = 100
      end>
    TabOrder = 2
    ViewStyle = vsReport
  end
end
Gruß
  Mit Zitat antworten Zitat