关于用CAxWindow的问题(不知道是哪里出错了)!

时间:2023-01-29 14:44:39
在VC.net 2003环境下:
我用CAxWindow生成一个窗口实例,然后用它做容器装载一个控件(IWebBrowser2)控件。具体代码如下:

CAxWindow m_Container;//为一个窗口类成员变量
IWebBrowser2 *pWebBrowser;

m_Container.Create(m_hWnd, CWindow::rcDefault, L"", 0, 0);  
//m_hWnd为一个已存在窗口句柄

m_Container.QueryControl(__uuidof(IWebBrowser2), reinterpret_cast<void**>(&pWebBrowser));

在程序的前头,我加入了环境的初始化:
CoInitialize(NULL);
_Module.Init(NULL, hInstance);
AtlAxWinInit();

甚至还加入了:
#import  "c:\winnt\system32\shdocvw.dll"

但是让我恼火的是,每次获得的pWebBrowser都是0,为此我折腾了一天,查询了相关的解决办法,都没有得到突破。
哪位大侠能帮我找出原因,不胜感激!!!!



12 个解决方案

#1


急切等待中

#2


HRESULT hr=m_Container.QueryControl(...);

你看看hr返回什么值,用Error lookup

#3


返回E_FAIL,用错误查询器查询,为未知的错误定义。

#4


CAxWindow::CreateControl See Also
CAxWindow Overview | Class Members | AtlAxCreateControl
Creates an ActiveX control, initializes it, and hosts it in the specified window.

HRESULT CreateControl(
   LPCOLESTR lpszName,
   IStream* pStream = NULL,
   IUnknown** ppUnkContainer = NULL 
);
HRESULT CreateControl(
   DWORD dwResID,
   IStream* pStream = NULL,
   IUnknown** ppUnkContainer = NULL 
);
Parameters
lpszName 
A pointer to a string to create the control. Must be formatted in one of the following ways: 
A ProgID such as "MSCAL.Calendar.7" 
A CLSID such as "{8E27C92B-1264-101C-8A2F-040224009C02}" 
A URL such as "http://www.microsoft.com" 
A reference to an Active document such as "file://\\Documents\MyDoc.doc" 
A fragment of HTML such as "MSHTML:<HTML><BODY>This is a line of text</BODY></HTML>" 
Note   "MSHTML:" must precede the HTML fragment so that it is designated as being an MSHTML stream.
pStream 
[in] A pointer to a stream that is used to initialize the properties of the control. Can be NULL. 
ppUnkContainer 
[out] The address of a pointer that will receive the IUnknown of the container. Can be NULL. 
dwResID 
The resource ID of an HTML resource. The WebBrowser control will be created and loaded with the specified resource. 
Return Value
A standard HRESULT value.

Remarks
If the second version of this method is used, an HTML control is created and bound to the resource identified by dwResID.

#5


这篇文章我也看过,不过,如何才能找到如下两个参数呢:
A ProgID such as "MSCAL.Calendar.7" 
--对于IWebBrowser2控件,我应该填写什么?

A CLSID such as "{8E27C92B-1264-101C-8A2F-040224009C02}" 
--如何获得IWebBrowser2的CLSID呢

#6


请用GetLastError(),将结果在MSDN中插一下看。

#7


http://www.vchelp.net/itbookreview/view_paper.asp?paper_id=1010

#8


To:Cline(营营) 

我用的是VC.net 2003版本。
无论用{8856F961-340A-11D0-A96B-00C04FD705A2}
还是用Shell.Explorer
甚至用Microsoft.IExplorer.6
都不能用(每次运行,都出现异常)。

但是我调用别的控件的时候,如
ShockwaveFlash.ShockwaveFlash.1
MSCAL.Calendar.7
都可以很好的应用。
不知道是什么原因?

阁下能不能指点我,如何获得控件的GUID或者ProgID,不胜感激!

#9


L""

接口
"guid"

#10


我安装了一个COM Explorer程序,获得了IE控件的ProgID和GUID,可是调用的时候还是系统异常,不知道什么原因。但是,调用别的控件,都不会有问题啊!

#11


怎么还没有人回复啊,呼唤高手!

#12


