Solved

how to close the search results window+delphi

Posted on 2006-07-07
5
193 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
5 Comments
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
It worked just fin on my winxp sp2 box.
0
 
LVL 28

Expert Comment

by:ciuly
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
hi there guys !!!! only atul_parmar's solution worked.thanks a lot
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

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…
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…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

728 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now