Page 1 of 1

GetSystemMetrics(SM_CMONITORS) returns 0 on Render process

PostPosted: Wed May 12, 2021 2:08 am
by hansJeong
Hi Everybody.

I'm developing the application on dual screen monitors environment. normally I use GetSystemMetrics(SM_CMONITORS) Windows API to get it. but when I use SANDBOX, it returns 0. it's no problem if not use SANDBOX.
is there any idea to get correct monitor count?

Code: Select all
class AdkExtensionHandler : public CefV8Handler{
   public:
      explicit AdkExtensionHandler(CefRefPtr<client::ClientAppRenderer> client_app)
         : client_app_(client_app)
         , messageId(0){
      }

      virtual bool Execute(const CefString& name,
         CefRefPtr<CefV8Value> object,
         const CefV8ValueList& arguments,
         CefRefPtr<CefV8Value>& retval,
         CefString& exception) {

         if (name == "getMonitorCount") {
            int monitorCount = GetSystemMetrics(SM_CMONITORS);
            retval = CefV8Value::CreateInt(monitorCount);

            return true;
         }
      }

   private:
      CefRefPtr<client::ClientAppRenderer> client_app_;
      int32 messageId;

      IMPLEMENT_REFCOUNTING(AdkExtensionHandler);
   };



Code: Select all
void ClientAppRenderer::OnWebKitInitialized() {
  DelegateSet::iterator it = delegates_.begin();
  for (; it != delegates_.end(); ++it)
    (*it)->OnWebKitInitialized(this);
   
// Define the extension contents.
     std::string strExtensionCode =
     "var adk;"
     "if (!adk)"
     "  adk = {};"
     "(function() {"
     "  adk.getMonitorCount = function() {"
     "    native function getMonitorCount();"
     "    return getMonitorCount();"
     "  };"
    "})();";

   // Register the extension.
   CefRefPtr<CefV8Handler> handler = new AdkExtensionHandler(this);
   CefRegisterExtension("adk", strExtensionCode, handler);
  }


CEF version : cef_84.4.0+g304e015+chromium-84.0.4147.105
Windows version
- Edition : Windows 10 Pro
- Version : 2004
- OS build : 19041.928

thanks

Re: GetSystemMetrics(SM_CMONITORS) returns 0 on Render proce

PostPosted: Wed May 12, 2021 9:03 am
by magreenblatt
You will need to send the information from the browser process. See https://bitbucket.org/chromiumembedded/ ... cation-ipc

Re: GetSystemMetrics(SM_CMONITORS) returns 0 on Render proce

PostPosted: Wed May 12, 2021 9:03 pm
by hansJeong
I could send the data from BrowserProcess to RenderProcess by OnRenderThreadCreated();

Much appreciated.