I want to close a child window of a running application programmatically. I am using the following code:
const UInt32 WM_CLOSE = 0x0010;
[DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
public static extern IntPtr FindWindow(String lpClassName, String lpWindowName);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern IntPtr SendMessage(IntPtr hWnd, UInt32 Msg, IntPtr wParam, IntPtr lParam);
public static bool CloseWindowbyTitle(string titleStr)
{
bool result = false;
IntPtr windowPtr = FindWindow(null, titleStr);
if (windowPtr == IntPtr.Zero)
return result;
SendMessage(windowPtr, WM_CLOSE, IntPtr.Zero, IntPtr.Zero);
result = true;
return result;
}
It is working fine. But when the child window is in edit mode, it asks to the user to save edited data and if the user clicks on 'Yes' or 'No' then only child window gets closed.
But I want to close the child window forcefully, so that without asking anything it should get closed. But I don't know how to achieve this.
I can't use Process
class to kill child windows as no separate process is getting created for that child window.
Thanks in advance.