[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 288
  • Last Modified:

How to open Windows Explorer in Thumbnails view

I need to open Windows Explorer, and have it show the 'Thumbnails' view of files.  I have the following:

ShellExecute(Handle, 'open', 'c:\folder', nil, nil, SW_SHOW)

But how do I do this in Thumbnails view?
0
light_bulb
Asked:
light_bulb
1 Solution
 
spk2000arCommented:
See this
http://www.experts-exchange.com/Programming/Languages/Pascal/Delphi/Q_21566249.html#a14957070
Perhaps you find something there that can help you
0
 
TheRealLokiSenior DeveloperCommented:
when Explorer is created, it uses a new handle, so it is very tricky to determine the handle of the new explorer window.
Here's a method I use to find the new explorer window. Then you can set the viewstyle (as i am doing in this demo for you)

unit MainForm;

interface

uses
  Windows, Messages, SysUtils, Forms, Buttons, ShellAPI, CommCtrl, StdCtrls,
  Classes, Controls;

type
  TfMain = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
  private
    { Private declarations }
    procedure FindTheWindowHandles;
    function DetermineNewExplorerWindow: THandle;
  public
    { Public declarations }
    winlist, lastwinlist: TStrings;
  end;

var
  fMain: TfMain;
  LVHandle: HWND;

implementation

{$R *.DFM}

function TheWindowEnumProc(AHandle: hWnd; AnObject: TObject): BOOL; stdcall;
// callback for EnumWindows.
var
  theClassName: string;
  theWinText: string;
  tmpS: string;
  s: string;
begin
  Result := True;
  SetLength(theClassName, 256);
  GetClassName(AHandle, PChar(theClassName), 255);
  SetLength(theWinText, 256);
  GetWindowText(AHandle, PChar(theWinText), 255);
  tmpS := StrPas(PChar(theClassName));
  if theWinText <> EmptyStr then
    tmpS := tmpS + ' "'
            + StrPas(PChar(theWinText)) + '"'
  else
    tmpS := tmpS + '""';
  s := StrPas(PChar(theClassName));
  if ( (uppercase(s) = 'EXPLOREWCLASS') or (uppercase(s) = 'CABINETWCLASS') ) then
  begin
    if lowercase(StrPas(PChar(theWinText))) <> 'search results' then
      fMain.winlist.AddObject(tmpS, pointer(AHandle));
  end;
end;

{ TfMain }

procedure TfMain.FormCreate(Sender: TObject);
begin
  winlist := TStringList.Create;
  lastwinlist := TStringList.Create;
end;

procedure TfMain.FormDestroy(Sender: TObject);
begin
  winlist.clear;
  winlist.free;
  lastwinlist.clear;
  lastwinlist.free;
end;

procedure TfMain.FindTheWindowHandles;
begin
  winlist.clear;
  Screen.Cursor := crHourGlass;
  LVHandle := 0;
  try
    EnumWindows(@TheWindowEnumProc, LongInt(0));
  finally
    Screen.Cursor := crDefault;
  end;
end;


procedure TfMain.Button1Click(Sender: TObject);
const
  FCIDM_SHVIEW_LARGEICON = $7029;
  FCIDM_SHVIEW_SMALLICON = $702A;
  FCIDM_SHVIEW_LIST = $702B;
  FCIDM_SHVIEW_REPORT = $702C;
  FCIDM_SHVIEW_THUMBNAIL = $702D;
  FCIDM_SHVIEW_TILE = $702E;
var
  iterations: integer;
  _viewstyle: dWord;
  H:THandle;
begin
  lastwinlist.clear;
  FindTheWindowHandles;
  lastwinlist.assign(winlist);
// start the explorer window
  ShellExecute(Handle, 'open', 'c:\temp\', nil, nil, SW_SHOW);
  iterations := 10;
  repeat
    if iterations > 0 then sleep(100);
    FindTheWindowHandles;
    H := DetermineNewExplorerWindow;
  until (H <> 0) or (iterations >10);
  if (H <> 0) then
  begin
    _viewstyle := FCIDM_SHVIEW_THUMBNAIL;

    SendMessage(H, WM_COMMAND, _viewstyle, 0);
  end;
end;

function TfMain.DetermineNewExplorerWindow: THandle;
var
  i: integer;
begin
  result := 0;
  i := 0;
  while (result = 0) and (i < winlist.count) do
  begin
    if lastwinlist.IndexOfObject(winlist.Objects[i]) = -1 then
      result := THandle(winlist.Objects[i]) // not found, so must be our new one :-)
    else
      inc(i);
  end;
end;

end.
0
 
light_bulbAuthor Commented:
Perfect answer!  Thanks so much!
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now