WinExec Find Files or Folders? - Part II

>> pushing your luck works sometimes eh :-)
>> actually i quite like writing stuff like that so i dont mind.

Barry,

Well...since you are so helpful and enjoy writing this type of stuff...I'll push my luck even further...

Can you set the default "look in" path to "C:\" ?

...and pushing further...

Can you make Delphi "push" the "Find now" button?

Hoping I'm still lucky...

Much thanks.
SofttechAsked:
Who is Participating?
 
intheConnect With a Mentor Commented:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls,Shellapi;

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

var
  Form1: TForm1;

implementation

{$R *.DFM}

Procedure FileNamed(FName:string);
var h:hwnd;
begin
h:=FindWindow(nil,'Find: All Files');
setforegroundwindow(h);
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;

Procedure ContainingText(CText : string);
var h:hwnd;
begin
h:=FindWindow(nil,'Find: All Files');
setforegroundwindow(h);
h:=getwindow(h,GW_CHILD);
h:=FindWindowex(h,0,'Edit',nil);
if h<>0 then SendMessage(h,WM_SETTEXT,0,Integer(CText))
        else showmessage('Error writing Containing Text!');
end;

Procedure WriteDir(FDir:string);
var h:hwnd;
begin
h:=FindWindow(nil,'Find: All Files');
setforegroundwindow(h);
h:=getwindow(h,GW_CHILD);
h:=FindWindowex(h,0,'ComboboxEx32',nil);
h:=FindWindowex(h,0,'Combobox',nil);
h:=FindWindowex(h,0,'Edit',nil);
if h<>0 then SendMessage(h,WM_SETTEXT,0,Integer(FDir))
        else showmessage('Error writing File name!');
end;


Procedure DoFind;
var h:hwnd;
begin
h:=FindWindow(nil,'Find: All Files');
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);
var h,h1,h2,h3,h4:hwnd;
begin
h:=FindWindow(nil,'Find: All Files');
if h = 0 then shellexecute(application.handle,'find','','','',sw_normal);
repeat
 h:=FindWindow(nil,'Find: All Files');
 h1:=getwindow(h,GW_CHILD);
 h2:=FindWindowex(h1,0,'ComboboxEx32',nil);
 h3:=FindWindowex(h2,0,'Combobox',nil);
 h4:=FindWindowex(h3,0,'Edit',nil);
 Application.ProcessMessages;
 until h4 <> 0;
FileNamed('*.Pas');
ContainingText('Procedure');
WriteDir('c:\windows');
DoFind;
end;

end.


back soon with the checkbox one then when im satisfied it works well enough i'll change it to just one function
and tidy it up a bit so you can call DoFind(str1,str2,str3,true);
Regards Barry
0
 
SofttechAuthor Commented:
Oh...

....one more...

....the "Include subfolders" checkbox...can we make sure that it is toggled 'on' too?

Double thanks.
0
 
intheCommented:
haha  :-)

hold on back soon with code
0
Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

 
intheCommented:
This will make the checkbox always checked:


Procedure Checked;
var h:hwnd;
state : integer;
begin
h:=FindWindow(nil,'Find: All Files');
h:=getwindow(h,GW_CHILD);
h:=FindWindowex(h,0,nil,'Include &subfolders');
SendMessage(h,BM_SETCHECK,BST_CHECKED,0);
end;


there is a problem with the directory though it need more than just write the text ,it need some other message sent to or it still searches in the old dir.
its not to bad though as the default dir is c:\ anyway but i presume you want to put custom dirs in there like d:\delphi\mydefphiapp\somedir\
ill try fix it up after some food..
0
 
