how can i kill windows with their handels

if i only have the window classname and handle how can i kill his proccess?

Thanks,Daniel.
LVL 2
saar071697Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

intheCommented:
you can use:

PostMessage(Handle, WM_CLOSE, 0, 0);

or wm_quit but close is better as it gives the app (notepad for instance) a chance to ask if any changes are to be saved.
Regards Barry
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
kretzschmarCommented:
hi saar,

did you tried,

sendmessage(YourHandle,WM_CLOSE,0,0);
or
sendmessage(YourHandle,WM_QUIT,0,0);

meikl
0
kretzschmarCommented:
hi barry,

allways fast,
well postmessage with wm_close is the best choice.

meikl ;-)
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

intheCommented:
have to be fast to keep up with you ;-)
0
DValeryCommented:
I'm recomend to look on Madshi Site http://nettrash.com/users/madshi/

Valery
0
kretzschmarCommented:
hi barry,
its hard enough to keep you on distance ;-)

hi valery,
yes, madshis site is a good one

meikl
0
MadshiCommented:
Thanx, guys...   :-)

Well, you should not send WM_QUIT to a window handle. So my recommendation is one of these 3 things:

(1) PostMessage(windowHandle, WM_CLOSE, 0, 0);
(2) PostThreadMessage(GetWindowThreadProcessID(windowHandle, nil), WM_QUIT, 0, 0);
(3)
var pid : dword;
    ph  : dword;
begin
  GetWindowThreadProcessID(windowHandle, @pid);
  ph := OpenProcess(PROCESS_TERMINATE, false, pid);
  if ph <> 0 then
    try
      TerminateProcess(ph, 0);
    finally CloseHandle(ph);
end;

Perhaps you'll have to make some minor corrections to choice (3), because I've not test-compiled it.

If you want the user to be asked whether he wants to save the opened files, you should go with (1), else you should go with (2) or (3).

Regards, Madshi.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.