//event handling if(LOWORD(wParam) == 2) { SendMessage(name, WM_GETTEXT, sizeof(cname), (ULONG)cname); //static HWND window; if(FindWindow(NULL, cname) != NULL) { HWND fWindow; fWindow = FindWindow(NULL, cname); SendMessage(fWindow,WM_SYSCOMMAND,SC_CLOSE, NULL); } else { MessageBox(NULL, "Cannot find such Window", "Warning", MB_OK); } }