?
Solved

Change another Applications' Listview ViewStyle

Posted on 2006-11-13
11
Medium Priority
?
295 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
  • 2
11 Comments
 
LVL 26

Accepted Solution

by:
Russell Libby earned 1000 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 1000 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
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!

 
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
 
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month7 days, 23 hours left to enroll

765 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