Ho una funzione in cui posso rispondere alle finestre che appaiono. Ora voglio sapere se la finestra che appare è una Messagebox. E se è uno, voglio leggere il testo di esso.Controlla se la finestra è un MessageBox
Sono già in grado di estrarre il Window-Titolo, Class-Nome e 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);
Ma come posso scoprire il testo di una messagebox?
Per avere tutte le finestre Sto usando questo:
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;
}
}
Piuttosto che rovistando con i messaggi di finestra, ecc perché non utilizzare le classi gestite per [Accessibilità e Automation] (http://msdn.microsoft.com/en-us/library/ms753388.aspx) che sono progettati per questo tipo di cose. –