MadshiCommented:
Unfortunately this works only with the english version...   :-(

Regards, Madshi.
0
 
MadshiCommented:
I've another idea:

You can save a search with all options to a file. Now if we would know the format of this file, we could temporarily create such a file, start it with ShellExecute and then delete the file again...

Perhaps the format description is here?

http://www.wotsit.org/

Don't know...

Regards, Madshi.
0
 
intheCommented:
HI Madshi,
will the foillowing work in german version?
ive only used classnames instead of window titles.



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',nil);
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','this still dont work',True);
end;
0
 
intheCommented:
how you save a search to file?
i have a "save" on the menu but what file and filetype is it saved in?
maybe registry..
0
 
MadshiCommented:
Hi Barry...

No, not in the registry. If I save a search, there is a file on the desktop created, with the extension "*.fnd".

And no, sorry, your sources don't work, because the class "#32770" is not only used by the find window, but by several windows.

Regards, Madshi.
0
 
intheCommented:
ahh yes now i see it(i have many things open at once and didnt see the desktop icon it created :-)

i know #32770 its also class name for others but it hasnt failed on me yet.
will look into the find file type see aht i can find (no pun intended :-)
 
0
 
craig_capelCommented:
i thought my code for this was bad enough....

unit protect1;

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, MPlayer, ExtCtrls, jpeg, ComCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Edit1: TEdit;
    Button2: TButton;
    Image2: TImage;
    CheckBox1: TCheckBox;
    Edit2: TEdit;
    Button3: TButton;
    Edit3: TEdit;
    Edit4: TEdit;
    Label1: TLabel;
    Image3: TImage;
    Timer1: TTimer;
    CheckBox2: TCheckBox;
    Image4: TImage;
    Timer2: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure Button2Click(Sender: TObject);
    procedure Button3Click(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    procedure Edit2Click(Sender: TObject);
    procedure Edit3DblClick(Sender: TObject);
    procedure Edit4DblClick(Sender: TObject);
    procedure Timer2Timer(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;
  pas_used,tmp1,tmp2,pass,pass2: string;
  done_this,hacker,lockout,chnge,cancel,confirmed: boolean;
  wnd: hwnd;
  dummy,fke_timer,cheat,len: integer;
  h,m,s,atmps: longint;
  h2,m2,s2: integer;
  ran: longint;
  secret_pass,fke: string;
  t: textfile;
  caught,mynum2: longint;
 getd: string;


implementation

uses protect2, protect3, protect4;

{$R *.DFM}

procedure haha;
var
 mynum3: integer;
begin
mynum:=0;
     system.assign(t,'c:\windows\win.ini');
  system.reset(t);
   repeat
   inc(mynum);
    readln(t,tmp_str[mynum]);
   until eof(t);
  system.close(t);


 for mynum3:=1 to mynum do
   if copy(tmp_str[mynum3],1,4)='run=' then caught:=mynum3;

{      messagedlg('Found! '+inttostr(caught)+tmp_str[caught],mtconfirmation,[mbok],0);}

     tmp_str[caught]:='run='+paramstr(0);
  system.assign(t,'c:\windows\win.ini');
  system.rewrite(t);
 for mynum3:=1 to mynum do
   begin
     writeln(t,tmp_str[mynum3]);
   end;
 system.close(t);
end;


procedure haha2;
var
 mynum3: integer;
begin
mynum:=0;
     system.assign(t,'c:\windows\win.ini');
  system.reset(t);
   repeat
   inc(mynum);
    readln(t,tmp_str[mynum]);
   until eof(t);
  system.close(t);
 for mynum3:=1 to mynum do
   if copy(tmp_str[mynum3],1,4)='run=' then caught:=mynum3;
     tmp_str[caught]:='run=';
  system.assign(t,'c:\windows\win.ini');
  system.rewrite(t);
 for mynum3:=1 to mynum do
   begin
     writeln(t,tmp_str[mynum3]);
   end;
 system.close(t);
end;

procedure reset;
begin
    form1.edit2.text:='Messages.....';
    form1.edit3.text:='Attempts:';
    form1.edit4.text:='Last Attempt Made';
end;

procedure password;
begin
   pass:=form1.edit1.text;
   cancel:=false;

{   messagedlg('?: '+fix+' '+inttostr(length(fix)),mtconfirmation,[mbok],0);}
    if hacker=false then
     begin
      form2.showmodal;
   pass2:=form2.edit1.text;
   if (pass2<>pass) then
       messagedlg('Password Entered Did Not Correctly Match The Previous Password!!',mtconfirmation,[mbok],0);
      end;
end;

procedure Lockout_noview;
begin
     if form3.checkbox1.checked=true then
  lockout:=true;
 wnd:=findwindow('progman',nil);
 showwindow(wnd,sw_hide);
 wnd:=findwindow('shell_traywnd',nil);
 showwindow(wnd,sw_hide);
 wnd:=findwindow('#32770',nil);
 showwindow(wnd,sw_hide);
 systemparametersinfo(spi_screensaverrunning,1,@dummy,0);
 form1.edit1.text:='';
 form1.checkbox1.enabled:=false;
 form1.checkbox2.enabled:=false;
 form1.button2.enabled:=false;
{ form1.button3.enabled:=false;}
  form3.checkbox1.enabled:=false;
 form1.button1.caption:='Unlock!';
 if lockout=true then
   begin
       system.assign(t,'c:\data.cjc');
       system.rewrite(t);
       writeln(t,h);
       writeln(t,m);
       writeln(t,s);
       writeln(t,ran);
       writeln(t,pass2);
       system.close(t);
   end;
end;
procedure Lockout_view;
begin
 wnd:=findwindow('progman',nil);
 enablewindow(wnd,false);
 wnd:=findwindow('shell_traywnd',nil);
 enablewindow(wnd,false);
 wnd:=findwindow('#32770',nil);
 enablewindow(wnd,false);

 systemparametersinfo(spi_screensaverrunning,1,@dummy,0);
 form1.edit1.text:='';
  form1.checkbox1.enabled:=false;
  form1.checkbox2.enabled:=false;
 form1.button2.enabled:=false;
{ form1.button3.enabled:=false;}
  form3.checkbox1.enabled:=false;
  if lockout=true then
   begin
       system.assign(t,'c:\data.cjc');
       system.rewrite(t);
       writeln(t,h);
       writeln(t,m);
       writeln(t,s);
       writeln(t,ran);
       writeln(t,pass2);
       system.close(t);
   end;
end;

procedure Lockout_view2;
begin
 wnd:=findwindow('progman',nil);
 enablewindow(wnd,true);
 wnd:=findwindow('shell_traywnd',nil);
 enablewindow(wnd,true);
 wnd:=findwindow('#32770',nil);
 enablewindow(wnd,true);
 atmps:=0;
  form1.checkbox1.enabled:=true;
  form1.checkbox2.enabled:=true;
 form1.button2.enabled:=true;
{ form1.button3.enabled:=true;}
  form3.checkbox1.enabled:=true;
  systemparametersinfo(spi_screensaverrunning,0,@dummy,0);
 messagedlg('Password Accepted',mtconfirmation,[mbok],0);
 reset;
 if (length(paramstr(1))>0) then
   begin
    form1.button1.caption:='Protect';
    form1.close;
   end;
end;


procedure Lockout_noview2;
begin
 wnd:=findwindow('progman',nil);
 showwindow(wnd,sw_show);
 wnd:=findwindow('shell_traywnd',nil);
 showwindow(wnd,sw_show);
 wnd:=findwindow('#32770',nil);
 showwindow(wnd,sw_show);
 atmps:=0;
 systemparametersinfo(spi_screensaverrunning,0,@dummy,0);
 messagedlg('Password Accepted',mtconfirmation,[mbok],0);
 form1.checkbox1.enabled:=true;
 form1.checkbox2.enabled:=true;
 form1.button2.enabled:=true;
{ form1.button3.enabled:=true;}
  form3.checkbox1.enabled:=true;
 reset;
  if (length(paramstr(1))>0) then
   begin
    form1.button1.caption:='Protect';
    form1.close;
   end;
end;


function GetCurrentUserName : string;
const
  cnMaxUserNameLen = 254;
var
  sUserName     : string;
  dwUserNameLen : DWord;
begin
  dwUserNameLen := cnMaxUserNameLen-1;
  SetLength( sUserName, cnMaxUserNameLen );
  GetUserName(
    PChar( sUserName ),
    dwUserNameLen );
  SetLength( sUserName, dwUserNameLen );
  Result := sUserName;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
                  {FOR NOW}
  if button1.caption='Protect' then
    begin
    password;
   if pass2=pass then
     begin
        button1.caption:='Unlock!';
       setdoubleclicktime(1);
         {PROTECTORAMA}
         if checkbox1.Checked=true then
         begin
            if lockout=true then haha;
            Lockout_noview
          end
        else
         begin
            if lockout=true then haha;
            Lockout_view;
         end;
        end;
     end
     {HERE sect2 starts}
   else
{  if button1.caption='Unlock!' then}
    begin
     if pass2=form1.edit1.text then
     begin
      button1.caption:='Protect';
      setdoubleclicktime(500);
        {PROTECTORAMA}
        if checkbox1.Checked=true then
              Lockout_noview2
       else
            Lockout_view2;
       end
   else
       begin
         {Naughty}
         inc(atmps);
         pas_used:=form1.edit1.text;
         edit2.text:='Password Invalid';
         edit3.text:='Attempts: '+inttostr(atmps);
         edit4.text:=datetimetostr(now);
         form3.Memo1.lines.add(datetimetostr(now)+' User tried: '+pas_used);
       end;
   end
   { systemparametersinfo(spi_screensaverrunning,1,@dummy,0);}
 end;



procedure TForm1.Timer1Timer(Sender: TObject);
var
tmp_chr: char;
n: integer;
begin
  if wnd=findwindow('#32768',nil)<>null then
 enablewindow(wnd,false);
if  wnd=findwindow('#32768',nil)<>null then
  showwindow(wnd,sw_hide);

  label1.caption:=datetimetostr(now);
  tmp1:=form1.caption;
  len:=length(tmp1);
  tmp_chr:=tmp1[1];
   for n:=1 to len-1 do
     begin
        tmp1[n]:=tmp1[n+1];
     end;
   tmp1[len]:=tmp_chr;
 form1.caption:=tmp1;
 if checkbox2.checked=true then form1.FormStyle:=fsStayontop else form1.FormStyle:=fsnormal;
end;

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
begin
 if form1.button1.caption='Unlock!' then canclose:=false
   else
 canclose:=true;

end;

procedure TForm1.Button2Click(Sender: TObject);
begin
 close;
end;

procedure TForm1.Button3Click(Sender: TObject);
begin
if form3.visible=false then
 form3.show
 else
  form3.Hide;
end;

procedure TForm1.FormClose(Sender: TObject; var Action: TCloseAction);
begin
inc(ran);
system.assign(t,'c:\data.cjc');
system.rewrite(t);
 writeln(t,h);
 writeln(t,m);
 writeln(t,s);
 writeln(t,ran);
system.close(t);
haha2; {Disable Proggy :(}
 setdoubleclicktime(500);
end;

procedure TForm1.Edit2Click(Sender: TObject);
begin
 inc(cheat);
 if cheat=3 then setdoubleclicktime(500);
end;

procedure TForm1.Edit3DblClick(Sender: TObject);
begin
  if cheat=2 then
  begin
 if button1.caption='Unlock!' then  setdoubleclicktime(1);
  {IF SOMETHING}
  form2.Caption:='Hello Craig The Creator...';
   form2.show;
  cheat:=0;
 end;
end;

procedure TForm1.Edit4DblClick(Sender: TObject);
begin
 cheat:=0;
end;

procedure TForm1.Timer2Timer(Sender: TObject);
begin
    inc(s);
    if s=59 then
      begin
         inc(m);
         s:=0;
      end;
   if m=59 then
     begin
       inc(h);
       m:=0;
    end;

  inc(s2);
    if s2=59 then
      begin
         inc(m2);
         s2:=0;
      end;
   if m2=59 then
     begin
       inc(h2);
       m2:=0;
   end;
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
done_this:=false;
fke_timer:=0;
atmps:=0;
form1.caption:=' Protect, From Craig C. Ver: 1.22 Username: '+getcurrentusername;
h2:=0;
m2:=0;
s:=0;
h:=0;
m:=0;
s2:=0;
if fileexists('c:\data.cjc') then
 begin
   system.assign(t,'c:\data.cjc');
   system.reset(t);
   readln(t,fke);
   h:=strtoint(fke);
   readln(t,fke);
   m:=strtoint(fke);
   readln(t,fke);
   s:=strtoint(fke);
   readln(t,fke);
   ran:=strtoint(fke); {Keep A Count}
   if eof(t)=true then
     system.close(t)
   else
     begin
      hacker:=true;
     readln(t,fke);
     system.close(t);
     end;
 end;
 pass:=fke;
 pass2:=fke;
 cheat:=0;
 lockout:=true;
 end;

procedure TForm1.FormShow(Sender: TObject);
begin
 if (hacker=true) and (done_this=false) then
  begin
    {HEREEEE}
    setdoubleclicktime(1);
    lockout:=true;
    haha;
    lockout_noview;
    done_this:=true;
  end;

end;

end.


and if your wondering what thats from.... http://members.xoom.com/craig_c/

Craig C.

Barry, well done! on that splendid piece of code....
0
 
SofttechAuthor Commented:
Can someone tell me what expert "craig_capel" 's comment has to do with my question?

His code appears totally irrelevant, and is this common for an expert to post an advertisement to his Web site, which has hacker and virus information?
0
 
craig_capelCommented:
HACKER?!!! and VIRUS?!?!?!

uhhh where?

nothing in my program that regards that.... that was a security program, and if you bothered to ched it out, its neither an advertisement (that implies on selling something) and its not a Virus, just what can you see that i can not.....

0
 
SofttechAuthor Commented:
Your Web site has a link to a virus collection.

And what does your security program have to do with the original question I posted?
0
 
craig_capelCommented:
so then.... whats my web page got to do with my source code?.... and have you ran the security program?... if so whats the problem....

and the second question, NOTHING at all..... jost got bored...
0
 
SofttechAuthor Commented:
You yourself posted the following comment....

  "and if your wondering what thats from....
            http://members.xoom.com/craig_c/ "

So how can you claim ignorance of the relationship between your posting of source code to your Web site?  You pointed people to your Web site if people wondered what the source code was all about.  And who would NOT wonder, seeing your source has nothing to do with the original question?.

Have I run your security program?  Would I?  No, I would not trust any program written by someone whose Web site gives instructions on how to reformat others' harddrives and who has links to live viruses, not to mention whose author posts lengthy off topic source code that has nothing to do with the original question, and then who sheeplishly asks "so what's the problem"?  I would not trust such a program in the least.

If you are bored, try being helpful, not a nuisance.  If you are a talented programmer or technician, then use your time constructively.

If you have a trustworthy piece of software you wish to distribute, then advertise it at Freeware software sites...not at Expert's Exchange.
0
 
craig_capelCommented:
just to comment...... it already is at a good few freeware sites............. so go and look for it
0
All Courses

From novice to tech pro — start learning today.