Link to home
Start Free TrialLog in
Avatar of almiller
almiller

asked on

Termination of a program in memory

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.
Avatar of ronit051397
ronit051397

To Close a notepad document:
SendMessage(FindWindow('notepad', nil), wm_Destroy, 0, 0);
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

You can find a class name of any active application by using the Spy program, coming with Delphi.
Avatar of almiller

ASKER

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.
What application you need to close?
how can i close netscape window?
ASKER CERTIFIED SOLUTION
Avatar of mvz121697
mvz121697

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial