消息无法响应......

mdejtod 2008-08-19 11:44:59
定义一个线程类
//用线程来检测系统配置
TSysDetectThd = Class (TThread)
private
FForm: TForm;
protected
Procedure Execute; Override;
public
constructor Create(AForm: TForm);
end;

在 procedure TSysDetectThd.Execute; 事件中向另一个窗体FrmSysDetect 发自定义的消息
procedure TSysDetectThd.Execute;
begin
inherited;
FreeOnTerminate := True;

TFrmSysDetect(FForm).IsSysDetecting := True;

if not Assigned(FForm) then Exit;
if not Func_GetVersionDirectX() then
begin
if not Assigned(FForm) then Exit;
PostMessage(FForm.Handle, WM_ShowSysDetect, 0, 0);
end
else
begin
if not Assigned(FForm) then Exit;
PostMessage(FForm.Handle, WM_ShowSysDetect, 0, 1);
end;
showmessage('one');
Sleep(500);
if not Assigned(FForm) then Exit;
if not Func_GetVersionMedia() then begin
if not Assigned(FForm) then Exit;
PostMessage(FForm.Handle, WM_ShowSysDetect, 1, 0);
end
else begin
if not Assigned(FForm) then Exit;
PostMessage(FForm.Handle, WM_ShowSysDetect, 1, 1);
end;
showmessage('two');
Sleep(500);
if not Assigned(FForm) then Exit;
if Func_IsHaveSoundCard() < 1 then begin
if not Assigned(FForm) then Exit;
PostMessage(FForm.Handle, WM_ShowSysDetect, 2, 0)
end
else begin
if not Assigned(FForm) then Exit;
PostMessage(FForm.Handle, WM_ShowSysDetect, 2, 1);
end;
showmessage('three');
TFrmSysDetect(FForm).IsSysDetecting := False;
end;
//这里进来后,可以正常的 showmessage

//窗体中的定义如下:
const WM_ShowSysDetect = WM_USER + $040; //显示系统配置检测结果
procedure ShowSysConf(var Msg: TMessage); message WM_ShowSysDetect;//消息处理事件


procedure TFrmSysDetect.ShowSysConf(var Msg: TMessage);
begin
Case Msg.WParam of
0: //DirectX版本检测
begin
if Msg.LParam = 1 then
imgDXState.Picture := imgYes.Picture;
if Msg.LParam = 0 then
imgDXState.Picture := imgNo.Picture;
imgDXState.Visible := True;
GSystemParam.DirectX := Integer(True);
// ShowMessage(IntToStr(Msg.WParam));
end;
1: //MediaPlayer版本检测
begin
if Msg.LParam = 1 then
imgMPState.Picture := imgYes.Picture;
if Msg.LParam = 0 then
imgMPState.Picture := imgNo.Picture;
imgMPState.Visible := True;
GSystemParam.MediaPlayer := Integer(True);
// ShowMessage(IntToStr(Msg.WParam));
end;
2: //声卡检测
begin
if Msg.LParam = 1 then
imgAUState.Picture := imgYes.Picture;
if Msg.LParam = 0 then
imgAUState.Picture := imgNo.Picture;
imgAUState.Visible := True;
GSystemParam.SoundCard := Integer(True);
// ShowMessage(IntToStr(Msg.WParam));
end;
end;
end;

在窗体显示时启动线程:
TSysDetectThd.Create(Self);

现在问题是,为何单步跟踪时就可以进入到消息处理事件ShowSysConf中执行,如果不单步,则只能接收到第一个消息,也就是只能showmessage(0),然后程序界面就S在那里了,请问是否消息没有同步?要如何做?感觉很奇怪,在D7下面很正常,放到2007下面就不行了
...全文
61 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
jacknes009 2008-08-21
  • 打赏
  • 举报
回复
加上同步对象同步
mdejtod 2008-08-20
  • 打赏
  • 举报
回复
怎么加同步对象?
手指风 2008-08-20
  • 打赏
  • 举报
回复
你在每个if里加上同步对象同步下看看
mdejtod 2008-08-20
  • 打赏
  • 举报
回复
一次就够了啊,每次创建窗体时都会创建线程,在线程里不止 PostMessage 了一次..是三次
晕S我了,单个程序没问题,很正常的,集成到软件里面就接收不到,
DumDum 2008-08-20
  • 打赏
  • 举报
回复
你的线程不是循环的,只会执行一次,所以只会PostMessage一次,那么也只会执行ShowSysConf一次,所以也只会showmessage(0)一次,你的程序没有问题~~!
mdejtod 2008-08-19
  • 打赏
  • 举报
回复
showmessage 只是想看下它到底有没有发消息出去,Postmessage() 中的窗体句柄是创建线程时赋过去的..
至于uses,只是将消息定义在窗体单元中,没有定义到线程单元中..
DelphiFans 2008-08-19
  • 打赏
  • 举报
回复
上面写错,我经常这样用
PostMessage(窗体句柄,WM_DOSOME ,1,1);
DelphiFans 2008-08-19
  • 打赏
  • 举报
回复
其实没有必要把窗体加进去,通过消息完全就可以实现
在线程单元定义和窗体单元做相同定义

Const
WM_DOSOME = WM_USER + 100;


线程中直接只要取到窗体句柄即可。
PostMessage(窗体句柄,WM_USER ,1,1);
即可,在线程中不要用SHOWMESSAGE之类
mdejtod 2008-08-19
  • 打赏
  • 举报
回复
怎么都没人呢?

16,748

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 语言基础/算法/系统设计
社区管理员
  • 语言基础/算法/系统设计社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