![](/img/trans.png)
[英]MessageBox 'Could not load TalkAPI library' pops up after defining an Excel Application in C# .Net Framework 4.5
[英]How to Clicked ok button of messagebox pops up on click the xyz application from my c# application
當我從我的 c# 應用程序中單擊 xyz 應用程序的按鈕時,我試圖單擊彈出消息框的確定按鈕。 我嘗試了以下代碼,以便單擊 xyz 的按鈕,但出現彈出消息框后 C# 應用程序凍結。 我創建了兩個按鈕 button1- 單擊 xyz 應用程序按鈕 button2- 單擊消息框的確定按鈕。
//按鈕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);
}
}
//按鈕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);
}
}
你可以試試這個;
[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..
}
}
您可以使用pinvoke.net進行簽名差異。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.