Solved

Change another Applications' Listview ViewStyle

Posted on 2006-11-13
11
285 Views
Last Modified: 2010-04-04
When you go "File-Open" from within MS-Word, it shows the documents in a listview with vsList set as the default.
But i want it to always show as vsReport, so I can see the date modified column

I've tried googling, and have not found a workable solution, so I wish to make a small app that will watch for the dialog appearing, and will set it's viewstyle.

something like:-
FindWindow (ms-word's open file dialog box)
find listview control on the dialog
set the listview's viewstyle to vsReport

Can anyone think of a way to programattically set another application's ListView ViewStyle?
Thanks in advance
0
Comment
Question by:TheRealLoki
  • 5
  • 3
  • 2
11 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 250 total points
ID: 17935370
Providing you can get the listview handle, you should be able to change the window style for the listview control.

Russell

----

eg:

// Requires COMMCTRL in the uses clause
procedure SetListViewStyle(Handle: HWND; Style: DWORD);
var  dwStyle:       DWORD;
begin

  // Check window
  if IsWindow(Handle) then
  begin
     // Get window style
     dwStyle:=GetWindowLong(Handle, GWL_STYLE);
     // Remove the type mask from style
     dwStyle:=dwStyle and (not LVS_TYPEMASK);
     // OR in the desired style which should be one of
     // LVS_ICON, LVS_SMALLICON, LVS_LIST, LVS_REPORT
     dwStyle:=dwStyle or Style;
     // Set window long
     SetWindowLong(Handle, GWL_STYLE, dwStyle);
     // Update the list view
     ListView_Arrange(Handle, LVA_SNAPTOGRID);
  end;

end;
0
 
LVL 26

Assisted Solution

by:EddieShipman
EddieShipman earned 250 total points
ID: 17938358
Going Rusell a bit farther, here's code that works on Explorer:

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, ComCtrls, CommCtrl;

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

var
  Form1: TForm1;
  LVHandle: HWND;

implementation

{$R *.dfm}


 
function EnumChildProc(AHandle: hWnd; AnObject: TObject): BOOL; stdcall;
var
  tmpS : string;
  theClassName : string;
  theWinText : 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 + '""';
  if Pos(UpperCase('SysListview32'), UpperCase(tmpS)) > 0 then
  begin
    LVHandle := AHandle;
  end;
end;

function WindowEnumProc(AHandle: hWnd; AnObject: TObject): BOOL; stdcall;
// callback for EnumWindows.
var
  theClassName: string;
  theWinText: string;
  tmpS: 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 + '""';
  if Pos(UpperCase('ExploreWClass'), UpperCase(tmpS)) > 0 then
  begin
    EnumChildWindows(AHandle, @EnumChildProc, longInt(0));
  end;
end;

procedure SetListViewStyle(Handle: HWND; Style: DWORD);
var
  dwStyle:       DWORD;
begin
  // Check window
  if IsWindow(Handle) then
  begin
     // Get window style
     dwStyle:=GetWindowLong(Handle, GWL_STYLE);
     // Remove the type mask from style
     dwStyle:=dwStyle and (not LVS_TYPEMASK);
     // OR in the desired style which should be one of
     // LVS_ICON, LVS_SMALLICON, LVS_LIST, LVS_REPORT
     dwStyle:=dwStyle or Style;
     // Set window long
     SetWindowLong(Handle, GWL_STYLE, dwStyle);
     // Update the list view
     ListView_Arrange(Handle, LVA_SNAPTOGRID);
  end;
end;

procedure TForm1.FindLVHandle;
begin
  Screen.Cursor := crHourGlass;
  LVHandle := 0;
  try
    EnumWindows(@WindowEnumProc, LongInt(0));
  finally
    Screen.Cursor := crDefault;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  FindLVHandle;
  if LVHandle <> 0 then
  begin
    SetListViewStyle(LVHandle, LVS_SMALLICON);
  end;
end;

end.
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 17938384
I think the EnumProcs code is from Ralph Friedman on the Borland NG's.
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17952937
>> Can anyone think of a way to programattically set another application's ListView ViewStyle?

The crux of the code (listview modification, which was what the question was about) was mine, yet a point split wasn't seen as an option? I will keep this in mind for future reference...

Russell
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 17955953
I agree, RealLoki, go to Community Support and ask for a re-open and split.
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 17

Author Comment

by:TheRealLoki
ID: 17958946
sorry Russel, honestly didn't notice it was the same code...
Don't be offended, just an oversight. have asked for a re-open/split

0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 17960250
You mean you didn't see my comment?

[quote]Going Rusell a bit farther, here's code that works on Explorer:[/quote]
0
 
LVL 26

Expert Comment

by:Russell Libby
ID: 17960438

NP, I just wanted to ensure that this was not an intentional slight.

Russell

0
 
LVL 17

Author Comment

by:TheRealLoki
ID: 17960853
EddieShipman, maybe it's a regional thing, but I took that statement to mean, "my way is better" so I didn't think twice about it :-)
I really appreciate the skills of both of you btw
0
 
LVL 26

Expert Comment

by:EddieShipman
ID: 17961262
I suppose, what I really meant to say was "taking Russell's example a bit farther..."
which would have essentially meant, his example works, I just "enhanced" it.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Using idhttp to login to instagram 2 76
oracle global variables 4 63
Controlled Assessment GCSE - desperate help needed 4 75
how can i search if string exist in array ? 3 49
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now