2004. február 9., hétfő

Display a Property dialog for file, folder or drive


Problem/Question/Abstract:

How display the standard Property dialog for file, folder or drive?

Answer:

Sometimes you need show the standard dialog with file properties from own application (especially if you develop some file manager)

You may easy solve this task - just run next code:

function ShowFilePropertiesDialog(hWndOwner: HWND; const FileName: string): Boolean;
var
  Info: TShellExecuteInfo;
begin
  { Fill in the SHELLEXECUTEINFO structure }
  with Info do
  begin
    cbSize := SizeOf(Info);
    fMask := SEE_MASK_NOCLOSEPROCESS or
      SEE_MASK_INVOKEIDLIST or
      SEE_MASK_FLAG_NO_UI;
    wnd := hWndOwner;
    lpVerb := 'properties';
    lpFile := pChar(FileName);
    lpParameters := nil;
    lpDirectory := nil;
    nShow := 0;
    hInstApp := 0;
    lpIDList := nil;
  end;

  { Call Windows to display the properties dialog. }
  Result := ShellExecuteEx(@Info);
end;

This is the same dialog box that Windows Explorer displays when viewing an object's properties. For example, from this dialog user can change permissions for folder or check free space for drive.

You may specify a file name or folder name or drive letter. For example:

ShowFilePropertiesDialog(Application.Handle, 'd:\debit.xls')

or

ShowFilePropertiesDialog(Application.Handle, 'd:\Oracle')

or

ShowFilePropertiesDialog(Application.Handle, 'd:\')

Nincsenek megjegyzések:

Megjegyzés küldése