Solved

how to close the search results window+delphi

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

Technology Partners: 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

The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…

688 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