Discussion:
How can I handle WebBrowser control events with C++?
(too old to reply)
S***@gmail.com
2006-03-08 12:36:21 UTC
Permalink
I wrappered the WebBrowser control to a Static Lib using C++ and ATL
window:
LIF(AtlAxWinInit());

// Create container window
WinContainer.Create(m_hParentWnd, &rc, L"shell.explorer", WS_CHILD |
WS_VISIBLE);
CComPtr<IUnknown> punkCtrl;
JIF(WinContainer.QueryControl(__uuidof(IWebBrowser2),
(void**)&punkCtrl))

CComPtr<IWebBrowser2> spWebBrowser = punkCtrl;
// omitted ......

The control can be created correctly, but I do not know how to handle
the user events. Anybody helps?
Igor Tandetnik
2006-03-08 13:25:56 UTC
Permalink
Post by S***@gmail.com
I wrappered the WebBrowser control to a Static Lib using C++ and ATL
The control can be created correctly, but I do not know how to handle
the user events. Anybody helps?
See IDispEventImpl and AtlEventHandling sample.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Pomelo
2006-03-10 04:24:48 UTC
Permalink
Greate Thanks! However, it is not an ATL project. The solution must be
a common Win32 Static Library, so I've no idea how to sink those COM
events.
Igor Tandetnik
2006-03-10 13:21:13 UTC
Permalink
Post by Pomelo
Greate Thanks! However, it is not an ATL project.
I distinctly remember seeing AtlAxWinInit, CComPtr and other ATL
features in your original post. Let me check ... yep, here they are.
Post by Pomelo
The solution must be
a common Win32 Static Library, so I've no idea how to sink those COM
events.
You need to implement IDispatch interface, and advise it to the control
via its IConnectionPointContainer and IConnectionPoint interfaces.
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Pomelo
2006-03-10 14:55:08 UTC
Permalink
Post by Igor Tandetnik
I distinctly remember seeing AtlAxWinInit, CComPtr and other ATL
features in your original post. Let me check ... yep, here they are.
Yeah, they are.. :p
Post by Igor Tandetnik
You need to implement IDispatch interface, and advise it to the control
via its IConnectionPointContainer and IConnectionPoint interfaces.
I got it. BTW, do you have some sample code or, any guidance? Thx a lot.
Pomelo
2006-03-14 08:34:56 UTC
Permalink
I did it. thanks.

Now I want to implement interfaces IDocHostUIHandler and IDocHostShowUI
and pass them to the webbrowser control. I studied the article
'WebBrowser Customization' in MSDN, but not well understood. So I turn
to you for help, wishing it not disturbs.
Thanks in advance.
Igor Tandetnik
2006-03-14 13:13:38 UTC
Permalink
Post by Pomelo
Now I want to implement interfaces IDocHostUIHandler and
IDocHostShowUI and pass them to the webbrowser control. I studied the
article 'WebBrowser Customization' in MSDN, but not well understood.
You implement these two interfaces on the client site object - the same
object you implement IOleClientSite on.

Do you or don't you use ATL after all?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Pomelo
2006-03-16 02:33:38 UTC
Permalink
ehhh... I guess I did not make it clear.
I set up a Static Library solution, not an ATL one. To hold the
Webbrowser control, I used some of the ATL classes, such as AxWindow.
And, I did not implement the interfaces other than IDispatch.
Igor Tandetnik
2006-03-16 04:51:01 UTC
Permalink
Post by Pomelo
ehhh... I guess I did not make it clear.
I set up a Static Library solution, not an ATL one. To hold the
Webbrowser control, I used some of the ATL classes, such as AxWindow.
And, I did not implement the interfaces other than IDispatch.
So you are using ATL hosting support. IDocHostUIHandler is easy - you
implement IDocHostUIHandlerDispatch (it's fundamentally the same
interface - why ATL authors decided to create a new interface is beyond
me) and set it with CAxWindow::SetExternalUIHandler.

Implementing IDocHostShowUI is difficult with ATL hosting. For some
options, see

http://groups.google.com/group/microsoft.public.vc.atl/browse_frm/thread/b4f078d6bc7a5c0b/9c0ec49d83637b5b
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Pomelo
2006-03-17 02:08:36 UTC
Permalink
Yeah, that works! I'll try to implement IDocHostShowUI. Great Thanks!
Pomelo
2006-03-23 06:09:06 UTC
Permalink
Well... one more question: how can I capture mouse events that occur on
the browser (Mouse Down)? I looked for help in MSDN, but did not find
any interface that helps...
Igor Tandetnik
2006-03-23 12:50:00 UTC
Permalink
Post by Pomelo
Well... one more question: how can I capture mouse events that occur
on the browser (Mouse Down)? I looked for help in MSDN, but did not
find any interface that helps...
You can sink onmousedown event off the document object. See
HTMLDocumentEvents[2]
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
Continue reading on narkive:
Search results for 'How can I handle WebBrowser control events with C++?' (Questions and Answers)
4
replies
How do you make a program access the internet?
started 2011-01-10 13:30:09 UTC
programming & design
Loading...