Check if the MessageBox is

I have a function where I can respond to windows that appear. Now I want to find out if the Messagebox window that appears is. And if he is alone, I want to read his text.

I can already extract the window title, class name and process id

[DllImport("user32.dll", CharSet = CharSet.Unicode)]
internal static extern int GetWindowText(IntPtr hWnd, StringBuilder text, int count);

[DllImport("user32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
internal static extern int GetClassName(IntPtr hWnd, StringBuilder lpClassName, int nMaxCount);

[DllImport("user32.dll")]
internal static extern int GetWindowThreadProcessId(IntPtr hWnd, out int lpdwProcessId);

But how can I find out the message text?

To get all the windows, I use this:

internal static class WindowFinder
    {
    private static readonly List<IntPtr> listWindows = new List<IntPtr>();

    private static bool IsWindowOrDialog(IntPtr hwnd, int lParam)
    {
        if (NativeMethods.IsHungAppWindow(hwnd) || !NativeMethods.IsWindowVisible(hwnd))
            return true;
        listWindows.Add(hwnd);
        return true;
    }

    internal static IEnumerable<IntPtr> GetAllWindows()
    {
        listWindows.Clear();
        NativeMethods.EnumWindows(IsWindowOrDialog, IntPtr.Zero);
        return listWindows;
    }
}
+5
source share
1 answer

I do not know what you are trying, but you can:

Because MessageBox have type static (0xFFFF), you have to use GetDlgItemand GetWindowTextas follows:

IntPtr dlgHandle = GetDlgItem(MboxHandle, 0xFFFF);
GetWindowText(dlgHandle, yourStringBuilder, maxTextCount);
+1
source

All Articles