簡體   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