Autor Beitrag
DerNetteNachbar
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 224



BeitragVerfasst: Mo 02.02.09 15:01 
Hallo an alle, wie man aus dem Thread Titel erkennt versuche ich Nachrichten und zwar selbst definierte z.B.
ausblenden Delphi-Quelltext
1:
  WM_TEST = WM_USER + 5201;					

zu empfangen per diese Funktion
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure MessageReceiver(var msg: TMessage); message WM_TEST;
  
procedure TForm1.MessageReceiver(var msg: TMessage);
begin
  if Msg.Msg >= WM_TEST then
  ShowMessage('');
end;

So jetzt zum Problem: wenn ich die Message per Hand sende z.B. an das Formhandle klappt es. So:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
procedure TForm1.Button1Click(Sender: TObject);
var
  txt: string;
begin
  txt := 'Hello World';
  SendMessage(Form1.Handle, WM_TEST, 0, DWORD(PChar(txt)));
end;

Sobald ich aber das Form1.Handle durch das Application.Handle ersetze klappt es nicht mehr.
Kennt jemand eine Lösung damit es mit dem Application.Handle klappt?

Übrigens klappt es auch mit TApplicationEvents, allerdings nicht wenn Nachrichten in einer dll empfangen werden sollen.


MfG

DerNetteNachbar
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: Mo 02.02.09 15:31 
Das Application.Handle ist das Handle des unsichtabren Application Fensters. Warum willst du nachricghten an dieses fenster schicken. Oder anderes gefargt, warum nicht an das sichtbare Fenster deiner Anwendung?
DerNetteNachbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 224



BeitragVerfasst: Mo 02.02.09 16:00 
Es handelt sich um einen KeyHook, und der sendet nun mal die Tastendrücke an das Application.Handle. Die Frage jetzt wie ich das an das zuständige Fenster liefern kann. Wie schon gesagt mit dem TApplicationEvents klappt es da es in der Komponente weitergereicht wird.

MfG
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mo 02.02.09 18:44 
TApplication.HookMainWindow / TApplication.UnhookMainWindow
DerNetteNachbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 224



BeitragVerfasst: Mi 04.02.09 10:23 
Kannst du es mal erläutern, kann wenig damit anfangen.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 04.02.09 11:20 
Damit kannst du Windows Messages an TApplication.Handle abfangen. Ist das nicht, was du wolltest?
DerNetteNachbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 224



BeitragVerfasst: Mi 04.02.09 11:24 
Ja schon, aber ich verstehe den Zusammenhang noch nicht 100%.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 04.02.09 11:57 
Welchen Zusammenhang?
DerNetteNachbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 224



BeitragVerfasst: Mi 04.02.09 12:08 
den ganzen.
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 04.02.09 12:09 
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:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Forms;

type
  TForm1 = class(TForm)
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
  public
    function ApplicationWndProcHook(var Message: TMessage): Boolean;
  end;

var
  Form1: TForm1;

implementation

{$R *.DFM}

const
  UM_TEST = WM_USER + 1;

function TForm1.ApplicationWndProcHook(var Message: TMessage): Boolean;
begin
  case Message.Msg of
    UM_TEST:
      OutputDebugString('Message received!');
  end;
  Result := False;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  Application.HookMainWindow(ApplicationWndProcHook);
  PostMessage(Application.Handle, UM_TEST, 00);
end;

procedure TForm1.FormDestroy(Sender: TObject);
begin
  Application.UnhookMainWindow(ApplicationWndProcHook);
end;

end.
DerNetteNachbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 224



BeitragVerfasst: Mi 04.02.09 12:26 
Dank dir. Über Application und Form klappt es. Werde gleich versuchen es aus der DLL zu starten.

MfG
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 04.02.09 12:31 
Das Application-Objekt "in einem DLL" entspricht nicht dem Application-Objekt des Mainprogrammes. Die Registrierung des Hooks darf nicht in der DLL geschehen, denn du kannst auch grundsätzlich nicht einfach (Dephi-)Objekte zwischen DLLs hin und herschieben.
DerNetteNachbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 224



BeitragVerfasst: Mi 04.02.09 13:06 
Gibt es denn da eine Lösung?
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Mi 04.02.09 13:16 
Schreibe eine saubere Schnittstelle.
DerNetteNachbar Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 224



BeitragVerfasst: Mi 04.02.09 14:01 
Kannst du mir bitte ein Beispiel schreiben?