maxkleiner / maXbox4

code compiler script studio
GNU General Public License v3.0
23 stars 10 forks source link

application.onmessage hung #6

Closed maxkleiner closed 6 months ago

maxkleiner commented 7 years ago

by calling direct app.onmessage handler we get an app crash but indirect it works an we stop the loop with Q to quit:

while (GetMessage(Msg, 0, 0, 0)) And (Not msgstop) do begin
    inc(cnt)
    aUnicode:= (Msg.hwnd = 0);
     //or (IsWindowUnicode(Msg.hwnd));          
    TranslateMessage(Msg);
    if aUnicode then
      wDispatchMessage(Msg) else
        DispatchMessage(Msg);
        if msg.wparam = 81 then exit;    //Q sign
      //writeln(itoa(msg.wparam)+': '+itoa(msg.lparam)+' '+botostr(msgstop))
      PrintF('msg: %d of hwnd: %d, wpara: %d, lpara: %d, mess: %d',
             [cnt, msg.hwnd,msg.wparam,msg.lparam, msg.message]);  
    application.processmessages;         
    //else  
  //DispatchMessage(Msg);              

end;

maxkleiner commented 5 years ago

on linux or wine vms you should disable application.processmessages like Procedure ProcessMessagesOFF; //application.processmessages Procedure ProcessMessagesON; or {$IFDEF MSWINDOWS}

procedure TIdAntiFreeze_Process;
var
  Msg: TMsg;
  ApplicationHasPriority: boolean;
begin
  if ApplicationHasPriority then begin
    Application.ProcessMessages;
  end else begin
    // This guarantees it will not ever call Application.Idle
    if PeekMessage(Msg, 0, 0, 0, PM_NOREMOVE) then begin
      Application.HandleMessage;
    end;
  end;
end;
{$ENDIF}