VCL TTimer stops when the drag and drop button is pressed

I have it TTimerturned on and should start without stops forever until the user stops it. However, this does not work. In an event, OnTimerit processes window messages over and over in milliseconds.

For example, here is a snippet of code.

procedure TDXCommDlg.Timer2Timer(Sender: TObject);
begin
  inherited;
  if Scanning then
  begin
    Timer1.Enabled := false;
    Timer2.Enabled := false;
     while not PostMessage(Handle,WM_USER + 10,1234,5678) do;
     Timer1.Enabled := true;
  end;
end;

What happens is this. While TTimer is turned on and running, you drag all the windows of the application or click on the drop-down menu, the TTimer event completely stops working, although I took precautions in another part of the code to prevent this from happening. However, this does not seem to help.

The only way to restart the event OnTimeris to stop and restart the timer by the user through the TButton event.

Windows XP, Delphi 7. Windows 7 Delphi 2010 .

. , .

HandleMsg. . HandleMsg onMessage;

Application.OnMessage: = HandleMsg();

PostMessage onMessage .

PostMessage, onMessage, HandleMsg().

:

 procedure TDXCommDlg.HandleMsg(var
 Msg: TMsg; var Handled: Boolean);
 begin
      Handled := false;
      case Msg.message of
      WM_USER + 10:
              begin
                   if (Msg.wParam = 1111) and (Msg.lParam = 2222) then
                   begin
                     SendLanMessage;
                     Handled := true;
                   end
                   else if (Msg.wParam = 1234) and (Msg.lParam = 5678) then
                   begin
                        SendMessage;
                        Handled := true;
                   end
                   else
                   begin
                     if (Msg.wParam = 4321) then
                     begin
                       MainFrm.CloseWindow(TViewFrm(Msg.lParam).WinCap);
                     end;
                   end;
              end;
      end; { case } end;

HandleMsg() PostMessage. , .

+3
2

( / ) , TApplication.ProcessMessage, WM_NCLBUTTONDOWN ( WM_NCRBUTTONDOWN, .. WM_RBUTTONUP, ..). , .

, WM_ENTERSIZEMOVE:

WM_ENTERSIZEMOVE . [....] , DefWindowProc.

HandleMessage TApplication.Run , DefWindowProc (, WM_NCLBUTTONDOWN WM_SYSCOMMAND , , /). , OnMessage , TApplication.ProcessMessage.

. OnMessage :

const
  WMUSER_10 = WM_USER + 10;

type
  TForm1 = class(TForm)
    Timer1: TTimer;
    procedure Timer1Timer(Sender: TObject);
  private
    procedure WmUser10(var Msg: TMsg); message WMUSER_10;
  public
  end;

procedure TForm1.Timer1Timer(Sender: TObject);
begin
  PostMessage(Handle, WMUSER_10, 1234, 5678);
end;

procedure TForm1.WmUser10(var Msg: TMsg);
begin
  //
end;


, OnTimer, WM_TIMER .

+6

. Windows , . , , . . , , . .

, , WM_USER, , - , . , , , .

0

Source: https://habr.com/ru/post/1795506/


All Articles