-1

我需要在 webbrowser 中禁用“另存为”文件下载对话框。

我发现这种方式:

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?

4

1 回答 1

0

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

于 2013-07-10T00:54:52.450 回答