362 procedure TWin32WidgetSet.AppProcessMessages;
363 var
364 AMessage: TMsg;
365 retVal, index: dword;
366 pHandles: Windows.LPHANDLE;
367
368 procedure CallWaitHandler;
369 begin
370 FWaitHandlers[index].OnEvent(FWaitHandlers[index].UserData, 0);
371 end;
372
373 begin
374 repeat
375 if FPendingWaitHandlerIndex >= 0 then
376 begin
377 index := FPendingWaitHandlerIndex;
378 FPendingWaitHandlerIndex := -1;
379 CallWaitHandler;
380 end;
381 {$ifdef DEBUG_ASYNCEVENTS}
382 if Length(FWaitHandles) > 0 then
383 DebugLn('[ProcessMessages] WaitHandleCount=', IntToStr(FWaitHandleCount),
384 ', WaitHandle[0]=', IntToHex(FWaitHandles[0], 8));
385 {$endif}
386 if FWaitHandleCount > 0 then
387 pHandles := @FWaitHandles[0]
388 else
389 pHandles := nil;
390 retVal := Windows.MsgWaitForMultipleObjects(FWaitHandleCount,
391 pHandles, False, 0, QS_ALLINPUT);
392 if (retVal < WAIT_OBJECT_0 + FWaitHandleCount) then
393 begin
394 index := retVal-WAIT_OBJECT_0;
395 CallWaitHandler;
396 end else
397 if retVal = WAIT_OBJECT_0 + FWaitHandleCount then
398 begin
399 while PeekMessage(AMessage, HWnd(nil), 0, 0, PM_REMOVE) do
400 begin
401 if AMessage.message = WM_QUIT then
402 begin
403 PostQuitMessage(AMessage.wParam);
404 break;
405 end;
406 // Handle MDI form accelerators
407 if Assigned(Application) and
408 Assigned(Application.MainForm) and
409 (Application.MainForm.FormStyle=fsMDIForm) and
410 TranslateMDISysAccel(Win32WidgetSet.MDIClientHandle, @AMessage)
411 then begin
412 // handled by TranslateMDISysAccel
413 end else begin
414 TranslateMessage(@AMessage);
415 DispatchMessageW(@AMessage);
416 end;
417 end;
418 end else
419 if retVal = WAIT_TIMEOUT then
420 begin
421 // check for pending to-be synchronized methods
422 CheckSynchronize;
423 CheckPipeEvents;
424 break;
425 end else
426 if retVal = $FFFFFFFF then
427 begin
428 DebugLn('[TWin32WidgetSet.AppProcessMessages] MsgWaitForMultipleObjects returned: ', IntToStr(GetLastError));
429 break;
430 end;
431 until false;
432 end;