GetSystemMetrics(SM_CMONITORS) returns 0 on Render process

Having problems with building or using CEF's C/C++ APIs? This forum is here to help. Please do not post bug reports or feature requests here.

GetSystemMetrics(SM_CMONITORS) returns 0 on Render process

Postby hansJeong » Wed May 12, 2021 2:08 am

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
hansJeong
Newbie
 
Posts: 2
Joined: Wed May 12, 2021 1:40 am

Re: GetSystemMetrics(SM_CMONITORS) returns 0 on Render proce

Postby magreenblatt » Wed May 12, 2021 9:03 am

You will need to send the information from the browser process. See https://bitbucket.org/chromiumembedded/ ... cation-ipc
magreenblatt
Site Admin
 
Posts: 12382
Joined: Fri May 29, 2009 6:57 pm

Re: GetSystemMetrics(SM_CMONITORS) returns 0 on Render proce

Postby hansJeong » Wed May 12, 2021 9:03 pm

I could send the data from BrowserProcess to RenderProcess by OnRenderThreadCreated();

Much appreciated.
hansJeong
Newbie
 
Posts: 2
Joined: Wed May 12, 2021 1:40 am


Return to Support Forum

Who is online

Users browsing this forum: Google [Bot] and 15 guests