postmessage问题 (100分)

  • 主题发起人 主题发起人 weiowen
  • 开始时间 开始时间
W

weiowen

Unregistered / Unconfirmed
GUEST, unregistred user!
我在线程用SMTP循环截取数据发邮件,每发一封邮件用postmessage返回信息给主进程的
ipos接收,看发了多少封邮件,这个消息机制要怎样写?
 
学习,帮你up
 
在主进程定义一个全局变量,在开始收时初始化为0,然后在定义一个自定义消息,当收
到一个消息时将变量加1,在非主线程中只要将这个消息向主窗口post就行了,自定义消
息你懂吧,以前的贴子很多的
 
可以把代码贴出来吗?谢谢
 
其实在一个程序里没必要这么复杂,写个函数通知就是了。
 
如果你非要用PostMessage,如下:
方法一:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
Const
CM_ParaMESSAGE = WM_USER + $1001;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
procedure RestoreRequest(var cmessage: TMessage);
message CM_ParaMESSAGE;
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.DFM}
procedure TForm1.RestoreRequest(var cmessage: TMessage);
begin

cmessage.Result := 1;
ShowMessage('hello');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(Handle, CM_ParaMESSAGE, 0, 0);
end;

end.

===============================================================================
方法2:
unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure FormCreate(Sender: TObject);
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
procedure WndProc(var Mess: TMessage);
override;
end;

var
Form1: TForm1;
MyMsg: UINT;
implementation
{$R *.DFM}
procedure TForm1.WndProc(var Mess: TMessage);
begin
if mess.Msg = MyMsg then
begin
ShowMessage('hello');
end;
inherited;
end;

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

procedure TForm1.Button1Click(Sender: TObject);
begin
PostMessage(Handle,MyMsg,0,0);
end;

end.
 
多人接受答案了。
 

Similar threads

S
回复
0
查看
636
swish
S
D
回复
0
查看
1K
DelphiTeacher的专栏
D
D
回复
0
查看
875
DelphiTeacher的专栏
D
后退
顶部