Link to home
Avatar of mhieta
mhieta

asked on

Waiting for window closing...

Hi!,

I have started Painter program with my program. Question is:
In the Painter programs "Export settings" window. My program clicks button witch executes "Retrieving data" window.
So i have to wait in my program until "Retrieving data" window closes.
And then in my program i can continue...
So how can i do that?

Regards Marko
Avatar of Igor UL7AAjr
Igor UL7AAjr
Flag of Kazakhstan image

Hi Marko,

Use .ShowModal method instead .Show. It will wait while modal form closed.

-----
Igor.

procedure TForm1.SpeedButton3Click(Sender: TObject);
begin
   FRetrieveData.ShowModal;
end;
Avatar of jeurk
jeurk

Wait for it to close :

procedure WaitForCMWindowClose(WindowName: string);
begin
  while WindowExist(WindowName) do
  begin
    application.ProcessMessages;
  end;
end;

function WindowExist(WindowName: string): boolean;
begin
  result := False;
  if getWindowHandle(WindowName, 'Your WindowClass') <> 0 then
  begin
    result := True;
  end;
end;

function getWindowHandle(WindowCaption: string; WindowClass: string): THandle;
begin //we should try to lowercas everything one day.
  fWindowCaption := WindowCaption;
  fWindowClass := WindowClass;
  result := 0;
  EnumWindows(@getCMChildWinHandle, Integer(@result));
end;

function getCMChildWinHandle(WinHandle: THandle; FoundWindow: PHandle): BOOL; stdcall;
var
  Buffer: array[0..50] of Char;
begin
  Result := True;
  GetClassName(WinHandle, Buffer, SizeOf(Buffer) - 1);
  if pos(PChar(fWindowClass), Buffer) <> 0 then
  begin
    GetWindowText(WinHandle, Buffer, SizeOf(Buffer) - 1);
    if Pos(fWindowCaption, Buffer) <> 0 then
    begin
      FoundWindow^ := WinHandle;
      Result := False;
    end;
  end;
end;


CU



Avatar of mhieta

ASKER

Hi jeurk!,

Where i should declare those functions?

Regards Marko
ASKER CERTIFIED SOLUTION
Avatar of jeurk
jeurk

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of mhieta

ASKER

Answer accepted
Avatar of mhieta

ASKER

Thank you jeurk! Now my program finally waits...

Regards Marko
I'm glad it helped you.
See you in another thread...