Link to home
Start Free TrialLog in
Avatar of lippo
lippo

asked on

Use API to close a program?

You can close a program by pressing the Ctrl-Alt-Del.
How can I close a program by Win32 API?
ASKER CERTIFIED SOLUTION
Avatar of irishka
irishka

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
Avatar of caiger
caiger

There are several ways thay you can close a program.

The first legal way is to post the main window a message telling it to close down

PostMessage(hMainWindow, WM_CLOSE, 0, 0L);

or the more illegal way is to terminate the process using TerminateProcess.

However for both of these methods you either need to main window handle, or the process id
I ran the example on my machine, but it doesn't work. Why? My machine is windows xp.

Thank you!