Windows with Delphi Windows API (94) Windows Filesystem (41) Windows Forms (69) Windows Graphics (38)
Exchange Links About this site Links to us 
|
Force the TOpenDialog to open in icon view
1 comments. Current rating: (1 votes). Leave comments and/ or rate it.
Question:
My application uses a TOpenDialog and I need it to open in 'icon' view (as opposed to in 'list' view, as it seems to start on my machine). I see no such property in the TOpenDialog class - how can I set the startup view?
Answer:
The Windows API does not provide a direct way to achieve this. The unit below hooks in the OpenDialog's OnShow event and retrieves there the window handle of the open dialog. Unfortunately, at this point, the dialog's controls (e.g. the listview control) are not ready to receive messages. So instead it posts a user message WM_USER+1 to the owning form (Form1) with the handle as the wParam.
It's important that this happens asynchronously (PostMessage() instead of SendMessage()).
By the time this message gets processed, the listview control in the file open dialog can be found with a call to FindWindowEx and the message to change the view can be sent synchronously. The wParam takes the desired display e.g. FCIDM_SHVIEW_LARGEICON.
 | |  | | unit Unit1;
interface
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
StdCtrls;
type
TForm1 = class(TForm)
OpenDialog1: TOpenDialog;
Button1 : TButton;
procedure Button1Click(Sender: TObject);
procedure OpenDialog1Show(Sender: TObject);
private
procedure WMUser(var Msg: TMessage);
message WM_USER + 1;
public
end;
var
Form1: TForm1;
implementation
const
FCIDM_SHVIEW_LARGEICON = 28713;
FCIDM_SHVIEW_SMALLICON = 28714;
FCIDM_SHVIEW_LIST = 28715;
FCIDM_SHVIEW_REPORT = 28716;
FCIDM_SHVIEW_THUMBNAIL = 28717; FCIDM_SHVIEW_TILE = 28718;
procedure TForm1.WMUser(var Msg: TMessage);
var
DlgWnd : HWND;
CtrlWnd: HWND;
begin
DlgWnd := Msg.WParam;
CtrlWnd := FindWindowEx(DlgWnd, 0, PChar('SHELLDLL_DefView'), nil);
if CtrlWnd<>0 then
begin
SendMessage(CtrlWnd, WM_COMMAND, FCIDM_SHVIEW_LARGEICON, 0)
end;
end;
procedure TForm1.OpenDialog1Show(Sender: TObject);
var
Dlg: HWND;
begin
Dlg := GetParent((Sender as TOpenDialog).Handle);
PostMessage(Handle, WM_USER + 1, Dlg, 0)
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
OpenDialog1.Execute;
end;
end.
| |  | |  |
Comments:
|
anonymous from Austria
|
 |
|
|
|
|