Solved

Terminate Foreign Windows / Applications

Posted on 2000-04-04
9
167 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
[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
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
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: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

Industry Leaders: 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!

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
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…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

730 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