get Hwnd of child window ?

1,168 views
Skip to first unread message

Nicola Fagan

unread,
Oct 16, 2014, 7:00:57 AM10/16/14
to cefs...@googlegroups.com
Hi,
I try to intercept the handle of a child window that open from a jscript.

For example: i insert a windows.open(.....), cefbrowser open a new window that is ok.
If a want to use handle of this child, for example to hide the "X" for close or other operation .....

I find on ClientAdapter.cpp the handle of main browser, but i have not idea to intercept the new window that open with windows.open  .

I attach spy result.

Help Me. :)

Thank you. :)

Nicola 


Cattura.PNG

Czarek Tomczak

unread,
Oct 16, 2014, 7:12:54 AM10/16/14
to cefs...@googlegroups.com
See ILifespanHandler::OnBeforePopup.

--
You received this message because you are subscribed to the Google Groups "CefSharp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cefsharp+u...@googlegroups.com.
To post to this group, send email to cefs...@googlegroups.com.
Visit this group at http://groups.google.com/group/cefsharp.
For more options, visit https://groups.google.com/d/optout.

Nicola Fagan

unread,
Oct 16, 2014, 8:41:59 AM10/16/14
to cefs...@googlegroups.com
Thank you Czarek :) :)

--
You received this message because you are subscribed to a topic in the Google Groups "CefSharp" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/cefsharp/9i61z3sITzs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to cefsharp+u...@googlegroups.com.

Nicola Fagan

unread,
Oct 16, 2014, 10:04:19 AM10/16/14
to cefs...@googlegroups.com
I see it's perfect :) ... i see on cef3 api CefLifeSpanHandler.

On cefsharp.core ClientAdapter class on onbeforepopup, i see 

bool ClientAdapter::OnBeforePopup(...)
{
     ILifeSpanHandler^ handler = _browserControl->LifeSpanHandler;

--> how convert this handler HWND  with  WindowInteropHelper but i can't how :(

i think that is similar for example

IntPtr winhandle = ?????? handler 

void * winhandleptr = winhandle.ToPointer();
HWND hWnd = static_cast<HWND>(winhandleptr);
//for example ....
SetWindowLong(hWnd, GWL_STYLE, GetWindowLong(hWnd, GWL_STYLE) & ~WS_SYSMENU);
:)

Czarek Tomczak

unread,
Oct 16, 2014, 10:17:00 AM10/16/14
to cefs...@googlegroups.com
In OnBeforePopup return true to cancel popup creation by CEF. Create a popup window on your own and embed browser in it.

You received this message because you are subscribed to the Google Groups "CefSharp" group.
To unsubscribe from this group and stop receiving emails from it, send an email to cefsharp+u...@googlegroups.com.

Czarek Tomczak

unread,
Oct 16, 2014, 10:23:20 AM10/16/14
to cefs...@googlegroups.com
There is also OnAfterCreated callback that occurs after popup browser is created:
https://github.com/cefsharp/CefSharp/blob/12f9c297e859948f307b7daceba9577c448c69f6/CefSharp.Core/Internals/ClientAdapter.cpp#L38
But I don't see any interface exposed for that callback.

Nicola Fagan

unread,
Oct 16, 2014, 10:27:38 AM10/16/14
to cefs...@googlegroups.com
Hi, thanks for your answer. Regarding opening a new browser with a custom function, i' m not sure on how to get a reference to the window on the caller javascript context. 
I mean,  window.open will return the window instance of the newly created window and the created window will have a reference of the opener (window.opener). Is it possible to have the same behaviour with a custom function?
Thanks in advance

Czarek Tomczak

unread,
Oct 16, 2014, 10:34:21 AM10/16/14
to cefs...@googlegroups.com
You would probably need to call CefWindowInfo.SetAsPopup:
But again, I don't see this API being exposed.

Nicola Fagan

unread,
Oct 20, 2014, 7:20:32 AM10/20/14
to cefs...@googlegroups.com
Hi Czarek.
I try to get the Popup Handler for modify window style, but never....

1)  bool ClientAdapter::OnBeforePopup is before, the handler is null ...
2) i try to get Handler from void ClientAdapter::OnAfterCreated(CefRefPtr<CefBrowser> browser)
but browser->GetHost()->GetWindowHandle() is the handler of the browser not of popup ....

i try:

HWND abc = browser->GetHost()->GetWindowHandle(); <------------------------ i want handler of popup window.,

long style = GetWindowLong(abc, GWL_EXSTYLE);
style |= WS_OVERLAPPEDWINDOW;
style |= WS_CLIPCHILDREN;
style |= WS_CLIPSIBLINGS;
style |= WS_VISIBLE;

SetWindowLong(abc,GWL_EXSTYLE, style);




style = GetWindowLong(abc, GWL_EXSTYLE);
style &= WS_BORDER;

SetWindowLong(abc, GWL_EXSTYLE, style);

:)

Kaido Kärner

unread,
Oct 22, 2014, 9:00:37 AM10/22/14
to cefs...@googlegroups.com
>> I try to get the Popup Handler for modify window style, but never....

>> 1)  bool ClientAdapter::OnBeforePopup is before, the handler is null ...
>> 2) i try to get Handler from void ClientAdapter::OnAfterCreated(CefRefPtr<CefBrowser> browser)
>> but browser->GetHost()->GetWindowHandle() is the handler of the browser not of popup ....

You mean 'handle', right? ;)

In the OnBeforePopup callback, the popup, and thus the window handle for it are created yet. You can create your own window, get handle and give this handle in the OnPopup callback, then the browser is created as child of your window. 
This is almost the only way to have some control over how the popup window looks.

The right way to handle the popups, is to create your own C#/WinForms form for the popup, create the ChromiumBrowser in it as usual, and set handle AND give the CefClient interface of this ChromiumBrowser control in the OnPopup, Unfortunately there are some slight modifications needed for this to work in the ChromiumBrowser (not to call CreateBrowser() if we know this will be a window for popup, and get its CefClient interface to the OnPopup handler of the creating window) .. 

This way You can open the popup the standard way with window.open() in javascript, and have full control over the window, browser, events, etcetc .. 

I hacked it together and it seems to be working. The hardest part for me was to get the CefClient interface through the OnPopup handler ..I really hope someone with proper knowledge of the Cef will do it properly one day .. 

kaido

Kaido Kärner

unread,
Oct 22, 2014, 9:01:25 AM10/22/14
to cefs...@googlegroups.com
>> and thus the window handle for it are created yet

should read: 

and thus the window handle for it are NOT created yet

Nicola Fagan

unread,
Oct 22, 2014, 12:36:45 PM10/22/14
to cefs...@googlegroups.com
Hi resolve a problem but not is clean ...


1)
on OnBeforePopup i insert ...

            if (handler == nullptr)
                return false;
else
windowInfo.SetAsPopup(browser->GetHost()->GetWindowHandle(), "Test");    <---- set name of popup ...... ma be pass with evalutatejavascript 

2) 
on void ClientAdapter::OnAfterCreated(CefRefPtr<CefBrowser> browser)

            if (!browser->IsPopup())
            {
....
} else
{
_pWin = ::FindWindow(NULL, L"Test"); <---- retrive handler

SetWindowLongPtr(_pWin, GWL_STYLE, WS_POPUP | WS_VISIBLE | WS_SYSMENU);    <----------------- set my style
InvalidateRect(_pWin, NULL, TRUE);
UpdateWindow(_pWin);
}

on ClientAdapter.h create a global HWND

what we think ? :)

--
330.gif
Reply all
Reply to author
Forward
0 new messages