CComQIPtr<IWebBrowser2> m_spBrowser;
CAxWindow content_wnd;
......
if(  _tcslen(m_tcHtmlFileName) > 0 )
{
RECT rc;
GetClientRect( &rc );
if(m_spBrowser==NULL)
{
LPOLESTR pstrbrowserid;
StringFromCLSID(IID_IWebBrowser2,&pstrbrowserid);
_bstr_t bstrbrowser(pstrbrowserid);
CoTaskMemFree(pstrbrowserid);
if(content_wnd.IsWindow())
content_wnd.DestroyWindow();
content_wnd.Create( m_hWnd, rc, LPCTSTR(bstrbrowser), WS_CHILD&brvbar;WS_VISIBLE&brvbar;WS_HSCROLL&brvbar;WS_VSCROLL );//create a browser control
HRESULT hrbrowser;
hrbrowser = content_wnd.QueryControl( IID_IWebBrowser2, reinterpret_cast<void**>(&m_spBrowser) );
}

#1


急切等待中

#2


HRESULT hr=m_Container.QueryControl(...);

你看看hr返回什么值,用Error lookup

#3


返回E_FAIL,用错误查询器查询,为未知的错误定义。

#4


CAxWindow::CreateControl See Also
CAxWindow Overview | Class Members | AtlAxCreateControl
Creates an ActiveX control, initializes it, and hosts it in the specified window.

HRESULT CreateControl(
   LPCOLESTR lpszName,
   IStream* pStream = NULL,
   IUnknown** ppUnkContainer = NULL 
);
HRESULT CreateControl(
   DWORD dwResID,
   IStream* pStream = NULL,
   IUnknown** ppUnkContainer = NULL 
);
Parameters
lpszName 
A pointer to a string to create the control. Must be formatted in one of the following ways: 
A ProgID such as "MSCAL.Calendar.7" 
A CLSID such as "{8E27C92B-1264-101C-8A2F-040224009C02}" 
A URL such as "http://www.microsoft.com" 
A reference to an Active document such as "file://\\Documents\MyDoc.doc" 
A fragment of HTML such as "MSHTML:<HTML><BODY>This is a line of text</BODY></HTML>" 
Note   "MSHTML:" must precede the HTML fragment so that it is designated as being an MSHTML stream.
pStream 
[in] A pointer to a stream that is used to initialize the properties of the control. Can be NULL. 
ppUnkContainer 
[out] The address of a pointer that will receive the IUnknown of the container. Can be NULL. 
dwResID 
The resource ID of an HTML resource. The WebBrowser control will be created and loaded with the specified resource. 
Return Value
A standard HRESULT value.

Remarks
If the second version of this method is used, an HTML control is created and bound to the resource identified by dwResID.

#5


这篇文章我也看过,不过,如何才能找到如下两个参数呢:
A ProgID such as "MSCAL.Calendar.7" 
--对于IWebBrowser2控件,我应该填写什么?

A CLSID such as "{8E27C92B-1264-101C-8A2F-040224009C02}" 
--如何获得IWebBrowser2的CLSID呢

#6


请用GetLastError(),将结果在MSDN中插一下看。

#7


http://www.vchelp.net/itbookreview/view_paper.asp?paper_id=1010

#8


To:Cline(营营) 

我用的是VC.net 2003版本。
无论用{8856F961-340A-11D0-A96B-00C04FD705A2}
还是用Shell.Explorer
甚至用Microsoft.IExplorer.6
都不能用(每次运行,都出现异常)。

但是我调用别的控件的时候,如
ShockwaveFlash.ShockwaveFlash.1
MSCAL.Calendar.7
都可以很好的应用。
不知道是什么原因?

阁下能不能指点我,如何获得控件的GUID或者ProgID,不胜感激!

#9


L""

接口
"guid"

#10


我安装了一个COM Explorer程序,获得了IE控件的ProgID和GUID,可是调用的时候还是系统异常,不知道什么原因。但是,调用别的控件,都不会有问题啊!

#11


怎么还没有人回复啊,呼唤高手!

#12


CComQIPtr<IWebBrowser2> m_spBrowser;
CAxWindow content_wnd;
......
if(  _tcslen(m_tcHtmlFileName) > 0 )
{
RECT rc;
GetClientRect( &rc );
if(m_spBrowser==NULL)
{
LPOLESTR pstrbrowserid;
StringFromCLSID(IID_IWebBrowser2,&pstrbrowserid);
_bstr_t bstrbrowser(pstrbrowserid);
CoTaskMemFree(pstrbrowserid);
if(content_wnd.IsWindow())
content_wnd.DestroyWindow();
content_wnd.Create( m_hWnd, rc, LPCTSTR(bstrbrowser), WS_CHILD&brvbar;WS_VISIBLE&brvbar;WS_HSCROLL&brvbar;WS_VSCROLL );//create a browser control
HRESULT hrbrowser;
hrbrowser = content_wnd.QueryControl( IID_IWebBrowser2, reinterpret_cast<void**>(&m_spBrowser) );
}