How to close a "folder"

Asked

Viewed 210 times

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:

inserir a descrição da imagem aqui

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

  • when you say folder, refers to Windows folder?

  • yes windows folder, this is her directory: "C: test"

1 answer

3


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

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

Take 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;
  • 1

    thanks for the explanation, that’s just what I needed!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.