繁体   English   中英

Cefsharp更改传递给站点的参数屏幕的宽度和高度c#

[英]Cefsharp change the parameter passed to the site the width and height of the screen c#

你能帮忙吗,如何改变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");

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM