📄 fixedhtmlview.cpp
字号:
IWebBrowser2* lpWB = NULL;
try
{
// COleSafeArray vPostData;
/* if (lpvPostData != NULL)
{
if (dwPostDataLen == 0)
dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);
vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
}*/
COleVariant vURL(lpszURL, VT_BSTR);
COleVariant vHeaders(lpszHeaders, VT_BSTR);
COleVariant vTargetFrameName(lpszTargetFrameName, VT_BSTR);
COleVariant vFlags((long) dwFlags, VT_I4);
lpDisp = m_wndBrowser.GetApplication();
if(lpDisp!=NULL)
{
//2.2
if(SUCCEEDED(lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&lpWB)))
lpWB->Navigate2(vURL,
vFlags, vTargetFrameName, vPostData, vHeaders);
// lpDisp->Release();
// lpDisp = NULL;
}
}
/* catch(CMemoryException* e)
{
if(e!=NULL)e->Delete();
}*/
catch(...)
{
}
try{
if(lpWB!=NULL)
lpWB->Release();
if(lpDisp!=NULL)
lpDisp->Release();
}
catch(...)
{
}
}
/*
void CFixedHtmlView::PutProperty(LPCTSTR lpszProperty, const VARIANT& vtValue)
{
m_wndBrowser.PutProperty(lpszProperty, vtValue);
}
BOOL CFixedHtmlView::GetProperty(LPCTSTR lpszProperty, CString& strValue)
{
BOOL bResult = FALSE;
VARIANT vReturn;
vReturn.vt = VT_BSTR;
vReturn.bstrVal = NULL;
vReturn = m_wndBrowser.GetProperty_(lpszProperty);
strValue = CString(vReturn.bstrVal);
bResult = TRUE;
return bResult;
}
COleVariant CFixedHtmlView::GetProperty(LPCTSTR lpszProperty)
{
COleVariant result;
VARIANT vReturn;
vReturn.vt = VT_BSTR;
vReturn.bstrVal = NULL;
vReturn = m_wndBrowser.GetProperty_(lpszProperty);
result = vReturn;
return result;
}
CString CFixedHtmlView::GetFullName()
{
return m_wndBrowser.GetFullName();
}
*/
void CFixedHtmlView::GoHome()
{
LPDISPATCH lpDisp = NULL;
IWebBrowser2* lpWB = NULL;
try{
lpDisp = m_wndBrowser.GetApplication();
if(lpDisp != NULL)
{
//2.2
if(SUCCEEDED(lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&lpWB)))
lpWB->GoHome();
//lpDisp->Release();
}
}catch(...)
{
}
try{
if(lpWB!=NULL)
lpWB->Release();
if(lpDisp!=NULL)
lpDisp->Release();
}catch(...)
{
}
}
void CFixedHtmlView::Stop()
{
LPDISPATCH lpDisp = NULL;
IWebBrowser2* lpWB = NULL;
try{
lpDisp = m_wndBrowser.GetApplication();
if(lpDisp != NULL)
{
//2.2
if(SUCCEEDED(lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&lpWB)))
lpWB->Stop();
//lpDisp->Release();
}
}catch(...)
{
}
try{
if(lpWB!=NULL)
lpWB->Release();
if(lpDisp!=NULL)
lpDisp->Release();
}catch(...)
{
}
}
void CFixedHtmlView::GoBack(int dist)
{
LPDISPATCH lpDisp = NULL;
IWebBrowser2* lpWB = NULL;
lpDisp = m_wndBrowser.GetApplication();
if(lpDisp != NULL)
{
//2.2
if(SUCCEEDED(lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&lpWB)))
{
for(int i=0; i<dist; i++)
lpWB->GoBack();
m_nBackSteps = dist;
}
//lpDisp->Release();
}
try{
if(lpWB!=NULL)
lpWB->Release();
if(lpDisp!=NULL)
lpDisp->Release();
}catch(...)
{
}
}
void CFixedHtmlView::GoForward(int dist)
{
LPDISPATCH lpDisp = NULL;
IWebBrowser2* lpWB = NULL;
lpDisp = m_wndBrowser.GetApplication();
if(lpDisp != NULL)
{
//2.2
if(SUCCEEDED(lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&lpWB)))
{
for(int i=0; i<dist; i++)
lpWB->GoForward();
m_nBackSteps = -dist;
}
//lpDisp->Release();
}
try{
if(lpWB!=NULL)
lpWB->Release();
if(lpDisp!=NULL)
lpDisp->Release();
}catch(...)
{
}
}
/*void CFixedHtmlView::GoSearch()
{
m_wndBrowser.GoSearch();
}*/
void CFixedHtmlView::Refresh()
{
LPDISPATCH lpDisp = NULL;
IWebBrowser2* lpWB = NULL;
try{
lpDisp = m_wndBrowser.GetApplication();
if(lpDisp != NULL)
{
//2.2
if(SUCCEEDED(lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&lpWB)))
lpWB->Refresh();
//lpDisp->Release();
//3.0
m_nProgress = 0;
}
}catch(...)
{
}
try{
if(lpWB!=NULL)
lpWB->Release();
if(lpDisp!=NULL)
lpDisp->Release();
}catch(...)
{
}
}
void CFixedHtmlView::Refresh2(int nLevel)
{
LPDISPATCH lpDisp = NULL;
IWebBrowser2* lpWB = NULL;
try{
lpDisp = m_wndBrowser.GetApplication();
if(lpDisp != NULL)
{
//2.2
if(SUCCEEDED(lpDisp->QueryInterface(IID_IWebBrowser2, (void**)&lpWB)))
lpWB->Refresh2(COleVariant((long) nLevel, VT_I4));
//lpDisp->Release();
//3.0
m_nProgress = 0;
}
}catch(...)
{
}
try{
if(lpWB!=NULL)
lpWB->Release();
if(lpDisp!=NULL)
lpDisp->Release();
}catch(...)
{
}
}
/////////////////////////////////////////////////////////////////////////////
// CFixedHtmlView event reflectors
void CFixedHtmlView::NavigateComplete2(LPDISPATCH pDisp , VARIANT* URL)
{
ASSERT(V_VT(URL) == VT_BSTR);
try
{
//2.5 add for sina ads
m_bLClick = FALSE;
m_bRClick = FALSE;
USES_CONVERSION;
strURL = OLE2T(V_BSTR(URL));
//successfully set history,
//this can get the real url of this navigation
//but not fit for history list, because the back and forward doesn't
//get the same url as navigation
// if(!IsIFrame(pDisp ,str))
SetHistory(strURL);
m_strLastURL = strURL;
if (!glpDisp)
{
glpDisp = pDisp;
}
//316
if(m_bForceResize)
{
CRect rect;
GetWindowRect(&rect);
PostMessage(WM_SIZE, 0, ((rect.Height())<<16)+rect.Width());
m_bForceResize = FALSE;
}
OnNavigateComplete2(strURL);
}
catch(...)
{
}
}
void CFixedHtmlView::BeforeNavigate2(LPDISPATCH pDisp , VARIANT* URL,
VARIANT* Flags, VARIANT* TargetFrameName,
VARIANT* PostData, VARIANT* Headers, BOOL* Cancel)
{
ASSERT(V_VT(URL) == VT_BSTR);
ASSERT(V_VT(TargetFrameName) == VT_BSTR);
ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF));
ASSERT(V_VT(Headers) == VT_BSTR);
ASSERT(Cancel != NULL);
try
{
USES_CONVERSION;
strURL = V_BSTR(URL);
//2.5 for download tools, share one instance between windows. let's test, if it
//can work properly, we can create separate instance for each window. But this may
//increase the cost of memory.
if(m_bIniDL)
{
if(((CMainFrame*)pMainFrame)->pDownload!=NULL && (strURL.Find('?')<0 || strURL.Find(".jsp?")>0))
{
try{
if(IsDownloadable(strURL))
{
IObjectWithSite* pSite = NULL;
((CMainFrame*)pMainFrame)->pDownload->QueryInterface(IID_IObjectWithSite, (void**)&pSite);
if(pSite!=NULL)
{
pSite->SetSite(GetApplication());
pSite->Release();
m_bIniDL = FALSE;
}
/* // VARIANT VarResult;
// EXCEPINFO ExcepInfo;
// unsigned int uArgErr=0;
DISPPARAMS dispparams;
dispparams.rgvarg = new VARIANT[7];
// The parameters for this DISPID are as follows:
// [0]: Cancel flag - VT_BYREF|VT_BOOL
// [1]: HTTP headers - VT_BYREF|VT_VARIANT
// [2]: Address of HTTP POST data - VT_BYREF|VT_VARIANT
// [3]: Target frame name - VT_BYREF|VT_VARIANT
// [4]: Option flags - VT_BYREF|VT_VARIANT
// [5]: URL to navigate to - VT_BYREF|VT_VARIANT
// [6]: An object that evaluates to the top-level or frame
// WebBrowser object corresponding to the event
//
VARIANT_BOOL cancel=VARIANT_FALSE;
dispparams.rgvarg[0].vt = VT_BYREF|VT_BOOL;
dispparams.rgvarg[0].pboolVal = &cancel;
dispparams.rgvarg[1].vt = VT_BYREF|VT_VARIANT;
dispparams.rgvarg[1].pvarVal = Headers;
dispparams.rgvarg[2].vt = VT_BYREF|VT_VARIANT;
dispparams.rgvarg[2].pvarVal = PostData;
dispparams.rgvarg[3].vt = VT_BYREF|VT_VARIANT;
dispparams.rgvarg[3].pvarVal = TargetFrameName;
dispparams.rgvarg[4].vt = VT_BYREF|VT_VARIANT;
dispparams.rgvarg[4].pvarVal = Flags;
dispparams.rgvarg[5].vt = VT_BYREF|VT_VARIANT;
dispparams.rgvarg[5].pvarVal = URL;
dispparams.rgvarg[6].vt = VT_DISPATCH;
dispparams.rgvarg[6].pdispVal = pDisp;
dispparams.cArgs = 7;
dispparams.cNamedArgs = 0;
HRESULT hr = ((CMainFrame*)pMainFrame)->pDownload->Invoke(250, IID_NULL,
LOCALE_USER_DEFAULT, DISPATCH_METHOD, &dispparams, NULL, NULL, NULL);
delete[] dispparams.rgvarg;*/
/* CStdioFile f;
f.Open("d:\\tmp.txt", CFile::modeCreate|CFile::modeNoTruncate|CFile::modeWrite);
f.SeekToEnd();
f.WriteString(strURL);
f.WriteString("\r\n");
f.Close(); */
/* if(cancel==VARIANT_TRUE)
{
*Cancel=TRUE;
return;
}
else //2.5 377 a test
return;*/
}
}catch(...)
{
}
}
}
//end 2.5
VARIANT* vtPostedData = V_VARIANTREF(PostData);
//CByteArray array;
BOOL array = FALSE;
if (V_VT(vtPostedData) & VT_ARRAY)
{
// must be a vector of bytes
ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1);
vtPostedData->vt |= VT_UI1;
COleSafeArray safe(vtPostedData);
DWORD dwSize = safe.GetOneDimSize();
//LPVOID pVoid;
//safe.AccessData(&pVoid);
//array.SetSize(dwSize>0?1:0);
array = dwSize>0?TRUE:FALSE; //2.5
//LPBYTE lpByte = array.GetData();
//memcpy(lpByte, pVoid, dwSize);
//safe.UnaccessData();
}
// make real parameters out of the notification
//2.0
// CString strTargetFrameName(V_BSTR(TargetFrameName));
// CString strHeaders = V_BSTR(Headers);
DWORD nFlags = V_I4(Flags);
// notify the user's class
// OnBeforeNavigate2(strURL, nFlags, strTargetFrameName,
// array, strHeaders, Cancel);
OnBeforeNavigate2(strURL, nFlags, "",
array, "", Cancel);
}
catch(...)
{
}
}
void CFixedHtmlView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
try{
// UNUSED_ALWAYS(pDisp);
ASSERT(V_VT(URL) == VT_BSTR);
//is download complete?
if (glpDisp && glpDisp == pDisp)
{
// if the LPDISPATCH are same, that means
// it is the final DocumentComplete. Reset glpDisp
TRACE("Document is done downloading");
glpDisp = NULL;
}
// CString str(V_BSTR(URL));
strURL = V_BSTR(URL);
OnDocumentComplete(strURL);
}catch(...)
{
}
}
//event
/////////////////////////////////////////////////////////////////////////////
// CFixedHtmlView Events
void CFixedHtmlView::OnProgressChange(long lProgress, long lProgressMax)
{
// user will override to handle this notification
UNUSED_ALWAYS(lProgress);
UNUSED_ALWAYS(lProgressMax);
}
void CFixedHtmlView::OnCommandStateChange(long lCommand, BOOL bEnable)
{
// user will override to handle this notification
UNUSED_ALWAYS(lCommand);
UNUSED_ALWAYS(bEnable);
}
/*void CFixedHtmlView::OnDownloadBegin()
{
// user will override to handle this notification
}
void CFixedHtmlView::OnDownloadComplete()
{
// user will override to handle this notification
}
*/
void CFixedHtmlView::OnTitleChange(LPCTSTR lpszText)
{
// user will override to handle this notification
UNUSED_ALWAYS(lpszText);
}
/*
void CFixedHtmlView::OnPropertyChange(LPCTSTR lpszProperty)
{
// user will override to handle this notification
UNUSED_ALWAYS(lpszProperty);
}*/
void CFixedHtmlView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* bCancel)
{
// default to continuing
*bCancel = FALSE;
// user will override to handle this notification
UNUSED_ALWAYS(ppDisp);
}
void CFixedHtmlView::OnDocumentComplete(LPCTSTR lpszURL)
{
// user will override to handle this notification
UNUSED_ALWAYS(lpszURL);
}
/*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -