主题:VB调用VC写的ACTIVEX控件遇到的问题
VB代码如下:
Private c As HttpWatch.Controller //用了HttpWatch的引用
Private p As HttpWatch.Plugin
Private Sub Command1_Click()
Dim wb As SHDocVw.WebBrowser
Dim html As MSHTML.HTMLDocument
Dim h2 As MSHTML.IHTMLDocument2
Set c = New HttpWatch.Controller
Set p = c.New
Set wb = p.Container //p.Container是一个浏览器对象
p.GotoURL "http://www.baidu.com"
Do While p.IsLoadingPage
DoEvents
Loop
Set html = wb.document //HTMLDocument对象
Set h2 = html //IHTMLDocument2对象
Call Capic1.CatchMyPic(h2, "c:\\test.bmp") //Capic是我写的一OCX控件,CatchMyPic是OCX控件的一方法
End Sub
Capic控件是用VC写的,很简单,就只用一个函数,简要代码如下:
void CCapicCtrl::CatchMyPic(LPDISPATCH doc, LPCTSTR path)
{
IHTMLDocument2 *pDoc=(IHTMLDocument2 *)doc;
IViewObject2* pView=NULL;
hr=pDoc->QueryInterface(IID_IViewObject2,(void **)&pView);
if(hr!=S_OK){
MessageBox("query IViewObject fail!");return;
}
//下面这句代码vc画成功,vb失败
hr=pView->Draw(DVASPECT_CONTENT,1,NULL,NULL,hScreenDC,hmap,&rt,NULL,NULL,0);
if(hr!=S_OK){
MessageBox("draw fail!");return;
}
}
不知道为什么,我用VC调用这个控件函数CatchMyPic就可以成功画出图,而用VB调用这个控件函数时,pView->Draw这句话总是失败,同样的控件,为什么在VC和VB中调用出两种结果?望高人来指点一下,谢谢!
Private c As HttpWatch.Controller //用了HttpWatch的引用
Private p As HttpWatch.Plugin
Private Sub Command1_Click()
Dim wb As SHDocVw.WebBrowser
Dim html As MSHTML.HTMLDocument
Dim h2 As MSHTML.IHTMLDocument2
Set c = New HttpWatch.Controller
Set p = c.New
Set wb = p.Container //p.Container是一个浏览器对象
p.GotoURL "http://www.baidu.com"
Do While p.IsLoadingPage
DoEvents
Loop
Set html = wb.document //HTMLDocument对象
Set h2 = html //IHTMLDocument2对象
Call Capic1.CatchMyPic(h2, "c:\\test.bmp") //Capic是我写的一OCX控件,CatchMyPic是OCX控件的一方法
End Sub
Capic控件是用VC写的,很简单,就只用一个函数,简要代码如下:
void CCapicCtrl::CatchMyPic(LPDISPATCH doc, LPCTSTR path)
{
IHTMLDocument2 *pDoc=(IHTMLDocument2 *)doc;
IViewObject2* pView=NULL;
hr=pDoc->QueryInterface(IID_IViewObject2,(void **)&pView);
if(hr!=S_OK){
MessageBox("query IViewObject fail!");return;
}
//下面这句代码vc画成功,vb失败
hr=pView->Draw(DVASPECT_CONTENT,1,NULL,NULL,hScreenDC,hmap,&rt,NULL,NULL,0);
if(hr!=S_OK){
MessageBox("draw fail!");return;
}
}
不知道为什么,我用VC调用这个控件函数CatchMyPic就可以成功画出图,而用VB调用这个控件函数时,pView->Draw这句话总是失败,同样的控件,为什么在VC和VB中调用出两种结果?望高人来指点一下,谢谢!