📄 myieview.cpp
字号:
else
oldIcon = ((CMainFrame*)pMainFrame)->SetTabIcon( 5, nTabID );
//update tab bar
pMainFrame->PostMessage(WM_UPDATE_TAB);
}
//mutex
// ReleaseMutex(m_hMutex);
}
}
//scroll bar
try{
if(!strUrl.IsEmpty() && m_IsNewPopup &&(m_nProgress==100 || m_nProgress<0))
{
WBShowScrollBar(this);
}
}
catch(...)
{
}
}
catch(...)
{
// AfxMessageBox("doc complete error");
//2.0
/* m_nProgress = -1;
if(IsActive)
{
percent= -1;
}*/
}
}
void CMyIEView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD /*nFlags*/,
LPCTSTR lpszTargetFrameName, CByteArray& baPostedData,
LPCTSTR /*lpszHeaders*/, BOOL* pbCancel)
{
//open in new window
//get time
LARGE_INTEGER liFinish;
LARGE_INTEGER liFreq;
BOOL bCanNew = FALSE;
TCITEM TabCtrlItem;
try
{
CChildFrame* tcf = (CChildFrame*)GetParentFrame();
CMainFrame* mf = (CMainFrame*)(tcf->GetParentFrame());
BOOL bLock = FALSE;
if(tcf!=NULL)
bLock = tcf->bLock;
if((bLinkInNewWindow || bLock) && m_tLastClick.LowPart != 0 && baPostedData.GetSize()==0)
{
QueryPerformanceCounter(&liFinish);
QueryPerformanceFrequency(&liFreq);
if(liFreq.LowPart!=0)
{
double secs = (double)(liFinish.LowPart - m_tLastClick.LowPart)/(double)liFreq.LowPart;
if(secs<0.6 && secs>0)
{
int dup = ((CMainFrame*)pMainFrame)->FindDupURL(lpszURL, tcf);
if(dup<0)
bCanNew = TRUE;
else
{
*pbCancel = TRUE;
if(mf!=NULL && mf->m_bActiveNewWindow)
{
TabCtrlItem.mask = TCIF_PARAM;
mf->m_wndTab.GetItem(dup, &TabCtrlItem);
CChildFrame* tcf2 = (CChildFrame*)TabCtrlItem.lParam;
if(tcf2!=NULL && tcf2!=tcf)
{
mf->MDIActivate(tcf2);
//((CMainFrame*)pMainFrame)->m_wndTab.SetCurSel(m_nDupID);
}
}
}
}
else
m_tLastClick.LowPart = 0;
}
}
if(!m_bFirst && (bLinkInNewWindow || bLock) && pMainFrame!=NULL && bCanNew)
{
if(strstr(lpszURL, "mailto:")==NULL && strstr(lpszURL, "javascript:")==NULL)
{
CWinApp* pApp = AfxGetApp();
CChildFrame *pWnd = NULL;
if(pApp==NULL)
return;
pWnd = ((CMainFrame*)pApp->m_pMainWnd)->NewChildWindow(0,1, NULL, this);
if(pWnd != NULL)
{
pWnd->m_pView->dwProperty = dwProperty;
pWnd->m_pView->m_IsNewPopup = FALSE; //TRUE;
pWnd->m_pView->m_bFirst = TRUE;
pWnd->m_pView->m_nProgress = 0;
pWnd->m_pView->ToNavigate(lpszURL);
if(pbCancel!=NULL)
*pbCancel = TRUE;
return;
}
}
}
m_bFirst = FALSE;
m_bForceRefresh = FALSE;
//secure info
if(strncmp(lpszURL, "https", 5)!=0)
m_bIsSecure = FALSE;
if(IsActive && pMainFrame!=NULL)
((CMainFrame*)pMainFrame)->m_bIsSecure = m_bIsSecure;
//filter popup
if(pMainFrame!=NULL && lpszURL!=NULL && EnablePopupFilter && strcmp(lpszURL, "about:blank")!=0)
{
//mutex
// WaitForSingleObject(m_hMutex, INFINITE);
//2.2 m_IsNewPopup &&
if((((CMainFrame*)pMainFrame)->m_astrPopup.Find(lpszURL)!=NULL || PopFilterStar(lpszURL)))
{
if(pbCancel!=NULL)
*pbCancel = TRUE;
IsPopUp = TRUE;
m_strPossibleURL = lpszURL;
m_nProgress = -1;
}
else
{
m_nProgress = 0;
if(IsActive)
{
percent = m_nProgress;
}
}
}
//2.3 329 filter duplicate url
if(EnableDupFilter && m_nFilterDup && !IsPopUp && m_IsNewPopup && pMainFrame!=NULL && lpszURL!=NULL && strcmp(lpszURL, "about:blank")!=0)
{
//mutex
// WaitForSingleObject(m_hMutex, INFINITE);
//only filter once the window popup
m_nFilterDup --;
int dup = ((CMainFrame*)pMainFrame)->FindDupURL(lpszURL, tcf);
if(dup>=0)
{
if(pbCancel!=NULL)
*pbCancel = TRUE;
IsPopUp = TRUE;
m_strPossibleURL = lpszURL;
m_nDupID = dup;
m_nProgress = -1;
m_nFilterDup = 0;
//active that dup window
if(m_bReUsed && tcf!=NULL && mf!=NULL && (mf->m_bActiveNewWindow || tcf->m_bForceActive))
{
// TCITEM TabCtrlItem;
TabCtrlItem.mask = TCIF_PARAM;
((CMainFrame*)pMainFrame)->m_wndTab.GetItem(m_nDupID, &TabCtrlItem);
CChildFrame* tcf2 = (CChildFrame*)TabCtrlItem.lParam;
if(tcf2!=NULL && tcf2!=tcf)
{
((CMainFrame*)pMainFrame)->MDIActivate(tcf2);
//((CMainFrame*)pMainFrame)->m_wndTab.SetCurSel(m_nDupID);
}
m_nDupID = -1;
}
}
else
{
m_nProgress = 0;
if(IsActive)
{
percent = m_nProgress;
}
}
}
/* if(bDelayAdd && m_IsNewPopup && !IsPopUp && tcf!=NULL)
{
//resize
/* CRect rect, oldrect;
m_wndBrowser.GetWindowRect(&oldrect);
GetParentFrame()->GetClientRect(&rect);
rect.left-=2;
rect.top-=2;
rect.right +=2;
rect.bottom +=2;
if(oldrect.Width()!=rect.Width() || oldrect.Height()!=rect.Height())
{
m_wndBrowser.MoveWindow(rect);
}* /
try{
CRect rect;
tcf->GetClientRect(&rect);
rect.left-=2;
rect.top-=2;
rect.right +=2;
rect.bottom +=2;
//m_wndBrowser.MoveWindow(rect);
SendMessage(WM_SIZE, 0, ((rect.Height())<<16)+rect.Width());
}catch(...)
{
}
}*/
//mutex
// WaitForSingleObject(m_hMutex, INFINITE);
//reused window
if(!IsPopUp && m_bReUsed && tcf!=NULL && mf!=NULL && (mf->m_bActiveNewWindow || tcf->m_bForceActive))
{
int nTabID = mf->FindTab(tcf);
//active window
mf->MDIActivate(tcf);
//select current tab
mf->m_wndTab.SetCurSel( nTabID );
tcf->m_bForceActive = FALSE;
}
m_bReUsed = FALSE;
//Add a tab to tabbar
if(!IsPopUp && bDelayAdd && tcf!=NULL && mf!=NULL)
{
tcf->ShowWindow(SW_SHOW);
bDelayAdd = FALSE;
//add tab
mf->AddNewTab(tcf);
int nTabID = mf->FindTab(tcf);
//active window
if(mf->m_bActiveNewWindow || tcf->m_bForceActive)
{
mf->MDIActivate(tcf);
//select current tab
mf->m_wndTab.SetCurSel( nTabID );
tcf->m_bForceActive = FALSE;
}
//set icon
oldIcon = mf->SetTabIcon( 0, nTabID );
//update tab bar
mf->PostMessage(WM_UPDATE_TAB);
// bUpdateTab = TRUE;
mf->PostMessage(WM_UPDATE_TAB_TIP);
}
}
/* catch(CMemoryException* e)
{
// AfxMessageBox("before nav error");
if(e!=NULL)e->Delete();
}*/
catch(...)
{
}
}
// these are all simple one-liners to do simple controlling of the browser
void CMyIEView::OnGoBack()
{
if(m_back)
GoBack();
}
void CMyIEView::OnGoForward()
{
if(m_forward)
GoForward();
}
void CMyIEView::OnGoStartPage()
{
GoHome();
}
// these functions control the font size. There is no explicit command in the
// CFixedHtmlView class to do this, but we can do it by using the ExecWB() function.
/*void CMyIEView::OnViewFontsLargest()
{
nDefFontSize = m_nFontSize = 0;
COleVariant vaZoomFactor(4l);
ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
&vaZoomFactor, NULL);
}
void CMyIEView::OnViewFontsLarge()
{
nDefFontSize = m_nFontSize = 1;
COleVariant vaZoomFactor(3l);
ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
&vaZoomFactor, NULL);
}
void CMyIEView::OnViewFontsMedium()
{
nDefFontSize = m_nFontSize = 2;
COleVariant vaZoomFactor(2l);
ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
&vaZoomFactor, NULL);
}
void CMyIEView::OnViewFontsSmall()
{
nDefFontSize = m_nFontSize = 3;
COleVariant vaZoomFactor(1l);
ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
&vaZoomFactor, NULL);
}
void CMyIEView::OnViewFontsSmallest()
{
nDefFontSize = m_nFontSize = 4;
COleVariant vaZoomFactor(0l);
ExecWB(OLECMDID_ZOOM, OLECMDEXECOPT_DONTPROMPTUSER,
&vaZoomFactor, NULL);
}
*/
void CMyIEView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* Cancel)
{
// TODO: Add your specialized code here and/or call the base class
CChildFrame *pWnd = NULL;
if(ppDisp == NULL || Cancel == NULL)
return;
//mutex
// WaitForSingleObject(m_hMutex, INFINITE);
try{
*Cancel = TRUE;
//auto filter popup window not opened by user
if(m_bAutoFilter)
{
//this window is to be closed, so don't open any other windows from it.
if(m_bToClose)
return;
LARGE_INTEGER liFinish;
LARGE_INTEGER liFreq;
QueryPerformanceCounter(&liFinish);
QueryPerformanceFrequency(&liFreq);
if(liFreq.LowPart!=0)
{
double secs = (double)(liFinish.LowPart - m_tLastClick.LowPart)/(double)liFreq.LowPart;
double Rsecs = (double)(liFinish.LowPart - m_tLastRClick.LowPart)/(double)liFreq.LowPart;
if(secs>1.0 && secs<5.0 && m_bLClick)
{
//get click point
BSTR bstr=NULL;
IHTMLElement* pElem = NULL;
IHTMLDocument2* pHTMLDoc=NULL;
try{
LPDISPATCH pDisp = GetHtmlDocument();
if(pDisp!=NULL)
{
if(SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDoc)))
{
if(SUCCEEDED(pHTMLDoc->elementFromPoint(m_LClickPT.x, m_LClickPT.y, &pElem)))
{
pElem->get_tagName(&bstr);
pElem->Release();
}
pHTMLDoc->Release();
}
pDisp->Release();
}
}catch(...)
{
}
try{
if(bstr!=NULL)
{
CString t(bstr);
tag = t;
SysFreeString(bstr);
}
}catch(...)
{}
}
if(!(m_bLClick && ((secs<=1.0 && secs>=0) || tag=="A")) && !(Rsecs>=0 && Rsecs<=5 && m_bRClick))
{
*ppDisp = NULL;
m_bLClick = FALSE;
tag == "";
return;
}
}
}
m_bLClick = FALSE;
tag == "";
if(pMainFrame!=NULL)
pWnd = ((CMainFrame*)pMainFrame)->NewChildWindow(0,1, NULL, this);
//mutex
// ReleaseMutex(m_hMutex);
if(pWnd!=NULL)
{
//this maybe a blank window.
if(((CChildFrame*)GetParentFrame())->m_pBlankChild != pWnd)
{
((CChildFrame*)GetParentFrame())->m_pBlankChild = pWnd;
QueryPerformanceCounter(&((CChildFrame*)GetParentFrame())->m_tBlankChild);
}
else
((CChildFrame*)GetParentFrame())->m_pBlankChild = NULL;
pWnd->m_pView->dwProperty = dwProperty;
pWnd->m_pView->m_IsNewPopup = TRUE;
pWnd->m_pView->IsPopUp = FALSE;
pWnd->m_pView->m_bToClose = FALSE;
pWnd->m_pView->m_nFilterDup = 1;
pWnd->m_pView->m_bForceResize = TRUE;
pWnd->m_pView->m_nProgress = 0;
pWnd->m_pView->m_bAutoFilter = m_bAutoFilter;
*ppDisp = pWnd->m_pView->GetApplication();
}
if(*ppDisp != NULL)
*Cancel = FALSE;
}
/* catch(CMemoryException* e)
{
// AfxMessageBox("new window error");
*Cancel=TRUE;
if(e!=NULL)e->Delete();
}*/
catch(...)
{
}
//CFixedHtmlView::OnNewWindow2(ppDisp, Cancel);
}
void CMyIEView::OnProgressChange(long nProgress, long nProgressMax)
{
// TODO: Add your specialized code here and/or call the base class
try{
int oldp = m_nProgress;
if(nProgressMax>0 && nProgress>=0 && nProgressMax/100>0)
{
m_nProgress = nProgress/(nProgressMax/100);
if(m_nProgress>100)
m_nProgress=100;
}
else
{
m_nProgress = -1;
//b5
// CString strUrl2;
// GetLocationURL(strUrl2);
// if((strUrl2 != "" && !strUrl2.IsEmpty()))
// m_lpszUrl = strUrl2;
}
if(IsActive)
percent = m_nProgress;
if(IsActive && m_bUseAutoScroll )
{
//start to scroll
if(m_nScrollTimer==0 && m_bUseAutoScroll && m_nSrSpeed!=0)
{
if(m_nProgress==100 || m_nProgress<0 || (!m_bScrollAfterDL && m_nProgress>=20))
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -