Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

window kill or is it process kill?

Posted on 2007-11-27
18
Medium Priority
?
510 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 

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
 
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 2000 total points
ID: 20363354
Ignore it or pass 0 instead, i.e.

TerminateProcess(hProcess,0);

 ;o)
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
Article by: evilrix
Looking for a way to avoid searching through large data sets for data that doesn't exist? A Bloom Filter might be what you need. This data structure is a probabilistic filter that allows you to avoid unnecessary searches when you know the data defin…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
Suggested Courses

885 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