[英]How to Clicked ok button of messagebox pops up on click the xyz application from my c# application
i am trying to click the ok button of messagebox pops up when i click the button of xyz application from my c# application.当我从我的 c# 应用程序中单击 xyz 应用程序的按钮时,我试图单击弹出消息框的确定按钮。 i have tried the following code so that the button of xyz is clicked but C# application freeze after pops up message box is appeared.
我尝试了以下代码,以便单击 xyz 的按钮,但出现弹出消息框后 C# 应用程序冻结。 i have created two button button1- to click the button of xyz application button2- to click the ok button of message box.
我创建了两个按钮 button1- 单击 xyz 应用程序按钮 button2- 单击消息框的确定按钮。
//button1 code //按钮1代码
IntPtr maindHwnd = FindWindow(null,"xyz application");
if (maindHwnd != IntPtr.Zero)
{
IntPtr panel = FindWindowEx(maindHwnd, IntPtr.Zero, "MDIClient", null);
IntPtr panel1 = FindWindowEx(panel, IntPtr.Zero, "TAveForm", null);
IntPtr panel2 = FindWindowEx(panel1, IntPtr.Zero, "TPanel", "Panel5");
IntPtr panel3 = FindWindowEx(panel2, IntPtr.Zero, "TPanel", null);
IntPtr childHwnd = FindWindowEx(panel3, IntPtr.Zero, "TBitBtn", "Save");
if (childHwnd != IntPtr.Zero)
{
SendMessage(childHwnd, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
}
}
//button2 code //按钮2代码
IntPtr hWnd = FindWindow(null, "Error");
if (hWnd != IntPtr.Zero)
{
IntPtr childHwnd = FindWindowEx(hWnd, IntPtr.Zero, "Button", "Ok");
if (childHwnd != IntPtr.Zero)
{
SendMessage(childHwnd, BM_CLICK, IntPtr.Zero, IntPtr.Zero);
}
} }
You can try this;你可以试试这个;
[DllImport("user32.dll", SetLastError = true)]
static public extern IntPtr FindWindow(string lpClassName, string lpWindowName);
[DllImport("user32.dll")]
static public extern bool GetWindowRect(IntPtr hWnd, out Rectangle lpRect);
var hwnd = FindWindow(null, "WindowTitle");
if (hwnd != IntPtr.Zero)
{
if (GetWindowRect(hwnd, out Rectangle rect))
{
// rect..
}
}
You can use pinvoke.net for signature differences.您可以使用pinvoke.net进行签名差异。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.