Solved

window kill or is it process kill?

Posted on 2007-11-27
18
504 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
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!

 

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 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

Technology Partners: 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

Suggested Solutions

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

685 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