Link to home
Start Free TrialLog in
Avatar of nikolaosk
nikolaoskFlag for Greece

asked on

how to read the current view of a folder window



hi there experts!!!


i want to do this

1) please fire up Internet explorer
2) in the address bar write c:\

3)then c drive opens up. please change the view to thumbnails.


i know how to do(the above) this programmatically.


 i have to get the view when someone changes that to details view


the code below almost does that. need help with debugging!!


i get an error in this line

wndStyle := SendMessage(myFolderView, LVM_GETVIEW, 0, 0);


please help



*************
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs,shellapi,shlobj, StdCtrls,comctrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  Function GetCurrentView():integer ;

implementation

{$R *.dfm}


Function GetCurrentView():integer ;

var
 myExplorer_hWnd,shellDll,DUIwnd, directUI,sink,myFolderView:cardinal;
  wndstyle:integer;
 begin

myExplorer_hWnd := FindWindow('ieframe', nil) ;



If myExplorer_hWnd <> 0 Then

    shellDll := FindWindowEx(myExplorer_hWnd, 0, 'SHELLDLL_DefView', nil);
    DUIwnd := FindWindowEx(shellDll, 0, 'DUIViewWndClassName', nil);
    directUI := FindWindowEx(DUIwnd, 0, 'DirectUIHWND', nil);
    sink := FindWindowEx(directUI, 0, 'CtrlNotifySink', nil);
    myFolderView := FindWindowEx(sink, 0, 'SysListView32', 'FolderView');


    wndStyle := SendMessage(myFolderView, LVM_GETVIEW, 0, 0);


GetCurrentView := wndStyle;


End;

procedure TForm1.Button1Click(Sender: TObject);
var
num:integer;

begin
num:=GetCurrentView();

showmessage(inttostr(num));

end;

end.
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

Add CommCtrl to the uses clause and change the line to
wndStyle := SendMessage(myFolderView, LVM_GETVIEWRECT, 0, 0);
Avatar of nikolaosk

ASKER


i do what you said and it works. i mean i get no syntax,compile errors.

the problem is that when i open this window in thumbnails view(fire up ie and type in the address bar c:\) i should get 0 as result. but when i go to details view i should get 1. instead i get 0 for all folder views.

what is wrong?

can you run the the program and see what i mean. i increased the score to 250
for LVM_GETVIEW Message - Minimum operating systems Windows XP

my system is xp.
ASKER CERTIFIED SOLUTION
Avatar of Ferruccio Accalai
Ferruccio Accalai
Flag of Italy image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
hi there ferrucio,
thanks for your answer. it works like charm in win xp

LVM_GETVIEW  exists only in comctrls32.dll version distributed with windows xp. so your solution works only for xp.

how can i make it work in  win 2000? what if i ship the comctrls32.dll in a win 2000 machine?

where is the comctrls32.dll located in the xp system?

thanks again

Well, first of all from Microsoft MSDN:

@ Note  To use this API, you must provide a manifest specifying Comclt32.dll version 6.0

This means that even if you ship the Comctl32.dll from XP on a W2K it will never work the same as the W2K ListView Controls are compiled with an older dll version so it will never process the message.
BTW there's another way to see if a W2K ListView is in thumbnail view style.
When it's in this view style a handle for a class "ThumbnailVwExtWnd32" is available, so as we have done for the XP function we can search for this child class starting from the knowed window handle...
Let's see the function.
Function ThumbnailViewStyle: boolean;
var
wnd,shelldll,Ie_Server,ATL_Shell,Tmb_wnd:hwnd;
begin
   //let's get the handle for the class under W2K and its children
   wnd := FindWindow('CabinetWClass',nil);
   //the shelldll_defview child handle
   shellDll := FindWindowEx(Wnd, 0, 'SHELLDLL_DefView', nil);
  // the IE Server child handle
   IE_Server := FindWindowEx(Shelldll,0,'Internet Explorer_Server',nil);
  //and the embedding child handle
   ATL_Shell := FindWindowEx(IE_Server,0,'ATL Shell Embedding',nil);
   //well, now if we are in thumbnail view style a class for this view style exists
   Tmb_wnd := FindwindowEx(ATL_Shell,0,'ThumbnailVwExtWnd32',nil);
  //finally our function result
  result := Tmb_wnd <> 0;
end;

For example you can use is in this way:

procedure TForm1.Button1Click(Sender: TObject);
begin
if ThumbnailViewStyle then
   MessageBox(0,'OK, Thumbnail View Style selected!','Thumbnail View Style',0)
else
   MessageBox(0,'Error, Thumbnail View Style NOT selected!','Thumbnail View Style',0);
end;

F68 ;-)


i understand now that even if i ship the the Comctl32.dll from XP on a W2K.

i send you again the .vbs that i open an explorer(actually an internet explorer window that resembles a windows explorer window)

***************
function nik(efiu)

Set OBJshell = CreateObject("wscript.shell")

DESKTOP = OBJshell.specialFolders("DESKTOP")


FILEPATH = DESKTOP & "\fold1"

ShowExplorer(filepath)

end function

wscript.echo nik(34)


sub ShowExplorer(filepath)


FVM_DETAILS = 4

Set ieExplorer = createobject("InternetExplorer.application")
 
' Navigate to the folder
 
ieExplorer.Navigate2 filepath

ieExplorer.Document.CurrentViewMode = FVM_DETAILS


 
ieExplorer.Visible = True


End Sub


*********

1) if you copy that .vbs above and save it on your desktop as nik.vbs
2) then  create a fold1 folder on your desktop and run the .vbs(dbl click) you will see it opening.


you might wonder why i am opening a windows explorer window as an internet explorer window. because i do not know how to open a normal windows explorer window in thumbnails view. do you know of any way? apis or wshell?


the code you posted above does not work.

i changed the line

wnd := FindWindow('CabinetWClass',nil);
with
 wnd := FindWindow('IEFrame',nil); because it is IE window

but still not working.

please help as i think we are close.

the code above will work only in windows 2000 or it will work in win xp? i ask that because i have xp and if it works only on

2000 i have to install delphi on win 2000 and test it.

thanks




Well, you must definitively know that W2K and WXP ListView controls are different, as since XP the manifest was introduced.
So the first XP function (LVM_GETVIEW) works only on a WXP Os and the second for W2K DOES NOT WORK on XP!
By the way to test the second code on a W2k OS just download this compiled example. http://www.afsoftware.it/Downloads/Project2.zip


hi again,


okey what i did was that.

1)i downloaded your project2.zip
2) i went to a win 2000 machine and i opened a windows explorer window in thumbnails view.it worked.
then i changed the view to details. it worked(gave me a wrong answer) as well. so i need the source code of the project2.exe.

so in win xp.

1) i know how to open a window(Ineternet explorer window) in thumbnails view
2) i know how to get that view


in win 2000

1) i know how to get the view of a normal windows explorer window with the code you are going to send me of project2.exe
2) the problem is opening that standard windows explorer window in details  view, so i can ask someone to change it to thumbnails and test it.



see the script below
*****************
function nik()

Set OBJshell = CreateObject("wscript.shell")
set myshell=createobject("shell.application")

DESKTOP = OBJshell.specialFolders("DESKTOP")


FILEPATH = DESKTOP & "\fold1"

myshell.open filepath

end function

wscript.echo nik()


*******************

how can i open it in details view always the above window?

thanks

okey i just saw that the code you originally posted was  the source code for project2.exe.

the problem is i do not know how to open a windows explorer window in details view.


so what i did was that.


i changed the line

wnd := FindWindow('CabinetWClass',nil);
with
 wnd := FindWindow('IEFrame',nil); because it is IE window


and when i open a IE window(c:\mytest\test.txt) i can see if it is in thumbnails view or not.

probably you think that everything works fine now in windows 2000. actually there is a problem.

as i said above i open the IE window in details(opr whatever view) with a .vbs script(see above)



when i try to run the line below


ieExplorer.Document.CurrentViewMode = FVM_DETAILS

it says currentview mode does not exist.


so now i have to solve my problem with 2 ways

either
1) i have to find a way to open a IE window in a view - then i know how to retrieve the view that i ask someone else to change

or
2) i have to find a way to open a standard explorer window in a view(details,thumbnails)-then i know how to read the view.


that is only for win 2000. for xp it is fine. so i think i am really close just need to open a standard or IE window in a certain view in win 2000 and i am done.

the code for that little W2K project is this

procedure TForm1.Button1Click(Sender: TObject);
Function ThumbnailViewStyle: boolean;
var
wnd,shelldll,Ie_Server,ATL_Shell,Tmb_wnd:hwnd;
begin
   //let's get the handle for the class under W2K and its children
   wnd := FindWindow('CabinetWClass',nil);
   //the shelldll_defview child handle
   shellDll := FindWindowEx(Wnd, 0, 'SHELLDLL_DefView', nil);
  // the IE Server child handle
   IE_Server := FindWindowEx(Shelldll,0,'Internet Explorer_Server',nil);
  //and the embedding child handle
   ATL_Shell := FindWindowEx(IE_Server,0,'ATL Shell Embedding',nil);
   //well, now if we are in thumbnail view style a class for this view style exists
   Tmb_wnd := FindwindowEx(ATL_Shell,0,'ThumbnailVwExtWnd32',nil);
  //finally our function result
  result := Tmb_wnd <> 0;
end;
begin
if ThumbnailViewStyle then
   MessageBox(0,'OK, Thumbnail View Style selected!','Thumbnail View Style',0)
else
   MessageBox(0,'Error, Thumbnail View Style NOT selected!','Thumbnail View Style',0);
end;

As you already have your vbs script just run it from delphi

add shellapi to uses clause and then

shellexecute(0,'','thumbnail.vbs','','',0);
where
'thumbnail.vbs' must contain the complete path
okey i got that. the code above works fine when i open a folder window and see its view.

the thing is i do not know how to open the standard explorer window or  a IE window that looks like a explorer window

in win 2000.


you wrote

As you already have your vbs script just run it from delphi

add shellapi to uses clause and then

shellexecute(0,'','thumbnail.vbs','','',0);
where
'thumbnail.vbs' must contain the complete path



i do not get that. my delphi app calls the script. i have no problem with that. i know how to call the script through delphi.


the script that is called is this


******************
function nik(efiu)

Set OBJshell = CreateObject("wscript.shell")

DESKTOP = OBJshell.specialFolders("DESKTOP")


FILEPATH = DESKTOP & "\fold1"

ShowExplorer(filepath)

end function

wscript.echo nik(34)


sub ShowExplorer(filepath)


FVM_DETAILS = 4

Set ieExplorer = createobject("InternetExplorer.application")
 
' Navigate to the folder
 
ieExplorer.Navigate2 filepath

ieExplorer.Document.CurrentViewMode = FVM_DETAILS


 
ieExplorer.Visible = True


End Sub



*************************

i know how to call the above script from my delphi application. the thing is that in win 2000 the line

ieExplorer.Document.CurrentViewMode = FVM_DETAILS  


fails so no IE window opens in any view so i cannot use your code for win 2000 that you posted.

mi problem is one step back. i need to open in win 2000 either using (delphi and apis or shell 32) a standard explorer window in details view or as the script i posted above i need to open in win 2000 an IE window(that looks like teh standard explorer window) but somehow the CurrentViewMode is not supported in win 2000.

that is the problem.

thanks again



hi again ferruccio,


i managed to solve the problem of opening a standard windows explorer window.here is the script


*************************
function nik()

Set OBJshell = CreateObject("wscript.shell")

set myshell=createobject("shell.application")


DESKTOP = OBJshell.specialFolders("DESKTOP")

FILEPATH = DESKTOP & "\fold1"


myshell.open filepath

wscript.sleep 200

objshell.SendKeys "+{F10}VD"

  'SendKeys "+{F10}VG"        'larGe icons
   'SendKeys "+{F10}VM"        'sMall icons
   'SendKeys "+{F10}VL"        'List
  ' SendKeys "+{F10}VD"        'Details
   'SendKeys "+{F10}VH"        'tHumbnail

end function

wscript.echo nik()


*********


i use sendkeys but it works so i can use your code you posted before. thanks


now i just have a little request.

with the line below we check for thumbnails

Tmb_wnd := FindwindowEx(ATL_Shell,0,'ThumbnailVwExtWnd32',nil);


what about if i want to check for list or tiles. what are the equivalent for

ThumbnailVwExtWnd32 for list,tiles,details view?

thanks

p.s any luck with my word help question? just need to get what someone writes on a word help window(no need for sniffer app)