On Windows platform, We are using onBeforePopup() to set our own main application window as the owner window of pop up
First get the "chromeWindow/HostWindow" from the browser instance as follow (this browser instance represent the browser from which window.open() request initiated)
- Code: Select all
HWND chromeTabWindow = browser->GetHost()->GetWindowHandle();
In our case, we are also setting one parent window in which chrome window gets rendered so we also need to get its instance too but in your case, it could be your main application window.
- Code: Select all
HWND myParentWindow = GetParent(chromeTabWindow);
Now, get the Main Application window as follow
- Code: Select all
HWND myOwnerWindow = ::GetWindow(myParentWindow, GW_OWNER);
Now, pass owner window instance in SetAsPopup() method
- Code: Select all
windowInfo.SetAsPopup(myOwnerWindow, target_frame_name);
Then we have some window position logic you can ignore it or change it as per your needs
- Code: Select all
RECT rect = { 0,0,600,600 };
if (GetWindowRect(myOwnerWindow, &rect)) {
windowInfo.x = abs(abs(rect.right - rect.left) - (popupFeatures.width)) / 2 ;
windowInfo.y = abs(abs(rect.bottom - rect.top) - (popupFeatures.height)) / 2;
}
if (popupFeatures.height > 0) {
windowInfo.height = popupFeatures.height;
}
if (popupFeatures.width > 0) {
windowInfo.width = popupFeatures.width;
}
if (popupFeatures.x > 0) {
windowInfo.x = popupFeatures.x;
}
if (popupFeatures.y > 0) {
windowInfo.y = popupFeatures.y;
}
Now you need to disable the Main application window to make your pop up dialog as modal window(i.e no other window should get focus)
- Code: Select all
EnableWindow(myOwnerWindow, FALSE);
Now, In "
OnBeforeClose()" you need to enable your main application window if pop gets closed
- Code: Select all
CefWindowHandle chromeTabWindow = browser->GetHost()->GetWindowHandle();
CefWindowHandle ownerWinHandle = GetParentWindow(chromeTabWindow);
if (browser->IsPopup()) {
EnableWindow(ownerWinHandle, TRUE);
SetForegroundWindow(ownerWinHandle);
}