2020年12月22日星期二

i have a question about how to get the control of the WebBrowser in a c# WPF Program [closed]

Now i have a C# WPF Program ,at the main page ,there is control named WebBrowser ,i can get the handle of the WPF Program ,but now i want to run some javascript on the HTML in the WebBrowser , so how can i do for it by C#,i want some Pseudocode to help me to solve this problem. And now ,if i use User32.dll like

[DllImport("User32.dll", EntryPoint = "FindWindow")]  private static extern IntPtr FindWindow(string lpClassName, string lpWindowName);  [DllImport("user32.dll", EntryPoint = "FindWindowEx", SetLastError = true)]  private static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr hwndChildAfter, string lpszClass, string lpszWindow);  var ParenthWnd = FindWindow(null, "MainWindow"); //!=0x00000000  var webbrowser = FindWindowEx(ParenthWnd, (IntPtr)0, "WebBrowser", ""); //0x00000000  

the program window's handle i can found but i cannot found the webbroswer's handle,and then i use FlaUI in nuget

var app = FlaUI.Core.Application.Attach(23480);//Myapp's process id  using (var automation = new FlaUI.UIA3.UIA3Automation())  {        var window = app.GetMainWindow(automation); //!= null        var kajiezhi = window.FindFirstDescendant(cf => cf.ByClassName("WebBrowser")); //null  }  

23480 was the process id in my computer ,and GetMainWindow can get my window but next find b y classname it still can not work for it ,so what can i do for it

https://stackoverflow.com/questions/65406269/i-have-a-question-about-how-to-get-the-control-of-the-webbrowser-in-a-c-sharp-wp December 22, 2020 at 05:33PM

没有评论:

发表评论