Я пытаюсь нажать кнопку "ОК" в окне сообщения формы окна С# с помощью winapi. Ниже приведен код, над которым я работаю.
private const int WM_CLOSE = 16;
private const int BN_CLICKED = 245;
[DllImport("user32.dll", CharSet=CharSet.Auto)]
public static extern int SendMessage(int hWnd, int msg, int wParam, IntPtr lParam);
[DllImport("user32.dll", SetLastError = true)]
public static extern IntPtr FindWindowEx(IntPtr parentHandle, IntPtr childAfter, string className, string windowTitle);
//this works
hwnd = FindWindow(null, "Message");
if(hwnd!=0)
SendMessage(hwnd, WM_CLOSE, 0, IntPtr.Zero);
//this doesn't work.
hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero, "Button", "ok");
SendMessage((int)hwndChild, BN_CLICKED, 0, IntPtr.Zero);
Хотя я получаю значение в hwndChild
, оно не распознает BN_CLICKED
. Я не уверен, что мне не хватает. любая помощь?
Я пытаюсь закрыть кнопку окна сообщения другого приложения, и это то, что я делаю. Но я все еще что-то упускаю.
IntPtr hwndChild = IntPtr.Zero;
hwndChild = FindWindowEx((IntPtr)hwnd, IntPtr.Zero,' '"Button", "OK");
SendMessage((int)hwndChild, WM_COMMAND, (BN_CLICKED '<<16) | IDOK, hwndChild);
System.Windows.Automation
. Вот пример, когда нажимает кнопку 7 в калькуляторе. Просто измените Калькулятор на Сообщение и 7 на ОК. - person Raymond Chen   schedule 19.02.2013