Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how to close the search results window+delphi

Posted on 2006-07-07
5
Medium Priority
?
214 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
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…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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