Solved

Termination of a program in memory

Posted on 1998-02-15
7
196 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
Comment Utility
To Close a notepad document:
SendMessage(FindWindow('notepad', nil), wm_Destroy, 0, 0);
0
 
LVL 2

Expert Comment

by:mvz121697
Comment Utility
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
Comment Utility
You can find a class name of any active application by using the Spy program, coming with Delphi.
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

Author Comment

by:almiller
Comment Utility
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
Comment Utility
What application you need to close?
0
 
LVL 4

Expert Comment

by:tomerlei
Comment Utility
how can i close netscape window?
0
 
LVL 2

Accepted Solution

by:
mvz121697 earned 200 total points
Comment Utility
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

771 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now