How to close a "folder"

2

I have a project in Delphi 2010 that when I click on a button opens a directory, this is the code:

DirFolder := 'C:\teste';
ShellExecute(Handle, 'open', PChar(DirFolder), nil, nil, SW_SHOWNORMAL);

Open this:

I leave the question, is it possible when I close the project to also close this folder?

    
asked by anonymous 12.10.2016 / 17:09

1 answer

3

There are several ways to do this, one of which is to use the FindWindow " to return the window identifier through the class name or title.

To close, you can use the SendMessage and use the sign WM_CLOSE to indicate that the application should be terminated.

See an example:

procedure TForm1.Button2Click(Sender: TObject);
var
  Janela: THandle;
begin
  Janela := FindWindow(nil, 'teste'); // "teste" é o título da janela
  if Janela > 0 then // Se conseguir encontrar a janela
     SendMessage(Janela, WM_CLOSE, 0, 0);
end;
    
12.10.2016 / 17:38