Autor Beitrag
maxk
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: So 12.10.03 01:11 
Hi,

ich versuche mit PostMessage(HWND_BROADCAST,WM_USER+1234,0,0); an alle Fenster zu broadcasten. Leider erfolglos. Der Codes des Empfängers:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
type
  TForm1 = class(TForm)
    procedure DoMsg(var Msg:TMessage); message (WM_USER+1234);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.DoMsg(var Msg:TMessage);
begin
 ShowMessage('Message angekommen');
end;
Leider funktioniert das Ganze nicht - Was mache ich falsch?

Danke schon mal,
maxk

Moderiert von user profile iconTino: Code- durch Delphi-Tags ersetzt.

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
Luckie
Ehemaliges Mitglied
Erhaltene Danke: 1



BeitragVerfasst: So 12.10.03 05:14 
So geht es irgendwie auch nicht:
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:
const
  MY_MESSAGE = WM_USER+1974;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private-Deklarationen }
  public
    { Public-Deklarationen }
  protected
    procedure WndProc(var msg: TMessage); override;
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.WndProc(var msg: TMessage);
begin
  case msg.Msg of
    MY_MESSAGE: ShowMessage('Angekommen. :o)');
  end;
  inherited;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  PostMessage(HWND_BROADCAST, MY_MESSAGE, 00);
end;

Wenn ich das Handle einsetzte geht es.
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: So 12.10.03 11:08 
geht einfacher:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
type
  TMyFOrm = CLass(TForm);
  public
  procedure WMBroadCastMessage(var Msg:TMessage);Message my_Message;
end;


ausblenden Delphi-Quelltext
1:
2:
3:
4:
procedure TMyForm.WMBroadCastMessage;
begin
  // enter code here
end;

Das Problem ist, die MessageFunktion muss im public Teil stehen.!!

grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: So 12.10.03 13:17 
Es ist egal ob solche Message-Handler public, private oder protected sind.. ich hab auch mal ein paar Sachen ausprobiert, bin mit SendMessage/PostMessage aber auch nicht weitergekommen. Aber mit BroadcastSystemMessage funktioniert es problemlos:
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:
unit Unit1;

interface

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

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    WM_BroadCast: DWord;
    procedure WndProc(var Message: TMessage); override;
  end;

var
  Form1: TForm1;  

implementation

{$R *.dfm}

{ TForm1 }

procedure TForm1.WndProc(var Message: TMessage);
begin
  if Message.Msg = WM_BroadCast then
    ShowMessage('Angekommen')
  else
    inherited;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  BroadcastSystemMessage(BSF_FORCEIFHUNG or BSF_POSTMESSAGE, nil, WM_BroadCast, 00);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
  WM_BroadCast := RegisterWindowMessage('WM_BroadCast');
end;

end.

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!
maxk Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic starofftopic star
Beiträge: 1696
Erhaltene Danke: 1

Win XP, Debian Lenny
Delphi 6 Personal
BeitragVerfasst: So 12.10.03 19:46 
Motzi hat folgendes geschrieben:
Aber mit BroadcastSystemMessage funktioniert es problemlos:
Das wäre meine nächste Frage gewesen. Ich komme mit den Parametern nicht so recht zu Recht. Delphi meint, dass die in der Hilfe erwähnte Konstante vom falschen Typ wäre. (integer<>PDWord)

_________________
Ein Computer wird das tun, was Du programmierst - nicht das, was Du willst.
Tana´Ri
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 230



BeitragVerfasst: Mo 13.10.03 09:11 
also wenn ich mich recht entsinne (hab irgendwie nimmer im sdk o. help gefunden) werden Messages mit HWND_BROADCAST nur an die Top-Level Fenster der Z-Order gesendet.

PDWord = ^DWord; Pointer auf ein DWord

geht wohl um den Parameter -> lpdwRecipients
Zeiger auf Variable (DWord) die eine Kombination, der Values aus der Hife, repräsentiert (was eine addition der Konstanten bedeutet). Sodas mit einer logischen Und-Verknüpfung die gesetzten Eigenschaften der Message zu tragen kommt.

_________________
mfg
Tana´Ri
Motzi
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2931

XP Prof, Vista Business
D6, D2k5-D2k7 je Prof
BeitragVerfasst: Mo 13.10.03 11:13 
Schau dir einfach meinen Code an, da verwend ich BroadcastSystemMessage... einfach als 2ten Parameter nil angeben...

_________________
gringo pussy cats - eef i see you i will pull your tail out by eets roots!