Solved

how to close the search results window+delphi

Posted on 2006-07-07
5
198 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 500 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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Suggested Solutions

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…
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…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

730 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