简体   繁体   English

如何单击我的 c# 应用程序中的 xyz 应用程序时弹出消息框的确定按钮

[英]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.

相关问题 在C#.Net Framework 4.5中定义Excel应用程序后弹出MessageBox'无法加载TalkAPI库' - MessageBox 'Could not load TalkAPI library' pops up after defining an Excel Application in C# .Net Framework 4.5 如何在 c# 应用程序的 showdialog() 上自动单击确定按钮? - how to make automatic click ok button on showdialog() on c# application? 从我的C#应用​​程序中单击另一个应用程序中的按钮? - click on a button in another application from my C# application? 如何抑制运行 C# Winforms 应用程序时弹出的黑色 Shell? - How Can I Suppress the Black Shell that Pops Up When I Run my C# Winforms Application? 如何检查按钮是否在C#中的Windows窗体应用程序中的另一个按钮单击事件内被单击 - how to check whether a button is clicked, inside another button click event in windows form application in C# 单击MessageBox后,关闭C#控制台应用程序 - Close C# Console Application after MessageBox click 如何创建在用户设置的特定日期和时间弹出的WPF C#应用程序? - How do I create a WPF C# Application that pops up at a certain date and time set by the user? 如何在使用 C# 单击另一个按钮时弹出的 window 中放置另一个按钮 - How to place another button in a window that pops up from clicking another button using C# 如何获取,在C#Winform应用程序中单击表单上的哪个按钮 - how to get, which button is clicked on form in c# winform application 在C#WPF中的DataGrid中双击特定单元格时,如何弹出消息框或文本框 - How can I make a messagebox or textbox pop up when a specific cell is double clicked in my DataGrid in C# WPF
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM