-1

I need to disable "save as" file download dialog in webbrowser.

I found this way:

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;

But here using missing dll. Help me please.

This is where I found the code: How to block downloads in .NET WebBrowser control?

Community
  • 1
  • 1

1 Answers1

0

The only thing missing is the pinvoke wrappers, which you can either write yourself from the documentation (or use pinvoke.net for easy reference with cut&pastable examples), or use one of the wrapper libraries that exist (if you can find one that's compatible with your licensing needs).

Malcolm
  • 1,239
  • 1
  • 14
  • 25