讨论一下delphi的消息机制(100分)

  • 主题发起人 主题发起人 heidongzhiling
  • 开始时间 开始时间
H

heidongzhiling

Unregistered / Unconfirmed
GUEST, unregistred user!
各位大虾:
我个人认为delphi中得事件是由消息触发的,而消息的触发到底是根据的是啥?
象buttonclick等可以说是内置但是象那些不是标准的事件,他的处理流程是啥?
希望能给清楚,最好能比marco讲得清楚.我太愚笨!!
 
呵呵,想清楚这个的都是好同志:
看看c-view免费杂志的第一期----第n期
http://www.c-view.org/root/index.htm
 
当然是根据Windows 底层的消息来源了。
Buttonclick 不是消息,它是被其它过程处理过的,然后调用用户的Buttonclick 程序段
看一下 VC方面的书吧!对你会有所帮助
 
可以看看下边的文章:

http://www.delphibbs.com/delphibbs/dispq.asp?lid=597873
 
你们能不能看一下面的代码,并且给我解释一下消息循环是不是循环队列呢?是不是一个消息被执行后就将其去除?
unit PostForm;

interface

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

type
TFormManyMess = class(TForm)
LBox: TListBox;
Button1: TButton;
ButtonPost: TButton;
ButtonSend: TButton;
ButtonPerform: TButton;
ButtonMouseDown: TButton;
ButtonOnMouseDown: TButton;
procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure Button1Click(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure ButtonPostClick(Sender: TObject);
procedure ButtonSendClick(Sender: TObject);
procedure ButtonPerformClick(Sender: TObject);
procedure ButtonMouseDownClick(Sender: TObject);
procedure ButtonOnMouseDownClick(Sender: TObject);
private
{ Private declarations }
public
procedure WndProc(var Message: TMessage); override;
procedure DefaultHandler(var Message); override;
procedure WmLButtonDown (var Message: TWMMouse);
message wm_lButtonDown;
procedure MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer); override;
procedure ApplicationMessage (var Msg: TMsg;
var Handled: Boolean);
end;

var
FormManyMess: TFormManyMess;

implementation

{$R *.DFM}

procedure TFormManyMess.FormMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState;
X, Y: Integer);
begin
if Button = mbLeft then
LBox.Items.Add (Format ('%s in (%d, %d)',
['FormMouseDown', X, Y]));
end;

procedure TFormManyMess.WndProc(var Message: TMessage);
begin
if Message.Msg = wm_LButtonDown then
LBox.Items.Add (Format ('%s in (%d, %d)',
['WndProc', LoWord (Message.LParam),
HiWord (Message.LParam)]));
inherited;
end;

procedure TFormManyMess.DefaultHandler(var Message);
begin
with TMessage (Message) do
if Msg = wm_LButtonDown then
LBox.Items.Add (Format ('%s in (%d, %d)',
['DefaultHandler', LoWord (LParam),
HiWord (LParam)]));
inherited;
end;

procedure TFormManyMess.WmLButtonDown (var Message: TWMMouse);
begin
LBox.Items.Add (Format ('%s in (%d, %d)',
['WmLButtonDown', Message.XPos, Message.YPos]));
inherited;
end;

procedure TFormManyMess.MouseDown(Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
begin
if Button = mbLeft then
LBox.Items.Add (Format ('%s in (%d, %d)',
['MouseDown', X, Y]));
inherited;
end;

procedure TFormManyMess.ApplicationMessage (var Msg: TMsg;
var Handled: Boolean);
begin
if (Msg.Message = wm_LButtonDown) and
(Msg.hWnd = Handle) then
LBox.Items.Add (Format ('%s in (%d, %d)',
['ApplicationMessage', LoWord (Msg.LParam),
HiWord (Msg.LParam)]));
Handled := False;
end;

procedure TFormManyMess.FormCreate(Sender: TObject);
begin
Application.OnMessage := ApplicationMessage;
end;

procedure TFormManyMess.Button1Click(Sender: TObject);
begin
LBox.Clear;
end;

procedure TFormManyMess.ButtonPostClick(Sender: TObject);
begin
LBox.Items.Add (' --- PostMessage ---');
PostMessage (Handle, wm_lButtonDown,
0, MakeLong (10, 10));
PostMessage (Handle, wm_lButtonUp,
0, MakeLong (10, 10));
end;

procedure TFormManyMess.ButtonSendClick(Sender: TObject);
begin
LBox.Items.Add (' --- SendMessage ---');
SendMessage (Handle, wm_lButtonDown,
0, MakeLong (10, 10));
SendMessage (Handle, wm_lButtonUp,
0, MakeLong (10, 10));
end;

procedure TFormManyMess.ButtonPerformClick(Sender: TObject);
begin
LBox.Items.Add (' --- Perform ---');
Perform (wm_lButtonDown,
0, MakeLong (10, 10));
Perform (wm_lButtonUp,
0, MakeLong (10, 10));
end;

procedure TFormManyMess.ButtonMouseDownClick(Sender: TObject);
begin
LBox.Items.Add (' --- MouseDown ---');
MouseDown (mbLeft, [], 10, 10);
end;

procedure TFormManyMess.ButtonOnMouseDownClick(Sender: TObject);
begin
LBox.Items.Add (' --- OnMouseDown ---');
OnMouseDown (self, mbLeft, [], 10, 10);
end;

end.
 
学习。。。
 
我原本还想得到更好的解释,但看来只有如此
感谢大家的支持!
愿你们的留下更多的code!!!
 
后退
顶部