我需要禁用"另存为" 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?
答案 0 :(得分:0)
唯一缺少的是pinvoke包装器,您可以从文档中自己编写(或使用pinvoke.net以便通过剪切和可操作的示例进行简单参考),或者使用其中一个存在的包装器库(如果可以的话)找到一个与您的许可需求兼容的产品。)