Link to home
Start Free TrialLog in
Avatar of skymag
skymag

asked on

Terminate Foreign Windows / Applications

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?
Avatar of jeurk
jeurk

hello, i suggest you take a look here:
http://www.jgsoftware.com/nt.htm
Avatar of skymag

ASKER

Sorry, but I can't find any relevant information there.
Avatar of skymag

ASKER

Adjusted points from 100 to 150
Avatar of skymag

ASKER

I would really appreciate some sample code.
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.
Avatar of skymag

ASKER

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;
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of skymag

ASKER

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.
listenning