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?
ASKER
Sorry, but I can't find any relevant information there.
ASKER
Adjusted points from 100 to 150
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.
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.
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;
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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
http://www.jgsoftware.com/nt.htm