Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Why do i can't close IE WINDOW and explorer window

Posted on 2003-11-30
9
Medium Priority
?
802 Views
Last Modified: 2010-04-05
i use this function to close:
SendMessage(GetForegroundWindow, WM_CLOSE, 0, 0);
i can close any window of any program but i can't close INTERNET EXPLORER WINDOW and EXPLORER WINDOW
 when i use
SendMessage(GetForegroundWindow, WM_SYSCOMMAND, SC_MINIMIZE, 0);
i can minimize   INTERNET EXPLORER WINDOW and EXPLORER WINDOW
but i can't close them when use SendMessage(GetForegroundWindow, WM_CLOSE, 0, 0);
please help me
0
Comment
Question by:petervn
[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
  • 3
  • 2
  • 2
  • +2
9 Comments
 
LVL 1

Expert Comment

by:fanar
ID: 9845381
Try this
procedure TForm1.Button1Click(Sender: TObject);
var
ProID: Dword;
hprocess: Dword;
begin

GetWindowThreadProcessId(GetForegroundWindow(),@ProID);
hprocess:=OpenProcess(PROCESS_TERMINATE,TRUE,ProID);
TerminateProcess(hprocess,1);
end;

REgards, Anar
0
 
LVL 1

Expert Comment

by:fanar
ID: 9845382
You can also use DestroyWindow(HWND) i thnk
0
 
LVL 5

Expert Comment

by:delphized
ID: 9848528
with terminateprocess you loose a lot of resource and memory and all the dependant modules.
If you look with winsight you can view that the windows you're closing isn't the iexplorer itself. You could try with a findwindow and then again with the close.
0
Independent Software Vendors: 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!

 

Author Comment

by:petervn
ID: 9849733
delphized
 can you tell me more details,
how to close the current window of internet explorer and explorer and other application)?
0
 
LVL 5

Accepted Solution

by:
delphized earned 375 total points
ID: 9853817
well, I tried for you.
the first part were not difficult, I spyed with winsight and thi works well:

var
  HWND:THandle;
begin
  //close internet explorer
  HWND:=FindWindow('IEFrame',nil);
  if HWND>0 then
  begin
    //this calls wm_destroy and wm_ncdestroy
    SendMessage(HWND,WM_DESTROY,0,0);
    SendMessage(HWND,WM_NCDESTROY,0,0);
  end
  else
  begin
    showmessage('no internet explorer to close');
  end;

for the second it is a bit frustrating, but I'll arrive to it in a day or two (I haven't so much time). I hope you can wait...
bye
0
 

Author Comment

by:petervn
ID: 9858568
hey man
but i need to close the window of any current application.
it's mean that,if it is the window of Internet explorer or explorer window or any current  application,i can close it
0
 
LVL 5

Expert Comment

by:delphized
ID: 9862847
yes, follow your method (wm_close) for normal windows and my method for iexplorer
0
 
LVL 1

Expert Comment

by:fidel83
ID: 9880441

procedure killGoogle;
var ie: thandle;
PID : Cardinal;
PH  : Cardinal;
begin
      ie:=findWindow('IEFrame', 'Google - Microsoft Internet Explorer');
      if ie=0 then exit;

      GetWindowThreadProcessId(ie, @PID);
      PH := OpenProcess(PROCESS_TERMINATE, False, PID);
      TerminateProcess(PH, 0);
      closeHandle(PH);
end;
0
 
LVL 1

Expert Comment

by:mgazza
ID: 9913273
why cant you just send a mesage to the system menu Wm_sysclose i think i havnt got my compiler right now :P
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

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
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…
Suggested Courses

715 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