简体   繁体   中英

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

can you help, how you can change the screen size, which cefsharp transmits ? I go to ipleak.net and saw Your screen: 1920 x 1080 Available screen: 1920 x 1040

Is there any way to change it ?

I tried that, but it didnt work

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();

or

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

I've found, that's possible through chrome DevTools protocol using setDeviceMetrics method. Many thanks to amaitland!

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

You also need to fully initialize CefSharp browser before use this method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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