c# - cefsharp改变传给网站的参数屏幕的宽高c#

标签 c# cefsharp

你能帮忙吗,你如何改变cefsharp传输的屏幕尺寸?我去 ipleak.net 看到了 您的屏幕:1920 x 1080 可用屏幕:1920 x 1040

有什么办法可以改变吗?

我试过了,没用

DllImport("user32.dll", EntryPoint = "SetWindowPos")]
        static extern bool SetWindowPos(
             int hWnd,           // window handle
             int hWndInsertAfter,    // placement-order handle
             int X,          // horizontal position
             int Y,          // vertical position
             int cx,         // width
             int cy,         // height
             uint uFlags);   // window positioning flags

        [DllImport("USER32.DLL", CharSet = CharSet.Unicode)]
        public static extern IntPtr FindWindow(string lpClassName,
            string lpWindowName);


        protected delegate bool EnumWindowsProc(IntPtr hWnd, IntPtr lParam);
        [DllImport("user32.dll")]
        protected static extern bool EnumWindows(EnumWindowsProc enumProc, IntPtr lParam);


        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        protected static extern int GetWindowText(IntPtr hWnd, StringBuilder strText, int maxCount);
        [DllImport("user32.dll", CharSet = CharSet.Unicode)]
        protected static extern int GetWindowTextLength(IntPtr hWnd);
        [DllImport("user32.dll")]

        protected static extern bool IsWindowVisible(IntPtr hWnd);
        public static IntPtr m_hwndForm;

        protected static bool EnumTheWindows(IntPtr hWnd, IntPtr lParam)
        {
            int size = GetWindowTextLength(hWnd);
            if (size++ > 0 && IsWindowVisible(hWnd))
            {
                StringBuilder sb = new StringBuilder(size);
                GetWindowText(hWnd, sb, size);
                string strName = sb.ToString();
                if (strName.Contains("Form111111"))
                    m_hwndForm = hWnd;

            }
            return true;
        }

...
 EnumWindows(new EnumWindowsProc(EnumTheWindows), IntPtr.Zero);
            SetWindowPos(m_hwndForm.ToInt32(), 0, 10, 20, 600, 800, 0x0040);
            InitializeChromium();

settings.CefCommandLineArgs.Add("Screen-width", "800");
settings.CefCommandLineArgs.Add("Screen-height", "600");

最佳答案

我发现,这可以通过 chrome DevTools 协议(protocol)使用 setDeviceMetrics 实现方法。非常感谢 amaitland!

var client = browser.GetDevToolsClient();
await client.Emulation.SetDeviceMetricsOverrideAsync(1000, 800, 1, true);

在使用此方法之前,您还需要完全初始化 CefSharp 浏览器。

关于c# - cefsharp改变传给网站的参数屏幕的宽高c#,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44459440/

相关文章:

c# - 在单独的表单上更改 NotifyIcon

c# - 为什么 element.click() 在 Cefsharp 中不起作用?

ClickOnce依赖和cefsharp winforms部署

c# - CefSharp.WinForms "Dock =DockStyle.Fill"没有效果,黑边。如何让ChromiumWebBrowser 填充TBForm?

c# - Parallel.For 在这种情况下造成巨大的上下文切换开销......为什么?

c# - 如何在 visual studio 中找到要连接的 informix 数据源

c# - 如何检测是否从 Unity 安装了 Google Play 服务?

带前导零的 C# BitArray

wpf - 如何将 CefSharp 浏览器限制到给定域

c# - CefSharp chromium 浏览器字体问题