📄 fixedhtmlview.cpp
字号:
COleVariant((long) dwFlags, VT_I4),
COleVariant(lpszTargetFrameName, VT_BSTR),
vPostData,
COleVariant(lpszHeaders, VT_BSTR));
}
//2.1
// lpDisp->Release();
// lpDisp = NULL;
}
}
/* catch(CMemoryException* e)
{
if(e!=NULL)e->Delete();
}*/
catch(...)
{
}
try{
//2.2
if(bstrURL!=NULL)
SysFreeString(bstrURL);
if(lpWB!=NULL)
lpWB->Release();
if(lpDisp!=NULL)
lpDisp->Release();
}
catch(...)
{
}
}
void CFixedHtmlView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
LPCTSTR lpszTargetFrameName /* = NULL */,
LPCTSTR lpszHeaders /* = NULL */,
LPVOID lpvPostData /* = NULL */, DWORD dwPostDataLen /* = 0 */)
{
// if(m_pBrowserApp == NULL)
// return;
LPDISPATCH lpDisp = NULL;
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();
}
}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();
}
}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
{
USES_CONVERSION;
CString str = 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(str);
m_strLastURL = str;
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(str);
}
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;
VARIANT* vtPostedData = V_VARIANTREF(PostData);
CByteArray array;
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);
// 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 strURL = V_BSTR(URL);
// 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(CMemoryException* e)
{
if(e!=NULL)e->Delete();
}*/
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));
OnDocumentComplete(str);
}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);
}
/*
void CFixedHtmlView::OnQuit()
{
// user will override to handle this notification
}
void CFixedHtmlView::OnVisible(BOOL bVisible)
{
// user will override to handle this notification
UNUSED_ALWAYS(bVisible);
}
void CFixedHtmlView::OnToolBar(BOOL bToolBar)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -