?
Solved

Termination of a program in memory

Posted on 1998-02-15
7
Medium Priority
?
207 Views
Last Modified: 2010-04-04
I need a way to terminate a running application (a different
one from the one I'm running) which will check if a certain
programming is running, and if so will terminate it.

In other words, I need to find a way to send the WM_CLOSE
message to a specified application in memory.
0
Comment
Question by:almiller
7 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1359259
To Close a notepad document:
SendMessage(FindWindow('notepad', nil), wm_Destroy, 0, 0);
0
 
LVL 2

Expert Comment

by:mvz121697
ID: 1359260
You'll first have to know the ClassName of the app you are trying to close. Then use FindWindow to get e handle of the main window. Then you can use SendMessage to send a WM_CLOSE message.

For example with Word 97 (the classname is OpusApp):

var h:Integer;
begin
 h:=FindWindow('OpusApp',nil);
 if h>0 then SendMessage(h,WM_DESTROY,0,0);
end;

Some know class-names are:

Calculator                        "SciCalc"
Notepad                           "Notepad"
Paintbrush (Win3x            "pbParent"
Paint (Win95)                    "MSPaintApp"
Write (Win3x)                    "MSWRITE_MENU"
WordPad (Win95)             "WordPadClass"
Word 2/6/7                        "OpusApp"
Excel 4/5/7                       "XLMAIN"
PowerPoint 4                      "PPApplicationClass"
PowerPoint 7                      "PP7FrameClass"
ToolBook (authoring            "ToolBook"
ToolBook (runtime)                "TBKMain"
Windows Help                     "MS_WINDOC"
WinHelp32 Topic                 "MS_WINDOC_SECONDARY"
File Manager                      "WFS_Frame"
Control Panel                     "CtlPanelClass"
Print Manager                     "PrintManager"
Explore (Win95)                   "ExploreWClass"
Program Manager                   "Progman"
Microsoft Exchange 4.0            "Microsoft Exchange 4.0 Viewer"
Microsoft Internet Explorer 3.0   "IEFrame"
Lotus Organizer 2.1               "TzBook"
Lotus123 5.0                      "123WParent"
Lotus Approach 96                 "ApproachWClass"
Lotus Freelance Graphics 96       "FLWApp"
Lotus ScreenCam 2.1               "ScreenCamMainWnd"
Lotus WordPro 96                  "WordProAppWndNT"

Greetings MvZ

0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1359261
You can find a class name of any active application by using the Spy program, coming with Delphi.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

Author Comment

by:almiller
ID: 1359262
Thanks for you answer. This _is_ what I was looking for, but it lacks the ClassName part which mvz commented on.

The two lines of code you wrote work on NotePad but not on anything else. I can only assume it has to do with the ClassName, so I need to know how to find the ClassName without any external programs such as Spy.
0
 
LVL 5

Expert Comment

by:ronit051397
ID: 1359263
What application you need to close?
0
 
LVL 4

Expert Comment

by:tomerlei
ID: 1359264
how can i close netscape window?
0
 
LVL 2

Accepted Solution

by:
mvz121697 earned 600 total points
ID: 1359265
When you don't know the classname you can use
the Window-name.
If you want to close netscape you can:

procedure TForm1.Button1Click(Sender: TObject);
var cWindow:string;
    h:integer;
begin
 cWindow:='Netscape';
 h:=FindWindow(nil,Pchar(cWindow));
 if h>0 then SendMessage(h,WM_CLOSE,0,0);
end;

Be sure to use the exact windowname. If a document is opened, and the document name is also in the caption, you must provide this whole new caption-name.

You can also find a classname if you know the WindowName, by using this routine:

var cCLassName: PChar;
    cName:string;
    cWindow:string;
    n,h:integer;
begin
 cWindow:='Test.txt - Notepad';           // exact caption
 h:=FindWindow(nil,Pchar(cWindow));
 if h>0 then begin
   GetMem(cCLassName,256);
   try
    n:=GetClassname(h,cCLassName,256);
    if n=0 then ShowMessage('Error')
    else begin
      ShowMessage('Classname is '+cCLassName);
    end;
   finally
    Freemem(cCLassName,256);
   end;
 end else MessageBeep(0);
end;


BTW, you can use EnumWindows function to get a list of
all openend windows.


Greetings,
MvZ
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
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…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses

864 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