Solved

Terminate Foreign Windows / Applications

Posted on 2000-04-04
9
165 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
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…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

776 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