How can I close another application?
Applies To: C++Builder 1 or higher
Category: Knowledge Base
- I can close my own forms by using the Close method. But how can I shutdown a 3rd party application such as Notepad ®.
-
- Start a new project using File | New Application.
-
- Add a Button. Edit its OnClick event:
-
- void __fastcall TForm1::Button1Click(TObject *Sender)
- {
- HANDLE handle = FindWindow("Notepad", NULL);
- if(handle)
- SendMessage(handle, WM_SYSCOMMAND, SC_CLOSE, NULL);
- }
-
- To get the handle of a particular window using FindWindow, you have to know the caption and/or the class of this window.
C++Builder Developer's Network
Copyright © Yoto Yotov