Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Jul 20th, 2012  |  syntax: None  |  size: 2.31 KB  |  hits: 8  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. Get a handle to IFileDialog from a TFileDialogEvent to get the filename
  2. function TFileDialogEvent.OnButtonClicked(const pfdc: IFileDialogCustomize;
  3.   dwIDCtl: DWORD): HResult; stdcall;
  4. var
  5.   iImageEnIO: TImageEnIO;
  6.   iFilename: string;
  7.   iName: PChar;
  8.   pfd: IFileDialog;
  9. begin
  10.   if dwIDCtl = dwVisualGroup8ID then
  11.   begin
  12.     iImageEnIO := TImageEnIO.Create(nil);
  13.     try
  14.       FileDialog.QueryInterface(
  15.     StringToGUID('{8016B7B3-3D49-4504-A0AA-2A37494E606F}'),
  16.     pfd);
  17.     // How to get correct valid handle to IFileDialog?
  18.       pfd.GetFileName(iName);
  19.       iFilename := string(iName);
  20.       if FileExists(iFilename) then
  21.       begin
  22.        
  23. function TFileDialogEvent.OnButtonClicked(const pfdc: IFileDialogCustomize;
  24.   dwIDCtl: DWORD): HResult; stdcall;
  25. var
  26.   iImageEnIO: TImageEnIO;
  27.   iFilename: string;
  28.   pFolder: PWideChar;
  29.   iFolder: string;
  30.   iName: PChar;
  31.   pfd: IFileDialog;
  32.   hr: HRESULT;
  33.   aShellItem: IShellItem;
  34. begin
  35.   if dwIDCtl = dwVisualGroup8ID then
  36.   begin
  37.     iImageEnIO := TImageEnIO.Create(nil);
  38.     try
  39.       FileDialog.QueryInterface(IFileDialog, pfd);
  40.       pfd.GetFileName(iName);
  41.       // Get the ShellItem
  42.       hr := SHCreateItemFromParsingName(iName, nil,
  43.       StringToGUID(SID_IShellItem), aShellItem);
  44.       // Get the folder
  45.       pfd.GetFolder(aShellItem);
  46.       // Get the folder displayname
  47.       aShellItem.GetDisplayName(SIGDN_FILESYSPATH, pFolder);
  48.       iFolder := string(pFolder);
  49.       if DirectoryExists( iFolder) then
  50.         iFilename := IncludeTrailingPathDelimiter( iFolder) + string(iName);
  51.       if FileExists(iFilename) then
  52.       begin
  53.        
  54. FileDialog.QueryInterface(IFileDialog, pfd);
  55.        
  56. pfd := FileDialog as IFileDialog;
  57.        
  58. if Supports(FileDialog, IFileDialog, pfd) then ...
  59.        
  60. function TFileDialogEvent.OnButtonClicked(const pfdc: IFileDialogCustomize;  dwIDCtl: DWORD): HResult; stdcall;
  61. var
  62.   iImageEnIO: TImageEnIO;
  63.   iFilename: string;
  64.   iName: PWideChar;
  65. begin
  66.   if dwIDCtl <> dwVisualGroup8ID then
  67.     Result := E_NOTIMPL
  68.   else
  69.   begin
  70.     Result := S_OK;
  71.     if FAILED(Self.Dialog.GetFileName(iName)) then Exit;
  72.     try
  73.       iFilename := string(iName);
  74.     finally
  75.       CoTaskMemFree(iName);
  76.     end;
  77.     iImageEnIO := TImageEnIO.Create(nil);
  78.     try
  79.       if FileExists(iFilename) then
  80.       begin
  81.         ...
  82.       end;
  83.     finally
  84.       iImageEnIO.Free;
  85.     end;
  86.   end;
  87. end;