Solved

window kill or is it process kill?

Posted on 2007-11-27
18
503 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

774 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