tags:

views:

19

answers:

2

Hi, I have an app written in C++ using Visual Studio 2010 to run on Windows (version XP upwards) as an .EXE. It uses plain Win32 for the existing UI.

I also have some content based on web browser formats, HTML/CSS/JavaScript. I would like to have this content displayed in the application window, in the same way that WebView works on Android and UIWebView works on iPhone. The web content should be able to communicate with the surrounding native application using calls to custom JavaScript methods.

I am aware of the WebKit project. However, looking at the binaries available for download it appears to be presented as a stand-alone application, rather than a library that can be linked against a C++ app to allow browser content to displayed.

Can anyone suggest a good way of doing this?

+1  A: 

You could try to include the Internet Explorer as a COM component in your application. This is explained on http://msdn.microsoft.com/en-us/library/aa752046(VS.85).aspx.

You could also use the QtWeb library (see http://www.qtweb.net/).

Patrick
+1  A: 

If you're using MFC, Patrick's answer is correct.

If you're not using MFC, you can embed Internet Explorer using "ATL control containment" - see How to add ATL control containment support to any window in Visual C++.

It boils down to linking with the right libraries and then using this one-liner:

// Creates the Web Browser control and navigates to the 
// specified web page.
HWND hWnd = ::CreateWindow("AtlAxWin", "http://www.microsoft.com", 
                           WS_CHILD|WS_VISIBLE, 10, 10, 500, 300, hParent, NULL,
                           ::GetModuleHandle(NULL), NULL);

Getting your JavaScript to call functions in your C++ application is a bit of a fiddle - you need to create an object that implements IDispatch, then pass that to the Advise method of the IE control's IConnectionPoint interface, which you obtain via IConnectionPointContainer::FindConnectionPoint. Your JavaScript then calls window.external.my_func(...) which becomes a call to the Invoke method of your IDispatch-implementing object.

RichieHindle
Thanks a lot Richie. I am not using MFC by the way, just plain Win32.
Jim Blackler