I have a function where i can react on appearing windows. Now i want to know if the appearing window is a Messagebox. And if it is one, i want to read the text of it.
I'm already able to extract the Window-Title, Class-Name and Process-Id by
[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 text of a messagebox?
To get all windows i am using 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;
}
}
I don't know what you're trying exactly but you can:
FindWindow
GetDlgItem
and extract the text usingGetWindowText
Since MessageBoxes are of type static (0xFFFF), you should use GetDlgItem
and GetWindowText
like this:
IntPtr dlgHandle = GetDlgItem(MboxHandle, 0xFFFF);
GetWindowText(dlgHandle, yourStringBuilder, maxTextCount);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With