我封装了一个ocx控件,里面封装了一个下载窗体,下载窗体有一个时钟事件用于在该窗体中显示下载文件的进度。这个事件当单击下载窗体的下载按钮时被激发。
在外部主窗体利用了ocx组件,主窗体文件主函数我向下载窗体发送postmessage表示下载文件完了,紧接着主函数调用了exit函数退出主函数。在下载窗体中写了相应的处理函数(当然包括终止timer事件),但是奇怪的是下载窗体在关闭之前处理函数没有被执行,timer继续执行,显示进度这个时候当然一直是100%。是exit造成的原因,还是timer事件执行的不确定性,造成处理消息的函数没有执行,先谢谢了,大家帮我解答下
在外部主窗体利用了ocx组件,主窗体文件主函数我向下载窗体发送postmessage表示下载文件完了,紧接着主函数调用了exit函数退出主函数。在下载窗体中写了相应的处理函数(当然包括终止timer事件),但是奇怪的是下载窗体在关闭之前处理函数没有被执行,timer继续执行,显示进度这个时候当然一直是100%。是exit造成的原因,还是timer事件执行的不确定性,造成处理消息的函数没有执行,先谢谢了,大家帮我解答下
解决方案 »
- cx控件的问题
- 怎么删除???
- 无法正确截获QQ密码框信息
- 没事玩,大家玩过XP的讲述人么?
- 如何使用delphi7连接C#创建的webservices
- 怎样写程序将另一台电脑上的共享文件夹映射成本地硬盘?
- 重画Cell颜色
- 急!!! MSComm中output的输出类型问题(输出字符要求转化为hex 16进制) : delphi中如何声明16进制数 ?
- 你参加了Borland的全球认证考试了吗?
- 在写DCOM时出现了一个错误提示“Mismatch in datapacket”这是为什么?
- 急用:如何将图片文件(.jpg)进行Base64编码?!!
- 求一日期转换方法,如2010-10-15转换成二○一○-十-十五?
而PostThreadMessage是用来发送消息的。
具体的参数定义、用法参考 Help吧。
PeekMessage的第一个参数 @Msg ,在Delphi里是 TMsg, 你可以这样定义: var MyMsg : TMsg;
下面的代码瞎写的,请大家指正: ////////////////// main.pas //////////////
unit main; interface uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls,MyThread;
const
WM_MyMessage=WM_USER+100;
type
TForm1 = class(TForm)
BtnQuitThread: TButton;
ListBox1: TListBox;
BtnPost: TButton;
BtnStart: TButton;
BtnExit: TButton;
procedure BtnQuitThreadClick(Sender: TObject);
procedure BtnStartClick(Sender: TObject);
procedure BtnPostClick(Sender: TObject);
procedure BtnExitClick(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
MyThread : MsgThread;
end; var
Form1: TForm1; implementation {$R *.DFM} procedure TForm1.BtnQuitThreadClick(Sender: TObject);
begin
// MyThread.Terminate;
if MyThread = nil then exit; if PostThreadMessage(MyThread.ThreadID,
WM_QUIT,0,0) then
Caption := 'Post Message Ok! '
else
Caption := 'Post Message Fail! ';
end; procedure TForm1.BtnStartClick(Sender: TObject);
begin
if (MyThread = nil) then
MyThread := MsgThread.Create(false);
end; procedure TForm1.BtnPostClick(Sender: TObject);
begin
if MyThread = nil then exit; if PostThreadMessage(MyThread.ThreadID,
WM_MyMessage,0,0) then
Caption := 'Post Message Ok! '
else
Caption := 'Post Message Fail! ';
end; procedure TForm1.BtnExitClick(Sender: TObject);
begin
MyThread.Free;
Close;
end; end.
///////////// MyThread.pas/////////////////
unit MyThread; interface uses
Classes,windows, Messages; const
WM_MyMessage=WM_USER+100;
type
MsgThread = class(TThread)
private
{ Private declarations }
FMyString : string;
protected
procedure Execute; override;
procedure ShowString;
end; implementation { Important: Methods and properties of objects in VCL can only be used in a
method called using Synchronize, for example, Synchronize(UpdateCaption); and UpdateCaption could look like, procedure PMessage.UpdateCaption;
begin
Form1.Caption := 'Updated in a thread ';
end; } { PMessage }
uses Main; procedure MsgThread.Execute;
var Msg : TMsg;
begin
{ Place thread code here }
FMyString := 'Thread Start! ';
Synchronize(ShowString); while (not Terminated) do
begin
if PeekMessage(Msg,0,0,0,PM_REMOVE) then
begin
if (Msg.message = WM_QUIT) then
begin
FMyString := 'Thread Quit ';
Synchronize(ShowString);
Terminate;
end;
if (Msg.message = WM_MyMessage) then
begin
FMyString := 'Thread Get a USER Message! ';
Synchronize(ShowString);
end;
end;
end;
end; procedure MsgThread.ShowString;
begin
Form1.ListBox1.Items.Add(FMyString);
end; end.
没有数字签名的文件不允许向有数字签名的文件发送
没有管理员权限的文件不允许向其他程序发送设置你程序管理员身份运行,并且接受方没有数字签名才可以