Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 805
  • Last Modified:

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

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
petervn
Asked:
petervn
  • 3
  • 2
  • 2
  • +2
1 Solution
 
fanarCommented:
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
 
fanarCommented:
You can also use DestroyWindow(HWND) i thnk
0
 
delphizedCommented:
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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
petervnAuthor Commented:
delphized
 can you tell me more details,
how to close the current window of internet explorer and explorer and other application)?
0
 
delphizedCommented:
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
 
petervnAuthor Commented:
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
 
delphizedCommented:
yes, follow your method (wm_close) for normal windows and my method for iexplorer
0
 
fidel83Commented:

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
 
mgazzaCommented:
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

  • 3
  • 2
  • 2
  • +2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now