关于MsgWaitForMultipleObjects的应用。
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
根本不起作用。
请问高手,能帮忙解决一下吗?
[解决办法]
试试这样if Msg.message = WM_CLOSE thenbegin PostQuitMessage(Msg.wParam); Break;end;
[解决办法]
WaitForEvent是在次线程还是主线程调用?
[解决办法]
up一下
[解决办法]
PeekMessage(Msg, 0, 0, 0, PM_REMOVE)
是会将所有的APP消息取出。
那有可能是处理一条消息耗时N久,那就有可能还未取WM_CLOSE消息时就超时了。
另:将if Msg.message in [WM_CLOSE] then改掉。in操作好像只限于0..255值之间
[解决办法]
MsgWaitForMultipleObjects处理WM_CLOSE不会调到WAIT_OBJECT_0 + 1中,就肯定不会发生作用了