| David T 2005-12-05, 8:10 am |
| Hi all,
Does somebody know how to get the IWebBrowser2 interface from the HTML
Control ? Because i tried many things, but it's was without seccess.
In the code below, my problem is that pWebBrowser2 is always NULL. However,
I need this interface to modify the properties of the Browser.
I hope that somebody can help me for that.
Thanks.
David
//-----------------------------------------------------------------------
#include <htmlctrl.h>
#include <piedocvw.h>
[...]
BOOL CreateHTMLControlWindow(HWND hParentWnd)
{
if( !InitHTMLControl(g_hInst))
{
//InitHTMLControl failed.
MessageBox(hParentWnd, _T("Can't InitHTMLControl."), _T("Warning"),
MB_OK);
return FALSE;
}
RECT l_clientRect;
GetClientRect(hParentWnd, &l_clientRect);
// Create the control.
m_hwndHTML = CreateWindow( WC_HTML, NULL,
WS_CHILD |
WS_VISIBLE | WS_CLIPSIBLINGS /*| WS_BORDER*/
| HS_CONTEXTMENU |
HS_NOSELECTION | HS_CLEARTYPE | HS_INTEGRALPAGING,
0, 0,
l_clientRect.right , l_clientRect.bottom,
hParentWnd,
NULL, g_hInst, NULL);
if (m_hwndHTML == NULL)
{
// CreateWindow failed.
MessageBox(hParentWnd, _T("Can't create window WC_HTML."),
_T("Warning"), MB_OK);
return FALSE;
}
SendMessage(m_hwndHTML, DTM_CLEAR, 0, 0);
SendMessage(m_hwndHTML, DTM_ADDTEXTW, FALSE,
(LPARAM)L"<HTML><HEADER>Simple APP</HEADER><BODY>Hello
world</BODY></HTML>");
SendMessage(m_hwndHTML, DTM_ENDOFSOURCE, 0, 0);
IWebBrowser2 *pWebBrowser2= NULL;
DWebBrowserEvents2 * pDWebBrowserEvents=NULL;
SendMessage(m_hwndHTML, DTM_BROWSERDISPATCH, 0, (LPARAM)
&pDWebBrowserEvents);
if( pDWebBrowserEvents == NULL){
MessageBox(NULL, _T("pDWebBrowserEvents==NULL"),
_T("CreateHTMLControlWindow"), MB_OK);
return FALSE;
}
pDWebBrowserEvents->QueryInterface(IID_IWebBrowser2,
(void**)&pWebBrowser2);
if( pWebBrowser2 == NULL ){
MessageBox(NULL, _T("pWebBrowser2==NULL"),
_T("CreateHTMLControlWindow"), MB_OK);
return FALSE;
}
[....]
}
//-------------------------------------------------------------------------------------------------------
|