Solved

window kill or is it process kill?

Posted on 2007-11-27
18
500 Views
Last Modified: 2010-05-18
is there a


HWND kill (hwnd hwnd1)

?
0
Comment
Question by:Troudeloup
  • 9
  • 6
  • 2
  • +1
18 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20362548
Maybe you need CloseWindow(hwnd)
0
 

Author Comment

by:Troudeloup
ID: 20362561
that only minimize window.
0
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20362579
then use DestroyWindow(), it destroys the window and invalidates the hWnd handle
0
 

Author Comment

by:Troudeloup
ID: 20362582
it actually doesn't work.

( tried that first )


it's not a mere window

i am trying to kill half life 2.
0
 

Author Comment

by:Troudeloup
ID: 20362586
in a window.
0
 
LVL 4

Expert Comment

by:yuy2002
ID: 20362863
if you know the process name,you could do like this:
ShellExecute(NULL,"open","taskkill","/im process-name /t /f",NULL,SW_HIDE);
0
 

Author Comment

by:Troudeloup
ID: 20362865
how do I get process name from hwnd?
0
 
LVL 86

Expert Comment

by:jkr
ID: 20362902
If you want to close an appliction, take a look at the code from http://support.microsoft.com/default.aspx?scid=KB;en-us;178893& ("How To Terminate an Application "Cleanly" in Win32") which works for pretty much everything.
0
 

Author Comment

by:Troudeloup
ID: 20362939
http://msdn2.microsoft.com/en-us/library/ms686714.aspx

BOOL WINAPI TerminateProcess(
  __in  HANDLE hProcess,
  __in  UINT uExitCode
);


  __in  HANDLE hProcess,


is this hwnd?



  __in  UINT uExitCode

what is this?


also, can I call this function out of the blue like

TerminateProcess( hwnd, var );



?
0
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 86

Expert Comment

by:jkr
ID: 20362964
You should only use 'TerminateProcess()' as a last resort, since it forcefully ends the process. Rather try the other code in the article at http://support.microsoft.com/default.aspx?scid=KB;en-us;178893& ("How To Terminate an Application "Cleanly" in Win32") before, i.e.

SendMessage(hwnd,WM_CLOSE,0,0);

first.
0
 

Author Comment

by:Troudeloup
ID: 20363010
i actually know that's what I want to do :D


how does it work?
0
 
LVL 86

Expert Comment

by:jkr
ID: 20363095
'SendMessage()'? Well, that one sends a 'close' request to the window in question, usually causing it to shut down. If you really want to terminate that process, use 'GetWindowThreadProcessId()', e.g

DWORD dwPID;
GetWindowThreadProcessId(hwnd,&dwPID);

HANDLE hProcess = OpenProcess(PROCESS_TERMINATE,FALSE,dwPID);

TerminateProcess(hProcess,-1);

CloseHandle(hProcess);
0
 

Author Comment

by:Troudeloup
ID: 20363334
I got a warning with



TerminateProcess(hProcess,-1);


kill_window.cpp:37: warning: passing negative value `-0x000000001' for converting 2 of `BOOL TerminateProcess(void*, UINT)'
0
 
LVL 86

Accepted Solution

by:
jkr earned 500 total points
ID: 20363354
Ignore it or pass 0 instead, i.e.

TerminateProcess(hProcess,0);

 ;o)
0
 

Author Comment

by:Troudeloup
ID: 20363362
0
 
LVL 86

Expert Comment

by:jkr
ID: 20363371
Sorry, but I am gonna hit the sack now for today, it is simply getting too late (or too early ;o) ?
0
 

Author Comment

by:Troudeloup
ID: 20363374
oh god, this is my 14th hours for computers.

yet I have to go see Enchanted, figure i ll pass out there a bit ;p
0
 
LVL 86

Expert Comment

by:jkr
ID: 20363380
Sleep well! *g*
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

757 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now