1

I want to close all the running instances of Notepad through my application. I got the window handle using

FindWindow() API.

I got the handle of Window.

CloseWindow() API

is minimizing the notepad but I want to close all the instances of Notepad.

How can I achieve this?

CLIX159
  • 67
  • 1
  • 11

1 Answers1

-1

By using FindWindow() you will get HWND

Use that HWND to get pid i.e process id.

HWND hWnd;  // using findwindow you will get hWnd
DWORD pid;
TCHAR tcInput [MAX_PATH];
CString strName;
GetWindowThreadProcessId(hWnd,&pid);
//::GetWindowText(hWnd,tcInput,MAX_PATH);
//strName = (CString)tcInput;
//if(strName.MakeLower().Find( _T("untitle"))!=-1)   //you can check windows title here
    KillProcess(pid);  // kill the process
Himanshu
  • 4,327
  • 16
  • 31
  • 39
  • Lots of commented out (and completely unrelated) code, followed by some fantasy API call. Sorry, -1 for sloppiness alone. – IInspectable Jul 15 '16 at 13:02