Hi =) You must look to WinApi methods FindWindow and method EndDialog.
you can use this class for your purpose:
public static class NativeMethods
{
private const string c_user32 = "user32.dll";
static NativeMethods() { }
#region user32 p/invoke
[DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
internal static extern IntPtr FindWindow(string className, string windowName);
[DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
internal static extern bool CloseWindow(IntPtr hWnd);
[DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
internal static extern bool DestroyWindow(IntPtr hWnd);
[DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
internal static extern bool BringWindowToTop(IntPtr hWnd);
[DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
internal static extern IntPtr SetFocus(IntPtr hWnd);
[DllImport(c_user32, SetLastError = true, CharSet = CharSet.Ansi)]
internal static extern bool EndDialog(IntPtr hDlg, IntPtr nResult);
#endregion
public static void CloseDialog(string windowName, bool bringToTop = false)
{
IntPtr hWd = default(IntPtr);
hWd = FindWindow(null, windowName);
if (hWd != default(IntPtr))
{
EndDialog(hWd, IntPtr.Zero);
}
}
}
To close you MessageBox call such construction:
NativeMethods.CloseDialog("Information")