Solved

ShellExecute Windows' Find In Files

Posted on 2000-03-14
11
513 Views
Last Modified: 2008-02-20
Howdy

I want to know how to ShellExecute a Windows "Find In Files" dialog, optionally loading it with all it's constituent goodies along the way (i.e. 'file types', 'date created', 'containing keywords' from the advanced tab, etc.).

Lucky for you, I don't need to access the results! I just need to set it up for my users.

Fond Regards,
Edo
0
Comment
Question by:Edo082297
[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
11 Comments
 
LVL 17

Accepted Solution

by:
inthe earned 100 total points
ID: 2616910
hi,
i did this once for another question.its a bit rusty but gives you the idea:

Procedure DoFind(FName,FText,FDir:String; FCheck:boolean);
var
h,cbh,wh,wh1,wh2,wh3,wh4:hwnd;
begin   {get a instance of find or start one}
wh := 0;
wh:= FindWindow('#32770','Find: All Files');
if wh = 0 then shellexecute(application.handle,'find','','','',sw_normal);
repeat
 wh:= FindWindow('#32770',nil);
 wh1:=getwindow(wh,GW_CHILD);
 cbh:=FindWindowex(h,0,nil,'Include &subfolders');{checkbox}
 wh2:=FindWindowex(wh1,0,'ComboboxEx32',nil);
 wh3:=FindWindowex(wh2,0,'Combobox',nil);
 wh4:=FindWindowex(wh3,0,'Edit',nil);
 Application.ProcessMessages;
 until wh4 <> 0;
{start fname}
h:= FindWindow('#32770',nil);
h:=getwindow(h,GW_CHILD);
h:=FindWindowex(h,0,'Combobox',nil);
h:=FindWindowex(h,0,'Edit',nil);
if h<>0 then SendMessage(h,WM_SETTEXT,0,Integer(FName))
        else showmessage('Error writing File name!');
       { end fname} {start FText}
h:= FindWindow('#32770',nil);
h:=getwindow(h,GW_CHILD);
h:=FindWindowex(h,0,'Edit',nil);
if h<>0 then SendMessage(h,WM_SETTEXT,0,Integer(FText))
        else showmessage('Error writing Containing Text!');
        {end ftext} {start FDir}
h:= FindWindow('#32770',nil);
h:=getwindow(h,GW_CHILD);
h:=FindWindowex(h,0,'ComboboxEx32',nil);
h:=FindWindowex(h,0,'Combobox',nil);
SendMessage(h,WM_COMMAND,CBN_SELCHANGE,0);
h:=FindWindowex(h,0,'Edit',nil);
if h<>0 then begin
SendMessage(h,WM_RBUTTONDOWN,0,0);
 SendMessage(h,WM_KEYDOWN,0,0);
 SendMessage(h,WM_SETTEXT,0,Integer(FDir));
SendMessage(h,WM_KEYUP,0,0);
SendMessage(h,WM_RBUTTONUP,0,0);
end
  else showmessage('Error writing File name!');
  {end fdir}  {start FCheck}
  h:= FindWindow('#32770',nil);
h:=getwindow(h,GW_CHILD);
h:=FindWindowex(h,0,nil,'Include &subfolders');
if FCheck = TRUE  then
 SendMessage(h,BM_SETCHECK,BST_CHECKED,0)
else
 SendMessage(h,BM_SETCHECK,BST_UNCHECKED,0);
 {end fcheck} {start click find}
 h:= FindWindow('#32770',nil);
h:=FindWindowex(h,0,nil,'F&ind Now');
if h<>0 then begin
SendMessage(h,WM_LBUTTONDOWN,0,0);
SendMessage(h,WM_LBUTTONUP,0,0);
end
 else showmessage('Error Doing Find!');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
DoFind('*.pas','Procedure','E',True);
end;

ps
not sure how well that work on different language than english pc's.
0
 
LVL 17

Expert Comment

by:inthe
ID: 2616926
this one is a bit better:
(fdir dont work though i spent ages on this before with no success so hope someone else has an idea.

Procedure DoFind(FName,FText,FDir:String; FCheck:boolean);
var
h,Eh,Eh2,cbh,Ih,Bh,wh,wh1,wh2,wh3,wh4:hwnd;
begin   {get a instance of find or start one}
wh:= FindWindow('#32770','Find: All Files');
if wh = 0 then shellexecute(application.handle,'find','','','',sw_normal);
repeat   {tests to get some time mainly and check if window exists}
 wh:= FindWindow('#32770',nil);
 wh1:=getwindow(wh,GW_CHILD);
 cbh:=FindWindowex(h,0,'Button',nil);{checkbox Include &subfolders}
 wh2:=FindWindowex(wh1,0,'ComboboxEx32',nil);
 wh3:=FindWindowex(wh2,0,'Combobox',nil);
 wh4:=FindWindowex(wh3,0,'Edit',nil);
 Application.ProcessMessages;
 until wh4 <> 0;
h:= FindWindow('#32770',nil);
Wh1:=getwindow(h,GW_CHILD);
CBh:=FindWindowex(Wh1,0,'Combobox',nil);
Eh:=FindWindowex(CBh,0,'Edit',nil);
if Eh<>0 then SendMessage(Eh,WM_SETTEXT,0,Integer(FName))
        else showmessage('Error writing File name!');
Eh2:=FindWindowex(Wh1,0,'Edit',nil);
if Eh2<>0 then SendMessage(Eh2,WM_SETTEXT,0,Integer(FText))
        else showmessage('Error writing Containing Text!');
Wh2:=FindWindowex(Wh1,0,'ComboboxEx32',nil);
Wh3:=FindWindowex(Wh2,0,'Combobox',nil);

      SendMessage(Wh3,WM_RBUTTONDOWN,0,0);
       SendMessage(Wh3,WM_KEYDOWN,0,0);
       SendMessage(Wh3,WM_COMMAND,CBN_SELCHANGE,0);
Wh4:=FindWindowex(Wh3,0,'Edit',nil);
if Wh4<>0 then begin
 SendMessage(Wh4,WM_SETTEXT,0,Integer(FDir));
         SendMessage(Wh4,WM_KEYUP,0,0);
       SendMessage(Wh4,WM_RBUTTONUP,0,0);
        end
  else showmessage('Error writing File name!');
Ih:=FindWindowex(Wh1,0,'Button',nil);  //Include &subfolders
if FCheck = TRUE  then
 SendMessage(Ih,BM_SETCHECK,BST_CHECKED,0)
else
 SendMessage(Ih,BM_SETCHECK,BST_UNCHECKED,0);
Bh:=FindWindowex(Wh,0,'Button',nil);   //F&ind Now
if Bh<>0 then begin
SendMessage(Bh,WM_LBUTTONDOWN,0,0);
SendMessage(Bh,WM_LBUTTONUP,0,0);
end
 else showmessage('Error Doing Find!');
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
DoFind('*.pas','Procedure','E',True);
end;
0
 
LVL 2

Expert Comment

by:hubdog
ID: 2617850
unit FindDialogs;

{**********************************************************}
{                                                          }
{  TFindFilesDialog & TFindComputerDialog Unit             }
{  Copyright ?999 Workshell Software.                     }
{                                             }
{  Version 1.0                                       }
{                                                          }
{                                                          }
{  Web      -> http://www.workshell.uni.cc/                }
{  E - Mail -> finddlgs@kinsella.u-net.com                 }
{                                                          }
{**********************************************************}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ShlObj;

type
  TFindFilesDialog = class(TComponent)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    function Execute: Boolean;
    function ExecuteEx(pidlRoot, pidlSavedSearch: PItemIDList): Boolean;
  published
    { Published declarations }
  end;

type
  TFindComputerDialog = class(TComponent)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    function Execute: Boolean;
    function ExecuteEx(pidlRoot, pidlSavedSearch: PItemIDList): Boolean;
  published
    { Published declarations }
  end;

procedure Register;

implementation

function SHFindFiles(pidlRoot: PItemIDList; pidlSavedSearch: PItemIDList): Boolean;
 stdcall; external 'Shell32.dll' index 90;

function SHFindComputer(pidlRoot: PItemIDList; pidlSavedSearch: PItemIDList): Boolean;
 stdcall; external 'Shell32.dll' index 91;

function TFindFilesDialog.Execute: Boolean;
begin
Result := SHFindFiles(nil,nil);
end;

function TFindFilesDialog.ExecuteEx(pidlRoot, pidlSavedSearch: PItemIDList): Boolean;
begin
Result := SHFindFiles(pidlRoot,pidlSavedSearch);
end;

function TFindComputerDialog.Execute: Boolean;
begin
Result := SHFindComputer(nil,nil);
end;

function TFindComputerDialog.ExecuteEx(pidlRoot, pidlSavedSearch: PItemIDList): Boolean;
begin
Result := SHFindComputer(pidlRoot,pidlSavedSearch);
end;

procedure Register;
begin
  RegisterComponents('Dialogs', [TFindFilesDialog,TFindComputerDialog]);
end;

end.

good luck
hubdog
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 2

Expert Comment

by:hubdog
ID: 2617861
unit FindDialogs;

{**********************************************************}
{                                                          }
{  TFindFilesDialog & TFindComputerDialog Unit             }
{  Copyright ?999 Workshell Software.                     }
{                                             }
{  Version 1.0                                       }
{                                                          }
{                                                          }
{  Web      -> http://www.workshell.uni.cc/                }
{  E - Mail -> finddlgs@kinsella.u-net.com                 }
{                                                          }
{**********************************************************}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  ShlObj;

type
  TFindFilesDialog = class(TComponent)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    function Execute: Boolean;
    function ExecuteEx(pidlRoot, pidlSavedSearch: PItemIDList): Boolean;
  published
    { Published declarations }
  end;

type
  TFindComputerDialog = class(TComponent)
  private
    { Private declarations }
  protected
    { Protected declarations }
  public
    { Public declarations }
    function Execute: Boolean;
    function ExecuteEx(pidlRoot, pidlSavedSearch: PItemIDList): Boolean;
  published
    { Published declarations }
  end;

procedure Register;

implementation

function SHFindFiles(pidlRoot: PItemIDList; pidlSavedSearch: PItemIDList): Boolean;
 stdcall; external 'Shell32.dll' index 90;

function SHFindComputer(pidlRoot: PItemIDList; pidlSavedSearch: PItemIDList): Boolean;
 stdcall; external 'Shell32.dll' index 91;

function TFindFilesDialog.Execute: Boolean;
begin
Result := SHFindFiles(nil,nil);
end;

function TFindFilesDialog.ExecuteEx(pidlRoot, pidlSavedSearch: PItemIDList): Boolean;
begin
Result := SHFindFiles(pidlRoot,pidlSavedSearch);
end;

function TFindComputerDialog.Execute: Boolean;
begin
Result := SHFindComputer(nil,nil);
end;

function TFindComputerDialog.ExecuteEx(pidlRoot, pidlSavedSearch: PItemIDList): Boolean;
begin
Result := SHFindComputer(pidlRoot,pidlSavedSearch);
end;

procedure Register;
begin
  RegisterComponents('Dialogs', [TFindFilesDialog,TFindComputerDialog]);
end;

end.

good luck
hubdog
0
 
LVL 2

Expert Comment

by:hubdog
ID: 2617862
I think that is what you need .
0
 
LVL 12

Expert Comment

by:rwilson032697
ID: 2617938
Listening
0
 
LVL 17

Expert Comment

by:inthe
ID: 2617939
doesnt that component just do same as this:
shellexecute(handle,'find','','','',sw_normal);

how to load all the "filename", "text to find" etc with this component?
0
 
LVL 2

Expert Comment

by:hubdog
ID: 2618417
sorry,I find I am stupid.
I didn't read the question carefully.

hubdog
0
 
LVL 1

Author Comment

by:Edo082297
ID: 2644126
Hey Inthe

The code doesn't really work -- it gets stuck ad infinitum in the repeat...until loop. It also doesn't write to the windows. I will play around with it and see if I can get it to work. There were also compilation hints (unnecessary variables declared).

I'm afraid I have to score this as average; it's not up to your usually very high standards (we worked on the math parser a couple of years ago, remember?).

Fond Regards, buddy.

Edo

PS I would have rejected this answer and posted this as a comment but EE seems to have changed their policy in this regard...
0
 
LVL 17

Expert Comment

by:inthe
ID: 2645542
i know im sorry its pretty buggy ;~(

you should have been able to just reject it ..

maybe it is possible to execute a saved find ..
(do a find then do "file" - "save search" on the menu..
0
 
LVL 2

Expert Comment

by:hubdog
ID: 2646906
hi,friends
  I guess the better method of setuping the options of search file dialog maybe uses interface ISearchCommandExt imported from microsoft shell controls and automation type library.But when I use cosearchcommand.create to get the interface,there is a error message "class not registered".:(
  I don't know how to make it work.But maybe someone can do it .

good luck
hubdog
0

Featured Post

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month3 days, 11 hours left to enroll

630 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