Re: How to shut down a running application
From: Andrew Diabo (aadiabo_at_ix.netcom.com)
Date: 08/03/04
- Next message: Hallvard Vassbotn: "Re: NexusDB Memory Manager version 2 released"
- Previous message: Andrew Diabo: "Access Rights to folders in Win2k/XP"
- In reply to: Branko Burdian: "Re: How to shut down a running application"
- Next in thread: Matthew Jones: "Re: How to shut down a running application"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 2 Aug 2004 21:58:03 -0400
Hi Branko,
Thanks so much for the code. I will definitely give it a spin.
Andrew
"Branko Burdian" <burdian@siol.net> wrote in message
news:410e9a43$1@newsgroups.borland.com...
>
> "Andrew Diabo" <aadiabo@ix.netcom.com> wrote in message
> news:410e87bc@newsgroups.borland.com...
> > Hi Steve,
> >
> > I'm trying to close applications that are not necessarily Delphi
> > applications,
> > which means that I would not know the first parameter of FindWindow
> > (Window Class) in advance. Can I know this Window Class from code
> > for any running application?
>
> You can found ClassName with, for examle, WinDowse,
> if you don't know ClassName you must at least know WindowTitle
> (Form.Caption).
>
> Close Appl with this proc:
>
> procedure CloseAppl(const AClassName: string = ''; const AWindowTitle:
> string = '');
>
> function FindWindowByTitle(const ATitle: string): HWND;
> var
> WinHandle: HWND;
> WinTitle: array[0..255] of char;
> begin
> Result := 0;
> WinHandle := GetWindow(Application.Handle, GW_HWNDFIRST);
> while WinHandle > 0 do
> begin
> FillChar(WinTitle, Length(WinTitle), #0);
> GetWindowText(WinHandle, WinTitle, Length(WinTitle) - 1);
> if Pos(ATitle, String(WinTitle)) <= 0 then
> WinHandle := GetWindow(WinHandle, GW_HWNDNEXT)
> else begin
> Result := WinHandle;
> Break;
> end;
> end;
> end;
> var
> WinHandle: HWND;
> begin
> if AClassName = '' then
> WinHandle := FindWindowByTitle(AWindowTitle)
> else
> if AWindowTitle = '' then
> WinHandle := FindWindow(PChar(AClassName), nil)
> else
> WinHandle := FindWindow(PChar(AClassName),
PChar(AWindowTitle));
> SendMessage(WinHandle, WM_SYSCOMMAND, SC_CLOSE, 0)
> end;
>
> Best Regards
> Branko
>
> >
> > Thanks again
> > Andrew
> >
> > "Steve Forbes" <ozmosys@spamfreeoptusnet.com.au> wrote in message
> > news:410b356d@newsgroups.borland.com...
> > > Hi Andrew,
> > >
> > > You seem to have entirely missed my post (was first reply in thread)
> > > explaining how to do it with WM_CLOSE message ..
> > >
> > > Best regards
> > >
> > > Steve
> > >
> > > "Andrew Diabo" <aadiabo@ix.netcom.com> wrote in message
> > > news:410ae14a@newsgroups.borland.com...
> > > > Hi Bob,
> > > >
> > > > How do you recommend doing this in code safely?
> > > >
> > > > Thanks again.
> > > >
> > > > Andrew
> > > >
> > > > "Bob" <dont_write@dont_call.com> wrote in message
> > > > news:410a7d83$1@newsgroups.borland.com...
> > > > > > Then call TerminateProcess(ProcHandle, DWORD(-1));
> > > > >
> > > > > TerminateProcess should not be used until after you "ask" the
> > > application
> > > > to
> > > > > close with a WM_QUIT or WM_CLOSE message. It can result in lost
> > system
> > > > > memory, and prevents programs from cleaning up gracefully (i.e.
> > > returning
> > > > > window and graphic handles, etc.)
> > > > >
> > > > >
> > > >
> > > >
> > >
> > >
> >
> >
>
>
- Next message: Hallvard Vassbotn: "Re: NexusDB Memory Manager version 2 released"
- Previous message: Andrew Diabo: "Access Rights to folders in Win2k/XP"
- In reply to: Branko Burdian: "Re: How to shut down a running application"
- Next in thread: Matthew Jones: "Re: How to shut down a running application"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|