📄 fixedhtmlview.cpp
字号:
// FixedHtmlView.cpp : implementation file
//
#include "stdafx.h"
#include "GreenBrowser.h"
#include "FixedHtmlView.h"
#include "MainFrm.h"
#include <Mshtmhst.h>
//##############################################################
#ifdef AFX_HTML_SEG
#pragma code_seg(AFX_HTML_SEG)
#endif
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
//##############################################################
#define IDC_BROWSER_CONTROL 100
/////////////////////////////////////////////////////////////////////////////
// CFixedHtmlView
IMPLEMENT_DYNCREATE(CFixedHtmlView, CFormView)
CFixedHtmlView::CFixedHtmlView() : CFormView((LPCTSTR) NULL)
{
m_pBrowserApp = NULL;
m_pDisp = NULL;
m_tLastClick.LowPart = 0;
m_tLastRClick.LowPart = 0;
m_bRClick = FALSE;
m_pITravelLog = NULL;
m_bIniTravelLog = FALSE;
//
m_strTarget.Empty();
}
CFixedHtmlView::~CFixedHtmlView()
{
try{
if (m_pBrowserApp != NULL)
{
m_pBrowserApp->Release();
m_pBrowserApp=NULL;
}
}catch(...){}
try{
if(m_pITravelLog!=NULL)
{
m_pITravelLog->Release();
m_pITravelLog = NULL;
}
}catch(...){}
}
BEGIN_MESSAGE_MAP(CFixedHtmlView, CFormView)
//{{AFX_MSG_MAP(CFixedHtmlView)
ON_WM_PARENTNOTIFY()
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_DESTROY()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
BEGIN_EVENTSINK_MAP(CFixedHtmlView, CFormView)
ON_EVENT(CFixedHtmlView, IDC_BROWSER_CONTROL, 102 /* StatusTextChange */, OnStatusTextChange, VTS_BSTR)
ON_EVENT(CFixedHtmlView, IDC_BROWSER_CONTROL, 108 /* ProgressChange */, OnProgressChange, VTS_I4 VTS_I4)
ON_EVENT(CFixedHtmlView, IDC_BROWSER_CONTROL, 105 /* CommandStateChange */, OnCommandStateChange, VTS_I4 VTS_BOOL)
ON_EVENT(CFixedHtmlView, IDC_BROWSER_CONTROL, 113 /* TitleChange */, OnTitleChange, VTS_BSTR)
ON_EVENT(CFixedHtmlView, IDC_BROWSER_CONTROL, 252 /* NavigateComplete2 */, NavigateComplete2, VTS_DISPATCH VTS_PVARIANT)
ON_EVENT(CFixedHtmlView, IDC_BROWSER_CONTROL, 250 /* BeforeNavigate2 */, BeforeNavigate2, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
ON_EVENT(CFixedHtmlView, IDC_BROWSER_CONTROL, 251 /* NewWindow2 */, OnNewWindow2, VTS_PDISPATCH VTS_PBOOL)
ON_EVENT(CFixedHtmlView, IDC_BROWSER_CONTROL, 259 /* DocumentComplete */, DocumentComplete, VTS_DISPATCH VTS_PVARIANT)
END_EVENTSINK_MAP()
/////////////////////////////////////////////////////////////////////////////
// CFixedHtmlView drawing
void CFixedHtmlView::OnDraw(CDC* pDC)
{
}
void CFixedHtmlView::OnDestroy()
{
try{
if (m_pBrowserApp != NULL)
{
m_pBrowserApp->Release();
m_pBrowserApp = NULL;
}
}catch(...){}
}
/////////////////////////////////////////////////////////////////////////////
// CFixedHtmlView diagnostics
#ifdef _DEBUG
void CFixedHtmlView::AssertValid() const
{
CFormView::AssertValid();
}
void CFixedHtmlView::Dump(CDumpContext& dc) const
{
CFormView::Dump(dc);
}
#endif //_DEBUG
/////////////////////////////////////////////////////////////////////////////
// CFixedHtmlView message handlers
long CFixedHtmlView::GetLeft()
{
long result=0;
try{
m_pBrowserApp->get_Left(&result);
}catch(...){}
return result;
}
long CFixedHtmlView::GetTop()
{
long result=0;
try{
m_pBrowserApp->get_Top(&result);
}catch(...){}
return result;
}
long CFixedHtmlView::GetHeight()
{
long result=0;
try{
m_pBrowserApp->get_Height(&result);
}catch(...){}
return result;
}
long CFixedHtmlView::GetWidth()
{
long result=0;
try{
m_pBrowserApp->get_Width(&result);
}catch(...){}
return result;
}
void CFixedHtmlView::SetTop(long nNewValue)
{
try{
m_pBrowserApp->put_Top(nNewValue);
}catch(...){}
}
void CFixedHtmlView::SetLeft(long nNewValue)
{
try{
m_pBrowserApp->put_Left(nNewValue);
}catch(...){}
}
void CFixedHtmlView::SetHeight(long nNewValue)
{
try{
m_pBrowserApp->put_Height(nNewValue);
}catch(...){}
}
void CFixedHtmlView::SetWidth(long nNewValue)
{
try{
m_pBrowserApp->put_Width(nNewValue);
}catch(...){}
}
void CFixedHtmlView::GetLocationName(CString& strLocName)
{
BSTR bstr=NULL;
try{
m_pBrowserApp->get_LocationName(&bstr);
}catch(...){}
strLocName = bstr;
}
void CFixedHtmlView::GetLocationURL(CString& strLocURL)
{
if (m_b01InUrl)
{
strLocURL = ((CGreenBrowserView*)this)->m_lpszUrl;
return;
}
BSTR bstr=NULL;
try{
m_pBrowserApp->get_LocationURL(&bstr);
}catch(...){}
strLocURL = bstr;
}
READYSTATE CFixedHtmlView::GetReadyState()
{
READYSTATE result;
try{
m_pBrowserApp->get_ReadyState(&result);
}catch(...){}
return result;
}
LPDISPATCH CFixedHtmlView::GetApplication()
{
LPDISPATCH result=NULL;
try{
m_pBrowserApp->get_Application(&result);
}catch(...){}
return result;
}
LPDISPATCH CFixedHtmlView::GetHtmlDocument()
{
LPDISPATCH result=NULL;
try{
m_pBrowserApp->get_Document(&result);
}catch(...){}
return result;
}
OLECMDF CFixedHtmlView::QueryStatusWB(OLECMDID cmdID)
{
OLECMDF result;
try{
m_pBrowserApp->QueryStatusWB(cmdID, &result);
}catch(...){}
return result;
}
void CFixedHtmlView::ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt,
VARIANT* pvaIn, VARIANT* pvaOut)
{
try{
m_pBrowserApp->ExecWB(cmdID, cmdexecopt, pvaIn, pvaOut);
}catch(...){}
}
/////////////////////////////////////////////////////////////////////////////
// CFixedHtmlView operations
BOOL CFixedHtmlView::LoadFromResource(LPCTSTR lpszResource)
{
HINSTANCE hInstance = AfxGetResourceHandle();
ASSERT(hInstance != NULL);
CString strResourceURL;
BOOL bRetVal = TRUE;
LPTSTR lpszModule = new TCHAR[_MAX_PATH];
if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
{
strResourceURL.Format(_T("res://%s/%s"), lpszModule, lpszResource);
Navigate(strResourceURL, 0, 0, 0);
}
else
bRetVal = FALSE;
delete [] lpszModule;
return bRetVal;
}
BOOL CFixedHtmlView::LoadFromResource(UINT nRes)
{
HINSTANCE hInstance = AfxGetResourceHandle();
ASSERT(hInstance != NULL);
CString strResourceURL;
BOOL bRetVal = TRUE;
LPTSTR lpszModule = new TCHAR[_MAX_PATH];
if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
{
strResourceURL.Format(_T("res://%s/%d"), lpszModule, nRes);
Navigate(strResourceURL, 0, 0, 0);
}
else
bRetVal = FALSE;
delete [] lpszModule;
return bRetVal;
}
void CFixedHtmlView::Navigate(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
LPCTSTR lpszTargetFrameName /* = NULL */ ,
LPCTSTR lpszHeaders /* = NULL */, LPVOID lpvPostData /* = NULL */,
DWORD dwPostDataLen /* = 0 */)
{
CString m_strUrl(lpszURL);
BSTR bstrURL = m_strUrl.AllocSysString();
COleSafeArray vPostData;
if (lpvPostData != NULL)
{
if (dwPostDataLen == 0)
dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);
vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
}
m_pBrowserApp->Navigate(bstrURL,
COleVariant((long) dwFlags, VT_I4),
COleVariant(lpszTargetFrameName, VT_BSTR),
vPostData,
COleVariant(lpszHeaders, VT_BSTR));
}
void CFixedHtmlView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
LPCTSTR lpszTargetFrameName /* = NULL */,
LPCTSTR lpszHeaders /* = NULL */,
LPVOID lpvPostData /* = NULL */, DWORD dwPostDataLen /* = 0 */)
{
ASSERT(m_pBrowserApp != NULL);
if ((CFrameWnd*)GetParentFrame() == (CFrameWnd*)pmf->MDIGetActive())
pmf->m_wndAddress->SetWindowText(lpszURL);
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);
m_pBrowserApp->Navigate2(vURL,
vFlags, vTargetFrameName, vPostData, vHeaders);
}
void CFixedHtmlView::GoHome()
{
try{
m_pBrowserApp->GoHome();
}catch(...){}
}
void CFixedHtmlView::Stop()
{
try{
m_pBrowserApp->Stop();
}catch(...){}
}
void CFixedHtmlView::GoBack(int dist)
{
try{
for(int i=0; i<dist; i++)
m_pBrowserApp->GoBack();
m_nBackSteps = dist;
}catch(...){}
}
void CFixedHtmlView::GoForward(int dist)
{
try{
for(int i=0; i<dist; i++)
m_pBrowserApp->GoForward();
m_nBackSteps = -dist;
}catch(...){}
}
void CFixedHtmlView::Refresh()
{
try{
m_pBrowserApp->Refresh();
m_nProgress = 0;
}catch(...){}
}
void CFixedHtmlView::Refresh2(int nLevel)
{
try{
m_pBrowserApp->Refresh2(COleVariant((long) nLevel, VT_I4));
m_nProgress = 0;
}catch(...){}
}
/////////////////////////////////////////////////////////////////////////////
// CFixedHtmlView event reflectors
void CFixedHtmlView::NavigateComplete2(LPDISPATCH pDisp , VARIANT* URL)
{
ASSERT(V_VT(URL) == VT_BSTR);
try
{
m_bLClick = FALSE;
m_bRClick = FALSE;
USES_CONVERSION;
m_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(m_pITravelLog==NULL)
{
SetHistory(m_strUrl);
m_strLastURL = m_strUrl;
}
if (!m_pDisp)
{
m_pDisp = pDisp;
}
//在http://download.pchome.net/输入回车搜索的问题.
//如果已经变大了,post的消息,会造成rect重新变回去
//4.7.1 Create 的时候就已经传了rect
/*if(m_bForceResize)
{
CRect rect;
GetWindowRect(&rect);
PostMessage(WM_SIZE, 0, ((rect.Height())<<16)+rect.Width());
m_bForceResize = FALSE;
}*/
OnNavigateComplete2(m_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;
m_strUrl = V_BSTR(URL);
if (m_strUrl.Find( 0x01 )>=0 && m_strUrl.Find( '@' )>=0)
{
if (pmf->m_bConfirmUnsafePage)
{
CString strTip,strTip2;
LOADSTR(strTip ,IDS_TIP_01URL)
LOADSTR(strTip2 ,IDS_TIP_BROWSE);
strTip = m_strUrl + "\r\n\r\n" + strTip+strTip2;
if(MSGBOX(strTip, MB_YESNO|MB_ICONQUESTION)==IDNO)
{
CChildFrame* tcf = (CChildFrame*)GetParentFrame();
*Cancel=TRUE;
m_bToClose = TRUE;
tcf->PostMessage(WM_CLOSE);
return;
}
}
m_b01InUrl = TRUE;
((CGreenBrowserView*)this)->m_lpszUrl = m_strUrl;
}
else
m_b01InUrl = FALSE;
//do with target frame information
if (pmf->m_bUseTargetFrameName)
{
CString strTargetFrameName(V_BSTR(TargetFrameName));
if (strTargetFrameName.GetLength() && strTargetFrameName.Find("No__Name")<0)//{"_No__Name:4" VT_BSTR}
{
CChildFrame* tcf = (CChildFrame*)GetParentFrame();
CChildFrame* tcfTarget = pmf->GetChildFrameByTarget(tcf,strTargetFrameName);
if( VALID_TCF(tcfTarget) &&
//tcf->m_nActive means drag link
!tcf->m_nActive &&
//must do this, IsEmpty means the page have open in a new window
((CGreenBrowserView*)this)->m_lpszUrl.IsEmpty()
)
{
*Cancel=TRUE;
m_bToClose = TRUE;
tcf->PostMessage(WM_CLOSE);
tcfTarget->m_pView->Navigate2(m_strUrl);
return;
}
else
m_strTarget = strTargetFrameName;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -