关于MsgWaitForMultipleObjects的应用。

litangel 2007-09-17 10:48:35
clever internet suite套件。

里面的HTTP控件,在下载文件呀上传文件的时候,这时点窗口关闭,根本不起作用。
所以想改一下。

找到如下函数:

function WaitForEvent(AEvent: THandle; ATimeOutTicks, ATimeOut: Integer): Boolean;
var
res: DWORD;
Msg: TMsg;
events: array[0..0] of THandle;
begin
events[0] := AEvent;
res := MsgWaitForMultipleObjects(1, events, FALSE, DWORD(ATimeOut), QS_ALLEVENTS);
case res of
WAIT_FAILED:
begin
RaiseSocketError(WSAGetLastError());
end;
WAIT_TIMEOUT:
begin
RaiseSocketError(cTimeoutOccured, -1);
end;
WAIT_OBJECT_0 + 1:
begin
while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do
begin
//add start
if Msg.message in [WM_CLOSE] then
begin
Break;
end;
//add end

TranslateMessage(Msg);
DispatchMessage(Msg);
if Integer(GetTickCount()) - ATimeOutTicks > ATimeOut then
begin
RaiseSocketError(cTimeoutOccured, -1);
end;
end;
if Integer(GetTickCount()) - ATimeOutTicks > ATimeOut then
begin
RaiseSocketError(cTimeoutOccured, -1);
end;
end;
end;
Result := (res = WAIT_OBJECT_0);
end;


我加入如下代码:
//add start
if Msg.message in [WM_CLOSE] then
begin
Break;
end;
//add end

根本不起作用。


请问高手,能帮忙解决一下吗?
...全文
459 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bee2518 2007-09-19
  • 打赏
  • 举报
回复
MsgWaitForMultipleObjects处理WM_CLOSE不会调到WAIT_OBJECT_0 + 1中,就肯定不会发生作用了
ERR0RC0DE 2007-09-17
  • 打赏
  • 举报
回复
WaitForEvent是在次线程还是主线程调用?
hongqi162 2007-09-17
  • 打赏
  • 举报
回复
试试这样
if Msg.message = WM_CLOSE then
begin
PostQuitMessage(Msg.wParam);
Break;
end;
ERR0RC0DE 2007-09-17
  • 打赏
  • 举报
回复
PeekMessage(Msg, 0, 0, 0, PM_REMOVE)
是会将所有的APP消息取出。
那有可能是处理一条消息耗时N久,那就有可能还未取WM_CLOSE消息时就超时了。

另:将if Msg.message in [WM_CLOSE] then改掉。in操作好像只限于0..255值之间
brightyang 2007-09-17
  • 打赏
  • 举报
回复
up一下
litangel 2007-09-17
  • 打赏
  • 举报
回复
WaitForEvent是在主线程调用

1,183

社区成员

发帖
与我相关
我的任务
社区描述
Delphi Windows SDK/API
社区管理员
  • Windows SDK/API社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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