DELPHI AREA
MESSAGE BOARD
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Custom File List View in File Dialogs

 
   Reply to topic    DELPHI AREA Forum Index -> Delphi Programming
View previous topic :: View next topic  
Author Message
Kambiz
Administrator


Joined: 07 Mar 2003
Posts: 420
Location: Tehran, Iran

PostPosted: 04/10/03 15:40    Post subject: Custom File List View in File Dialogs Reply with quote

If an application asks user to select an icon, it's more convenient for the user to see list of files as large icons instead of small icons. Also, for selecting an image file, user will be happier to choose an image by seeing the thumbnails.

The standard file dialog initialy shows the files in the LIST (small icon) style, and there is no documented way to change this behavior. So, if user wants to see the file list in another style, she/he should change it manually by selecting the desired view style form the provided popup menu.

Here is a workaround for this limitation to select the reasonable view style for a file dialog.

Code:
type
  TFileViewStyle = (fvsIcons, fvsList, fvsDetails, fvsThumbnails, fvsTiles);

function SetFileDialogViewStyle(Handle: THandle; ViewStyle: TFileViewStyle): Boolean;
const
  CommandIDs: array[TFileViewStyle] of WORD = ($7029, $702B, $702C, $702D, $702E);
var
  NotifyWnd: THandle;
begin
  Result := False;
  NotifyWnd := FindWindowEx(GetParent(Handle), 0, 'SHELLDLL_DefView', nil);
  if NotifyWnd <> 0 then
  begin
    SendMessage(NotifyWnd, WM_COMMAND, CommandIDs[ViewStyle], 0);
    Result := True;
  end;
end;

Each time the file dialog opens, the above function should be called to set the desired view style. The OnShow event of the file dialogs seems to be the right place for this purpose, however at that time the list is not created yet and the function fails.

When the file list is created, the dialog raises two events: OnFolderChange and OnSelectionChange events. We can use one of these events for our purpose. However, we have to consider that the function should be called just once for each show.

Here is a sample usage of the introduced function:

Code:
procedure TForm1.Button1Click(Sender: TObject);
begin
  OpenDialog1.Tag := 0;
  OpenDialog1.Execute;
end;

procedure TForm1.OpenDialog1FolderChange(Sender: TObject);
begin
  if OpenDialog1.Tag = 0 then
  begin
    SetFileDialogViewStyle(OpenDialog1.Handle, fvsIcons)
    OpenDialog1.Tag := 1;
  end;
end;


Cheers,
Kambiz
Back to top
View user's profile Send e-mail Visit poster's website
Display posts from previous:   
   Reply to topic    DELPHI AREA Forum Index -> Delphi Programming All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB 2.0.6 © 2001, 2002 phpBB Group