我需要在 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?