Entwickler-Ecke

Windows API - Application.Processmessages() ohne TApplication Klasse


xi23 - Sa 17.08.02 16:07
Titel: Application.Processmessages() ohne TApplication Klasse
hi,
Ich habe ein Delphi Projekt ohne vordefiniertes Delphi TApplication Model und ohne ein Formular erstellt. Ich erstelle ein Formular selbst mit CreateWindowEx und verarbeite die Nachrichten mit MainWndProc und Get,Translate und Dispatch Message.
Ich will nun ein Sleep schreiben welches die Programmverarbeitung nicht unterbricht, diesen effekt konnte man mit Application.Processmessage erreichen.


GPF - So 18.08.02 02:24

Folgender Codeschnipsel stammt aus den Delphi 5 Sources. Ich hoffe ich verstoße damit nicht gegen irgendwelche Copyrightrechte:

Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
function TApplication.ProcessMessage(var Msg: TMsg): Boolean;
var
  Handled: Boolean;
begin
  Result := False;
  if PeekMessage(Msg, 0, 0, 0, PM_REMOVE) then
  begin
    Result := True;
    if Msg.Message <> WM_QUIT then
    begin
      Handled := False;
      if Assigned(FOnMessage) then FOnMessage(Msg, Handled);
      if not IsHintMsg(Msg) and not Handled and not IsMDIMsg(Msg) and
        not IsKeyMsg(Msg) and not IsDlgMsg(Msg) then
      begin
        TranslateMessage(Msg);
        DispatchMessage(Msg);
      end;
    end
    else
      FTerminate := True;
  end;
end;

procedure TApplication.ProcessMessages;
var
  Msg: TMsg;
begin
  while ProcessMessage(Msg) do {loop};
end;


toms - So 18.08.02 07:42


Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
function ProcessMessages: Boolean; 
var 
  Msg: TMsg; 
begin 
  Result := False; 
  while PeekMessage(Msg, 0, 0, 0, PM_REMOVE) do  
  begin 
    if Msg.Message = WM_QUIT then  
    begin 
      Result := True; 
      PostQuitMessage(Msg.wParam); 
      Exit; 
    end {If} 
    else 
      if not IsDialogMessage(GetActiveWindow, Msg) then 
    begin 
      TranslateMessage(Msg); 
      DispatchMessage(Msg); 
    end; {Else} 
  end; {While} 
end;