| View previous topic :: View next topic |
| Author |
Message |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Sat Apr 12, 2008 1:59 am Post subject: Delphi stop and application from starting or running |
|
|
hey, i was wondering if anyone could help me with a little something im working on, basically im trying to stop a process or application from running, anyone got any ideas?
_________________
|
|
| Back to top |
|
 |
NothingToShow Grandmaster Cheater Supreme
Reputation: 0
Joined: 11 Jul 2007 Posts: 1579
|
Posted: Sat Apr 12, 2008 2:35 am Post subject: |
|
|
http://www.latiumsoftware.com/en/delphi/00034.php
| Quote: | To close another application you can use the PostMessage API declared in the Windows unit to send a WM_CLOSE message to its main form. This function requires the handle of the window to which you want to post the message. You can get this handle for example using the FindWindow API, also declared in the Windows unit.
Here is a source code example:
uses Windows, Messages;
procedure TForm1.Button1Click(Sender: TObject);
var
h: HWND;
begin
h := FindWindow(nil, 'Main Form Caption');
if h <> 0 then PostMessage(h, WM_CLOSE, 0, 0);
end;
Instead of 'Main Form Caption' you should write the title (caption) of the main form of the application you want to close. Be sure this name is unique or you might end up closing another application (for example it wouldn't be good a name like 'Form1'). |
|
|
| Back to top |
|
 |
Snootae Grandmaster Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 969 Location: --->
|
Posted: Sat Apr 12, 2008 4:36 am Post subject: |
|
|
thanks moller, works well
_________________
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Apr 12, 2008 11:28 am Post subject: |
|
|
| If you're going to use FindWindow, use the class instead of the actual window name.
|
|
| Back to top |
|
 |
NothingToShow Grandmaster Cheater Supreme
Reputation: 0
Joined: 11 Jul 2007 Posts: 1579
|
Posted: Sat Apr 12, 2008 1:07 pm Post subject: |
|
|
| slovach wrote: | | If you're going to use FindWindow, use the class instead of the actual window name. |
I've got a question about the class name thing.
How do you know what the classname is?
|
|
| Back to top |
|
 |
killersamurai Expert Cheater
Reputation: 0
Joined: 10 Sep 2007 Posts: 197 Location: Colorado
|
|
| Back to top |
|
 |
hcavolsdsadgadsg I'm a spammer
Reputation: 26
Joined: 11 Jun 2007 Posts: 5801
|
Posted: Sat Apr 12, 2008 1:59 pm Post subject: |
|
|
| Moller wrote: | | slovach wrote: | | If you're going to use FindWindow, use the class instead of the actual window name. |
I've got a question about the class name thing.
How do you know what the classname is? |
Spy++
|
|
| Back to top |
|
 |
rapion124 Grandmaster Cheater Supreme
Reputation: 0
Joined: 25 Mar 2007 Posts: 1095
|
Posted: Sat Apr 12, 2008 7:43 pm Post subject: |
|
|
| Lol. It's ironic that you need a window handle to obtain the class, when obtaining the window handle requires the class or caption.
|
|
| Back to top |
|
 |
Symbol I'm a spammer
Reputation: 0
Joined: 18 Apr 2007 Posts: 5094 Location: Israel.
|
Posted: Sun Apr 13, 2008 1:36 am Post subject: |
|
|
| rapion124 wrote: | | Lol. It's ironic that you need a window handle to obtain the class, when obtaining the window handle requires the class or caption. |
Or, you could loop through all windows and get the class name, window name AND handle using GetWindow, GetClassNameA/W and GetWindowTextA/W APIs.
|
|
| Back to top |
|
 |
|