【问题标题】:C# webbrowser close save file dialogC# webbrowser 关闭保存文件对话框
【发布时间】:2013-07-09 23:19:21
【问题描述】:

我需要在网络浏览器中禁用“另存为”文件下载对话框。

我是这样找到的:

void ListenForDialogCreation()
{
    // Listen for name change changes across all processes/threads on current desktop...
    _WinEventHook = WinAPI.SetWinEventHook(WinAPI.EVENT_OBJECT_CREATE, procDelegate);
}
void StopListeningForDialogCreation()
{
    WinAPI.UnhookWinEvent(_WinEventHook);
}

void WinEventProc(IntPtr hWinEventHook, uint eventType, IntPtr hwnd, int idObject, int idChild, uint dwEventThread, uint dwmsEventTime)
{
    const uint OBJID_WINDOW = 0;
    const uint CHILDID_SELF = 0;

    // filter out non-HWND, and things not children of the current application
    if (idObject != OBJID_WINDOW || idChild != CHILDID_SELF)
        return;

    //Get the window class name
    StringBuilder ClassName = new StringBuilder(100);
    WinAPI.GetClassName(hwnd, ClassName, ClassName.Capacity);

    // Send close message to any dialog
    if (ClassName.ToString() == "#32770")
    {
        WinAPI.SendMessage(hwnd, WinAPI.WM.CLOSE, IntPtr.Zero, IntPtr.Zero);
        if (OnDialogCancelled != null)
            OnDialogCancelled();
    }
    if (ClassName.ToString() == "#32768")
    {
        WinAPI.SendMessage(hwnd, WinAPI.WM.CLOSE, IntPtr.Zero, IntPtr.Zero);
        if (OnDialogCancelled != null)
            OnDialogCancelled();
    }

}

public delegate void OnDialogCancelledEvent();
public event OnDialogCancelledEvent OnDialogCancelled;

但这里使用缺少的 dll。请帮帮我。

这是我找到代码的地方:How to block downloads in .NET WebBrowser control?

【问题讨论】:

  • 我需要禁用带有下载文件的窗​​口...
  • 现有 .net 应用程序中的嵌入式浏览器组件(System.Controls.Browser 等)不需要 ActiveX。

标签: c# dialog download


【解决方案1】:

唯一缺少的是 pinvoke 包装器,您可以从文档中自己编写(或使用 pinvoke.net 以便通过剪切和粘贴示例轻松参考),或使用现有的包装器库之一(如果你能找到一个这与您的许可需求兼容)。

【讨论】:

  • 我们可以使用钩子来更改事件下载文件吗?
  • 我不明白你在问什么。你想做什么?
猜你喜欢
  • 2013-07-06
  • 1970-01-01
  • 1970-01-01
  • 2016-04-17
  • 1970-01-01
  • 2016-10-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多