消息无法响应......
定义一个线程类
//用线程来检测系统配置
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下面就不行了