Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Termination of a program in memory

Posted on 1998-02-15
7
Medium Priority
?
205 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
[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
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
Technology Partners: 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: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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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 Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

636 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