• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 516
  • Last Modified:

window kill or is it process kill?

is there a


HWND kill (hwnd hwnd1)

?
0
Troudeloup
Asked:
Troudeloup
  • 9
  • 6
  • 2
  • +1
1 Solution
 
Jaime OlivaresSoftware ArchitectCommented:
Maybe you need CloseWindow(hwnd)
0
 
TroudeloupAuthor Commented:
that only minimize window.
0
 
Jaime OlivaresSoftware ArchitectCommented:
then use DestroyWindow(), it destroys the window and invalidates the hWnd handle
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
TroudeloupAuthor Commented:
it actually doesn't work.

( tried that first )


it's not a mere window

i am trying to kill half life 2.
0
 
TroudeloupAuthor Commented:
in a window.
0
 
yuy2002Commented:
if you know the process name,you could do like this:
ShellExecute(NULL,"open","taskkill","/im process-name /t /f",NULL,SW_HIDE);
0
 
TroudeloupAuthor Commented:
how do I get process name from hwnd?
0
 
jkrCommented:
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
 
TroudeloupAuthor Commented:
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
 
jkrCommented:
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
 
TroudeloupAuthor Commented:
i actually know that's what I want to do :D


how does it work?
0
 
jkrCommented:
'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
 
TroudeloupAuthor Commented:
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
 
jkrCommented:
Ignore it or pass 0 instead, i.e.

TerminateProcess(hProcess,0);

 ;o)
0
 
TroudeloupAuthor Commented:
0
 
jkrCommented:
Sorry, but I am gonna hit the sack now for today, it is simply getting too late (or too early ;o) ?
0
 
TroudeloupAuthor Commented:
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
 
jkrCommented:
Sleep well! *g*
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

  • 9
  • 6
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now