System.Windows.Forms.WebBrowser control DPI support?

0

How can I make the System.Windows.Forms.WebBrowser control use de DPI_AWARE flag to display documents with DPI support? If anyone can post a code example would be appreciated.

Edit 1: added more details

The problem is that px unit is treated as normal pixel unit (not web-like), so sizes at 150% dpi configuration differs a lot and even more on higher dpi settings. WebBrowser.Version is 11.x

class myWebBrowser: System.Windows.Forms.WebBrowser, IDocHostUIHandler
{
    private const uint E_NOTIMPL = 0x80004001;
    private const uint S_OK = 0;
    private const uint S_FALSE = 1;
    private HostUIFlags flags = HostUIFlags.DPI_AWARE;

    public myWebBrowser()
    {
        this.DocumentCompleted += OnLoadCompleted;
    }

    private void OnLoadCompleted(object sender, WebBrowserDocumentCompletedEventArgs args)
    {
        ICustomDoc doc = this.Document.DomDocument as ICustomDoc;
        if (doc != null)
        {
            \\code reaches this point
            doc.SetUIHandler(this);
        }
    }

    uint GetHostInfo(ref DOCHOSTUIINFO info)
    {
        info.dwFlags = (int)flags;
        info.dwDoubleClick = 0;
        return S_OK;
    }

    \\other IDocHostUIHandler methods...

}

The interfaces are defined here:

[ComImport, Guid("3050F3F0-98B5-11CF-BB82-00AA00BDCE0B"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface ICustomDoc
{
    [PreserveSig]
    int SetUIHandler(IDocHostUIHandler pUIHandler);
}

[ComImport, Guid("BD3F23C0-D43E-11CF-893B-00AA00BDCE1A"), InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
internal interface IDocHostUIHandler
{
    [PreserveSig]
    uint ShowContextMenu(int dwID, POINT pt, [MarshalAs(UnmanagedType.Interface)] object pcmdtReserved, [MarshalAs(UnmanagedType.Interface)] object pdispReserved);

    [PreserveSig]
    uint GetHostInfo(ref DOCHOSTUIINFO info);

    [PreserveSig]
    uint ShowUI(int dwID, [MarshalAs(UnmanagedType.Interface)] object activeObject, [MarshalAs(UnmanagedType.Interface)] object commandTarget, [MarshalAs(UnmanagedType.Interface)] object frame, [MarshalAs(UnmanagedType.Interface)] object doc);

   \\etc.
}

[StructLayout(LayoutKind.Sequential)]
internal struct DOCHOSTUIINFO
{
    public int cbSize;
    public int dwFlags;
    public int dwDoubleClick;
    public IntPtr dwReserved1;
    public IntPtr dwReserved2;
}
c#
winforms
webbrowser-control
asked on Stack Overflow Mar 15, 2017 by Federico • edited Mar 15, 2017 by Federico

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0