Tuesday, August 03, 2004

Changing the default view in TAgOpenDialog

I got a mail today asking if AgOpenDialog, a dialog I'd written for D5 a few years ago, would support defining a default view - i.e. when the dialog opens, it should be configurable to display the list view in, for instance, the thumbnails view.

A little bit of help from a Visual Basic site (The "Save and Open File Dialog Demo" link) gave me a clue. Define this first:

const
FCIDM_SHVIEW_LARGEICON = $7029; // 28713
FCIDM_SHVIEW_SMALLICON = $702A; // 28714
FCIDM_SHVIEW_LIST = $702B; // 28715
FCIDM_SHVIEW_REPORT = $702C; // 28716
FCIDM_SHVIEW_THUMBNAIL = $702D; // 28717
FCIDM_SHVIEW_TILE = $702E; // 28718
type
TAgOpenDialogView = (ovLargeIcon, ovSmallIcon,
ovList, ovReport,
ovThumbnails, ovTile);


and a published property:


property DefaultView : TAgOpenDialogView
read FDefaultView
write FDefaultView default ovLargeIcon;


Now, override the WndProc and set it up:


procedure TAgOpenDialog.WndProc(var Message: TMessage);
const
ViewConsts : array[TAgOpenDialogView] of integer =
( FCIDM_SHVIEW_LARGEICON, FCIDM_SHVIEW_SMALLICON,
FCIDM_SHVIEW_LIST, FCIDM_SHVIEW_REPORT,
FCIDM_SHVIEW_THUMBNAIL, FCIDM_SHVIEW_TILE);
var hList : THandle;
begin
inherited;
if (Message.Msg = WM_NOTIFY) then
case (POFNotify(Message.LParam)^.hdr.code) of
CDN_FOLDERCHANGE:
begin
if not FDefaultViewChanged then
begin
hList := FindWindowEx( GetParent(handle), 0,
'SHELLDLL_DefView', '');
if hList <> 0 then
begin
SendMessage(hList, WM_COMMAND,
ViewConsts[FDefaultView], 0);
FDefaultViewChanged := True;
end;
end;
end;
end;
end;


The FDefaultViewChanged is a boolean member initialized to False in the overridden Execute procedure. You can download the component and source code here. (Test project included).

0 Comments:

Post a Comment

<< Home