Hi,

I'm also a beginner in gecko embedding. Haven't found any real helpful
examples for MSVC, too. A sample with at least a MSVC 6.0 .dsw/.dsp
file can be found here:
http://mxr.mozilla.org/seamonkey/source/embedding/qa/testembed/
but to be honest, I couldn't load this into MSVC 6.0.

I messed around with the SDK ( http://developer.mozilla.org/en/Gecko_SDK
) and the ActiveX control but I haven't found a way to do what I
wanted to do with them. I need access to custom plugin-interfaces and
this seems only possible by building the whole Mozilla stuff by
myself.

Build Instructions can be found here: 
http://developer.mozilla.org/en/Build_Documentation

I have managed now to build seamonkey 1.1.17(
http://mirrors.xmission.com/mozilla.org/seamonkey/releases/1.1.17/ ) .
It is based on gecko 1.8.1 and I need this gecko version because it is
the last one which supports MSVC 6.0. Unfortunately I'm stuck to MSVC
6.0 because my embedding application needs it.

The build gave me a "dist/include" and a "dist/lib" directory
containing all the include files and libs needed for embedding.

Next step was to follow this instructions to set up gecko in my
application: 
http://developer.mozilla.org/en/Gecko_Embedding_Basics#Common_Embedding_Tasks
. Well it's a bit confusing and you need the class CBrowserImpl which
implements all the "callback" interfaces for gecko. I took
CBrowserImpl from one of the examples (sorry, forgot which one) and
modified it until it fitted into my project.

The init and setup stuff is done in a single function in my code which
is called after my app is up and running and the window for displaying
gecko is created.

Here is my code for setting up gecko and displaying a html file. Maybe
it gives you some hints:

-------------------------------------------------------------------------------------------------------------------------------------
        // gecko setup (https://developer.mozilla.org/en/
Gecko_Embedding_Basics#Gecko_setup)

        // init
        nsresult rv = NS_InitEmbedding(nsnull, nsnull);

        // create an instance of the Mozilla embeddable browser
        nsCOMPtr<nsIWebBrowser> cpWebBrowser = do_CreateInstance
(NS_WEBBROWSER_CONTRACTID, &rv);

        // Create the CBrowserImpl object - this is the object
        // which implements the interfaces which are required
        // by an app embedding mozilla i.e. these are the interfaces
        // thru' which the *embedded* browser communicates with the
        // *embedding* app
        //
        // The CBrowserImpl object will be passed in to the
        // SetContainerWindow() call below
        CBrowserImpl* pBrowserImpl = new CBrowserImpl();
        pBrowserImpl->SetWebBrowser(cpWebBrowser );
        pBrowserImpl->AddRef();
        cpWebBrowser ->SetContainerWindow(NS_STATIC_CAST
(nsIWebBrowserChrome*, pBrowserImpl));

        nsCOMPtr<nsIWebBrowserSetup>setup(do_QueryInterface(cpWebBrowser));
        if (setup)
        {
                setup->SetProperty
(nsIWebBrowserSetup::SETUP_ALLOW_PLUGINS,PR_TRUE);
        }

        // binding the browser window
        HWND hWnd = (...pointer to embedding CWnd object...)->GetSafeHwnd();
        if(hWnd)
        {
                RECT rcLocation;
                pWnd->GetClientRect(&rcLocation);
                nsCOMPtr<nsIBaseWindow> cpBaseWindow = do_QueryInterface
(cpWebBrowser, &rv);
                rv = cpBaseWindow->InitWindow(nsNativeWidget(hWnd),
                                nsnull,0, 0, rcLocation.right - rcLocation.left,
                                rcLocation.bottom - rcLocation.top);
                rv = cpBaseWindow->Create();

               // Finally, show the web browser window
              cpBaseWindow->SetVisibility(PR_TRUE);
        }

        // The BrowserImpl object is added as an nsIWebProgressListener. It
will now
        // receive progress messages. These callbacks will be used to update
the status/progress bars.
        nsWeakPtr weakling
        (dont_AddRef(NS_GetWeakReference(NS_STATIC_CAST
(nsIWebProgressListener*, pBrowserImpl))));
        cpWebBrowser->AddWebBrowserListener(weakling, NS_GET_IID
(nsIWebProgressListener));

        // get pointer to the nsIWebNavigation interface
        nsCOMPtr<nsIWebNavigation> cpWebNav = do_QueryInterface(cpWebBrowser,
&rv);

        // load uri
        rv = cpWebNav->LoadURI(NS_ConvertASCIItoUTF16("file:///C:/
MediaControl/ledbutton.html").get(),
                                              
nsIWebNavigation::LOAD_FLAGS_NONE, nsnull, nsnull, nsnull);
-------------------------------------------------------------------------------------------------------------------------------------

Needed to include lots of mozilla .h files and set include paths in my
project until it compiled. After compiling it comes to linking. This
page explains linking: http://developer.mozilla.org/en/XPCOM_Glue.

Well, I finally have gecko embedded into my application this way and
it shows me html pages. But im still struggling with the plugin
interfaces i wanted to access. Just wrote down some of my experiences
here. Maybe its helpfull for someone...


regards,
Rainer




_______________________________________________
dev-embedding mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-embedding

Reply via email to