Solved

window kill or is it process kill?

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


HWND kill (hwnd hwnd1)

?
0
Comment
Question by:Troudeloup
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
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!

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

734 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