Solved

Terminate Foreign Windows / Applications

Posted on 2000-04-04
9
166 Views
Last Modified: 2010-05-19
I have an application that is set to run as the Shell. I want to terminate certain windows that are displayed i.e. system messages or other apps that pop up. Does someone have some Delphi 4 code for Windows NT 4?
0
Comment
Question by:skymag
9 Comments
 
LVL 4

Expert Comment

by:jeurk
ID: 2683070
hello, i suggest you take a look here:
http://www.jgsoftware.com/nt.htm
0
 

Author Comment

by:skymag
ID: 2683107
Sorry, but I can't find any relevant information there.
0
 

Author Comment

by:skymag
ID: 2683159
Adjusted points from 100 to 150
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

Author Comment

by:skymag
ID: 2683160
I would really appreciate some sample code.
0
 
LVL 20

Expert Comment

by:Madshi
ID: 2683278
What do you know about the program you want to stop? Do you know it's process ID or it's main window handle or [...]?

There are several different possibilites to stop a process. It depends on how you want it to be stopped (e.g. may the user save modified files?) and what you know of that process.

TerminateProcess and PostMessage(windowHandle, WM_CLOSE, 0, 0) are two most common solutions.

Regards, Madshi.
0
 

Author Comment

by:skymag
ID: 2683375
Hi Madshi, I'm using the following code but it doesn't want to close the Internet Explorer. It seems to work on most other applications. I am using the EmbeddedWb Component.

procedure TfMain.WMActivate(var Msg: TWMActivate);
var
  S: String;
  wnd: HWND;
  i: Integer;
begin
  if Msg.Active=0 then
     begin
       wnd := Msg.ActiveWindow;
       if wnd = 0 then
          wnd := GetForegroundWindow;
       i := GetWindowTextLength(wnd);
       SetLength(S, i + 1);
       GetWindowText(Wnd, PChar(S), i + 1);

       if Pos('Internet Explorer', S) > 0 then
          Sendmessage(wnd, WM_CLOSE, 0, 0);
     end;
end;
0
 
LVL 20

Accepted Solution

by:
Madshi earned 150 total points
ID: 2683595
Try "PostMessage(wnd, WM_CLOSE, 0, 0);". But I guess that makes no difference. Please tell me what window text do you get when the explorer is activated? Add a line "caption := S;" to your sources to check that.
0
 

Author Comment

by:skymag
ID: 2683687
That actually closed it down. According to the Win32 Programmer's Guide this is the difference:
The SendMessage function sends the specified message to a window or windows. The function calls the window procedure for the specified window and does not return until the window procedure has processed the message. The PostMessage function, in contrast, posts a message to a thread's message queue and returns immediately.
0
 
LVL 3

Expert Comment

by:bryan7
ID: 2683744
listenning
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.

Question has a verified solution.

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

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

856 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