?
Solved

how to close the search results window+delphi

Posted on 2006-07-07
5
Medium Priority
?
209 Views
Last Modified: 2010-04-05
hi there experts,

i have the following problem

i need to close all the folder windows that are open.all these windows belong to the class

"CabinetWClass".

i have the code below and all works perfectly well.
but i have this problem. i have on my desktop a folder called "mydocs" inside there there are many .xls and many .doc files.

when i do the following:

1)right click on the "mydocs" folder -i choose the Search option from the menu.the search results window opens

2)  then i write *.doc on the search box and i hit the search button.i get in the window all the .doc windows

so far so good. now i need to close that search results window.

i tried the code below where all the windows that belong to the cabinetwclass close.but in this case i could not close it.

please help asap

urgent help needed

thanks a lot in advance


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

interface

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

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

var
  Form1: TForm1;

implementation

{$R *.dfm}


 Procedure CloseActiveFolders(Const AClassName: PAnsiChar; Const ACloseCommand: Integer);
Var
  H: THandle;
Begin
  H:= FindWindow(AClassName,Nil);
  While H > 0 Do Begin
    PostMessage(H,ACloseCommand,0,0);
    H:= FindWindow(AClassName,Nil);
  End;
End;

procedure TForm1.Button1Click(Sender: TObject);

begin
     CloseActiveFolders('CabinetWClass',wm_close);
end;
end.

***************
0
Comment
Question by:nikolaosk
[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 Comments
 
LVL 28

Expert Comment

by:2266180
ID: 17057329
It worked just fin on my winxp sp2 box.
0
 
LVL 28

Expert Comment

by:2266180
ID: 17057332
of coursem I tested on temp forlder with *.tmp, but that shouldn't matter.

what version of windows are you using?
0
 
LVL 16

Expert Comment

by:CodedK
ID: 17057384
I ve tried it too. Works for me too.
Restart explorer ("Task Manager" ---> Terminate Explorer... "New Task" : explorer.exe)
and try again.
0
 
LVL 10

Accepted Solution

by:
atul_parmar earned 2000 total points
ID: 17057576
I feel that before the window process the message it gets requrest for handle (because of continues looping) what prevents it to close.

Try the following
function EnumWindowsCallback(Handle : THandle; lParam : Integer) : Boolean stdcall;
var
  ClassName : array [0..255] of char;
begin
  GetClassName(Handle, ClassName, 255);
  If ClassName = 'CabinetWClass' then
    PostMessage(Handle, WM_CLOSE, 0, 0);
  Result := True;
end;

then call
  EnumWindows(@EnumWindowsCallback, 0);
0
 

Author Comment

by:nikolaosk
ID: 17058030
hi there guys !!!! only atul_parmar's solution worked.thanks a lot
0

Featured Post

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!

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…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Suggested Courses

800 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