我有一个列表Uri,我想要"点击"为了达到这个目的,我试图为每个Uri创建一个新的Web浏览器控件.我为每个Uri创建一个新线程.我遇到的问题是文档在文档之前结束是完全加载的,所以我永远不会使用DocumentComplete事件.我怎么能克服这个?
var item = new ParameterizedThreadStart(ClicIt.Click);
var thread = new Thread(item) {Name = "ClickThread"};
thread.Start(uriItem);
public static void Click(object o)
{
var url = ((UriItem)o);
Console.WriteLine(@"Clicking: " + url.Link);
var clicker = new WebBrowser { ScriptErrorsSuppressed = true };
clicker.DocumentCompleted += BrowseComplete;
if (String.IsNullOrEmpty(url.Link)) return;
if (url.Link.Equals("about:blank")) return;
if (!url.Link.StartsWith("http://") && !url.Link.StartsWith("https://"))
url.Link = "http://" + url.Link;
clicker.Navigate(url.Link);
}
Run Code Online (Sandbox Code Playgroud) 这是我之前的问题的延续.如何抑制Inproc COM服务器显示的对话框.
回顾一下我的情况:我有一个从第三方用Delphi编写的Inproc COM服务器.如果它捕获特定类型的错误,我调用的函数之一将显示错误消息对话框.问题是我正在尝试批量处理数据,我正在使用的数据源导致错误对话框弹出很多(感谢我之前的问题的答案它现在自动关闭,我能够运行它到完成后,它会显示对话框并要求有人按OK 9923次).进程将阻塞,直到消息框关闭.
我想更好地记录错误对话框所说的内容.但是,任何获取对话框正文的尝试都失败了.

//Snip
private void StartWindowListener()
{
//Queue the watcher on the message pump if we are not watching.
if (_watcherRunning == false)
{
_watcherRunning = true;
_dummyForm.BeginInvoke(new Action(() =>
{
_watcherRunning = false;
//If we are not inside the com object don't enumerate.
if (_insideCom == false) return;
// Enumerate windows to find dialogs
EnumThreadWndProc callback = new EnumThreadWndProc(CheckWindow);
EnumThreadWindows(GetCurrentThreadId(), callback, IntPtr.Zero);
GC.KeepAlive(callback);
}));
}
}
private bool CheckWindow(IntPtr hWnd, IntPtr …Run Code Online (Sandbox Code Playgroud) 正如标题所示,我试图以编程方式模拟MessageBox中的按钮单击.我之前尝试通过其标题找到其句柄,并应用WM_CLOSE或SC_CLOSE在中关闭MessageBox SendMessage().但是,由于存在"是/否"按钮,这不起作用(X按钮呈灰色显示).
现在我想点击No按钮,如下所示 - :
List<IntPtr> result = new List<IntPtr>();
GCHandle listHandle = GCHandle.Alloc(result);
try
{
IntPtr Window_hWnd = CloseMessageBox.FindWindowByCaption("#32770", "LastQuestion"); //Could use null as the first argument too. "#32770" represents classname Dialog.
CloseMessageBox.EnumChildWindows(Window_hWnd, (hWnd, lParam) =>
{
StringBuilder sb = new StringBuilder();
foreach (var control in GCHandle.FromIntPtr(lParam).Target as List<IntPtr>)
{
CloseMessageBox.GetWindowText(control, sb, 250);
if (sb.Equals("&No"))
{
CloseMessageBox.PostMessage(hWnd, CloseMessageBox.MouseDown, 0, 0);
CloseMessageBox.PostMessage(hWnd, CloseMessageBox.MouseUp, 0, 0);
}
}
return false;
}, GCHandle.ToIntPtr(listHandle));
}
catch (Exception e) …Run Code Online (Sandbox Code Playgroud)