CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    May 1999
    Posts
    13

    Killing/Destroying windows

    Hi,
    I'm building a command-line program to kill a window in winNT. Usage should be something like this : 'kill "test.txt - Notepad"'.

    This what i have:
    First I look for a HWND using EnumDesktopWindows and/or FindWindow,
    then I call the method GetWindowThreadProcessId, which returns a PID. I use this PID with OpenProcess to get an HANDLE to this process. At last i try to terminate this process by TerminateProcess, but does nothing but *CRASH*

    What am I doing wrong, or, how should i do this otherwise?

    Grthnx,
    Paul Kuijer



  2. #2
    Join Date
    May 1999
    Posts
    19

    Re: Killing/Destroying windows

    I think crash was because of something else, there is nothing wrong with your approach. I tried and succeeded,
    DWORD dwProcessId;
    HWND hWnd = ::FindWindow(NULL, "Untitled - Notepad");
    GetWindowThreadProcessId(hWnd, &dwProcessId);
    HANDLE hProcess = OpenProcess(PROCESS_TERMINATE, FALSE, dwProcessId);
    TerminateProcess(hProcess, 1);

    Notepad was terminated without any problem.

    [email protected]
    Bangalore,
    India.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured