📄 fixedhtmlview.cpp
字号:
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)
{
// user will override to handle this notification
UNUSED_ALWAYS(bToolBar);
}
void CFixedHtmlView::OnMenuBar(BOOL bMenuBar)
{
// user will override to handle this notification
UNUSED_ALWAYS(bMenuBar);
}
void CFixedHtmlView::OnStatusBar(BOOL bStatusBar)
{
// user will override to handle this notification
UNUSED_ALWAYS(bStatusBar);
}
void CFixedHtmlView::OnFullScreen(BOOL bFullScreen)
{
// user will override to handle this notification
UNUSED_ALWAYS(bFullScreen);
}
void CFixedHtmlView::OnTheaterMode(BOOL bTheaterMode)
{
// user will override to handle this notification
UNUSED_ALWAYS(bTheaterMode);
}
*/
void CFixedHtmlView::OnNavigateComplete2(LPCTSTR lpszURL)
{
// user will override to handle this notification
UNUSED_ALWAYS(lpszURL);
}
void CFixedHtmlView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags,
LPCTSTR lpszTargetFrameName, BOOL baPostData,
LPCTSTR lpszHeaders, BOOL* bCancel)
{
// default to continuing
*bCancel = FALSE;
// user will override to handle this notification
UNUSED_ALWAYS(lpszURL);
UNUSED_ALWAYS(nFlags);
UNUSED_ALWAYS(lpszTargetFrameName);
UNUSED_ALWAYS(baPostData);
UNUSED_ALWAYS(lpszHeaders);
}
void CFixedHtmlView::OnStatusTextChange(LPCTSTR pszText)
{
// try to set the status bar text via the frame
// CFrameWnd* pFrame = GetParentFrame();
// if (pFrame != NULL)
// pFrame->SetMessageText(pszText);
}
BOOL CFixedHtmlView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName, DWORD dwStyle, const RECT& rect, CWnd* pParentWnd, UINT nID, CCreateContext* pContext)
{
// TODO: Add your specialized code here and/or call the base class
// create the view window itself
//AfxEnableControlContainer();
try{
// m_pCreateContext = pContext;
if (!CView::Create(lpszClassName, lpszWindowName,
dwStyle, rect, pParentWnd, nID, pContext))
{
return FALSE;
}
//327
RECT rectClient;
if(m_bMax==1)
{
::GetClientRect(pMainFrame->m_hWndMDIClient, &rectClient);
rectClient.top -= 2;
rectClient.left -= 2;
rectClient.bottom += 2;
rectClient.right += 2;
}
else
{
rectClient.top = rect.top - 2;
rectClient.left = rect.left - 2;
rectClient.bottom = rect.bottom + 2;
rectClient.right = rect.right + 2;
}
//end 327
if(!m_wndBrowser.Create ("Browser", WS_VISIBLE|WS_CHILD|WS_TABSTOP, rectClient, this, IDC_BROWSER_CONTROL))
{//11/7
DestroyWindow();
return FALSE;
}
// create the control window
// AFX_IDW_PANE_FIRST is a safe but arbitrary ID
/* if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName,
WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDW_PANE_FIRST))
{
DestroyWindow();
return FALSE;
}
*/
//11/7
/* try{
LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
HRESULT hr;
if(lpUnk!=NULL)
hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);
if (!SUCCEEDED(hr))
{
m_pBrowserApp = NULL;
m_wndBrowser.DestroyWindow();
DestroyWindow();
return FALSE;
}
}catch(...)
{
}
*/
//12/27
//m_pBrowserApp = (IWebBrowser2*)m_wndBrowser.GetApplication();
/*2.2
create the BHO when initialize a web browser
The BHO has two main functions:
IObjectWithSiteImpl::SetSite(IUnknown*); pass the IWebBrowser2 to this function.
IDispatchImpl::Invoke(...); pass the Events to the BHO through this function.
CLSID clsID;
HRESULT hr;
IDispatch * pUnknown;
hr= CLSIDFromProgID(OLESTR("Jccatch.IeCatch2.1"), &clsID);
if(FAILED(hr))
{
AfxMessageBox("Retrieval of ProgID failed");
return FALSE;
}
hr = CoCreateInstance(clsID, NULL,
CLSCTX_INPROC_SERVER,
IID_IDispatch,
(void**)&pUnknown);
if(SUCCEEDED(hr))
AfxMessageBox("BHO created");*/
}
/* catch(CMemoryException* e)
{
if(e!=NULL)e->Delete();
}*/
catch(...)
{
}
return TRUE;
//return CWnd::Create(lpszClassName, lpszWindowName, dwStyle, rect, pParentWnd, nID, pContext);
}
BOOL CFixedHtmlView::PreTranslateMessage(MSG* pMsg)
{
ASSERT(pMsg != NULL);
ASSERT_VALID(this);
ASSERT(m_hWnd != NULL);
try
{
if(pMsg == NULL || m_hWnd == NULL)
return TRUE;
// allow tooltip messages to be filtered
if (CView::PreTranslateMessage(pMsg))
return TRUE;
// filter both messages to dialog and from children
if(pMsg->message == WM_KEYDOWN && pMsg->wParam == VK_RETURN)
{
QueryPerformanceCounter(&m_tLastClick);
m_bRClick = FALSE;
m_bLClick = TRUE;
}
//2.4
short ks;
ks =GetKeyState(VK_CONTROL);
if(pMsg->message == WM_KEYDOWN && pMsg->wParam != VK_ESCAPE && (pMsg->wParam<VK_F1 || pMsg->wParam>VK_F12) && (ks>=0 || pMsg->wParam==VK_CONTROL || pMsg->wParam=='C' || pMsg->wParam == 'X' || pMsg->wParam == 'V' || pMsg->wParam == 'Z' || pMsg->wParam == VK_INSERT)) // && ((pMsg->wParam == VK_TAB && ks>=0) || pMsg->wParam == VK_BACK || pMsg->wParam == VK_DELETE || pMsg->wParam == 'C' || pMsg->wParam == 'X' || pMsg->wParam == 'V' || pMsg->wParam == 'Z' || pMsg->wParam == VK_INSERT))
if(pMsg->wParam == VK_RETURN)
{
// PreTranslateInput(pMsg);
return FALSE;
}
else
return PreTranslateInput(pMsg);
// don't translate dialog messages when in Shift+F1 help mode
// CFrameWnd* pFrameWnd = GetTopLevelFrame();
// if (pFrameWnd != NULL && pFrameWnd->m_bHelpMode)
// return FALSE;
// since 'IsDialogMessage' will eat frame window accelerators,
// we call all frame windows' PreTranslateMessage first
/* pFrameWnd = GetParentFrame(); // start with first parent frame
while (pFrameWnd != NULL)
{
// allow owner & frames to translate before IsDialogMessage does
if (pFrameWnd->PreTranslateMessage(pMsg))
return TRUE;
// try parent frames until there are no parent frames
pFrameWnd = pFrameWnd->GetParentFrame();
}*/
/* if (pMainFrame != NULL && pMsg->message == WM_KEYDOWN && (pMsg->wParam == VK_BACK ))
{
// allow owner & frames to translate before IsDialogMessage does
if (pMainFrame->PreTranslateMessage(pMsg) )
return TRUE;
}*/
/* // don't call IsDialogMessage if form is empty
if (::GetWindow(m_hWnd, GW_CHILD) == NULL)
return FALSE;
*/
}
/* catch(CMemoryException* e)
{
if(e!=NULL)e->Delete();
}*/
catch(...)
{
}
return FALSE;
}
BOOL CFixedHtmlView::PreCreateWindow(CREATESTRUCT& cs)
{
// TODO: Modify the Window class or styles here by modifying
// the CREATESTRUCT cs
cs.lpszClass = AfxRegisterWndClass(
CS_DBLCLKS, // if you need double-clicks
NULL, // no cursor (use default)
NULL, // no background brush
NULL); // app icon
ASSERT(cs.lpszClass);
// cs.style |= WS_CLIPCHILDREN;
if( !CView::PreCreateWindow(cs) )
return FALSE;
return TRUE;
}
void CFixedHtmlView::OnParentNotify(UINT message, LPARAM lParam)
{
CView::OnParentNotify(message, lParam);
// TODO: Add your message handler code here
try{
if(message == WM_DESTROY)
{
m_bToClose = TRUE;
GetParentFrame()->PostMessage(WM_CLOSE);
}
}catch(...)
{
}
}
int CFixedHtmlView::SetHistory(LPCSTR strCurUrl)
{
short p = m_nHistoryLength;
int seth = 0;
LPDISPATCH pDisp = NULL;
IHTMLDocument2 *pHTMLDoc = NULL;
IHTMLWindow2 *pHTMLWnd = NULL;
IOmHistory *pHistory = NULL;
// IPersistMoniker *pPM = NULL;
// IMoniker * pMok = NULL;
try{
//get history length
pDisp = GetHtmlDocument();
if( pDisp )
{
if(SUCCEEDED(pDisp->QueryInterface(IID_IHTMLDocument2, (void**)&pHTMLDoc)))
{
if(SUCCEEDED(pHTMLDoc->get_parentWindow( &pHTMLWnd )))
{
if(SUCCEEDED(pHTMLWnd->get_history( &pHistory )))
{
if(pHistory->get_length(&p)==S_OK)
{
//
// DWORD d;
// pHTMLDoc->QueryInterface(IID_IPersistMoniker, (void**)&pPM);
// pPM->GetCurMoniker(&pMok);
// pMok->Hash(&d);
/* FILE * file;
file = fopen("c:\\moniker.txt", "a");
fprintf(file, "%d\r\n", p);
fclose(file);*/
//
if(p>0 && p!=m_nHistoryLength)
{
/* CString m_strLastURL;
//get last url from url list
int ul = m_astrLastURLs.GetSize();
if(ul==1)
m_strLastURL = m_astrLastURLs.GetAt(0);
else
{
CString pre1, pre2, tmp;
if(p-1-1>=0)
pre1 = m_astrHistoryURL.GetAt(p-2);
if(p-1-2>=0)
pre2 = m_astrHistoryURL.GetAt(p-3);
int i;
for(i=ul-1; i>0; i--)
{
tmp = m_astrLastURLs.GetAt(i);
if(tmp != pre1 && tmp != pre2)
break;
}
m_strLastURL = m_astrLastURLs.GetAt(i);
}
m_astrLastURLs.RemoveAll();*/
if(m_strLastTitle.IsEmpty())
m_strLastTitle = m_strLastURL;
if(p>m_nHistoryLength)
{
m_astrHistory.SetAtGrow(p-1, m_strLastTitle);
m_astrHistoryURL.SetAtGrow(p-1, m_strLastURL);
}
else
{
m_astrHistory.SetAt(p-1, m_strLastTitle);
m_astrHistory.SetSize(p);
if(m_nHistoryLength - p >10)
m_astrHistory.FreeExtra();
m_astrHistoryURL.SetAt(p-1, m_strLastURL);
m_astrHistoryURL.SetSize(p);
if(m_nHistoryLength - p >10)
m_astrHistoryURL.FreeExtra();
}
m_nCurHistory = p;
seth = 1;
// m_strLastURL = strCurUrl;
}
else if(p==0)
m_nCurHistory = 0;
//adjust cur history
m_nCurHistory -= m_nBackSteps;
if(!m_back)
m_nCurHistory = 0;
else if(!m_forward && seth && m_nBackSteps>=0)
m_nCurHistory = p;
else if(m_nCurHistory>=0 && m_nCurHistory<p && strCurUrl == m_astrHistoryURL.GetAt(m_nCurHistory))
m_nCurHistory = m_nCurHistory;
else if(m_nCurHistory-1>=0 && strCurUrl == m_astrHistoryURL.GetAt(m_nCurHistory-1))
m_nCurHistory --;
else if(m_nCurHistory-2>=0 && strCurUrl == m_astrHistoryURL.GetAt(m_nCurHistory-2))
m_nCurHistory -=2;
else if(m_nCurHistory+1<p && strCurUrl == m_astrHistoryURL.GetAt(m_nCurHistory+1))
m_nCurHistory ++;
else if(m_nCurHistory+2<p && strCurUrl == m_astrHistoryURL.GetAt(m_nCurHistory+2))
m_nCurHistory +=2;
if(m_forward && m_nCurHistory>=p-1)
m_nCurHistory = p-2;
if(m_back && m_nCurHistory==0)
m_nCurHistory =1;
m_nHistoryLength = p;
}
}
}
}
}
}
catch(...)
{
}
try{
if(pHistory != NULL)
pHistory->Release();
if(pHTMLWnd != NULL)
pHTMLWnd->Release();
if(pHTMLDoc != NULL)
pHTMLDoc->Release();
if(pDisp != NULL)
pDisp->Release();
}
catch(...)
{
}
m_nBackSteps = 0;
return seth;
}
/*BOOL CFixedHtmlView::IsIFrame(LPDISPATCH pDisp , LPCSTR url)
{
//find url in last iframe list
POSITION pos = m_lstrIFrames.Find(url);
if(pos != NULL)
return TRUE;
//get the new iframe list
m_lstrIFrames.RemoveAll();
IWebBrowser2 * pApp = NULL;
IHTMLDocument2 * pDoc = NULL;
IHTMLElementCollection * pAllElem = NULL;
LPDISPATCH pDp = NULL;
IHTMLElementCollection *pFrames = NULL;
VARIANT tag, index;
long p;
tag.vt = VT_BSTR;
CString tagname("Frame");
tag.bstrVal = tagname.AllocSysString();
pDisp->QueryInterface(IID_IWebBrowser2, (void**)&pApp);
if(pApp!=NULL)
{
pApp->get_Document((LPDISPATCH*)&pDoc);
if(pDoc!=NULL)
{
pDoc->get_all(&pAllElem);
if(pAllElem!=NULL)
{
pAllElem->tags(tag, &pDp);
if(pDp!=NULL)
{
pDp->QueryInterface(IID_IHTMLElementCollection, (void**)&pFrames);
pFrames->get_length(&p);
if(p>0)
{
}
}
}
}
}
SysFreeString(tag.bstrVal);
return FALSE;
}*/
BOOL CFixedHtmlView::IsDownloadable(CString &URL)
{
int i = URL.ReverseFind('.');
if(i>0)
{
ext = URL.Mid(i);
ext.MakeUpper();
if(ext.Find('/')>=0 || ext==".HTM" || ext==".HTML" || ext==".ASP")
return FALSE;
int j=0, l=ext.GetLength();
char ch;
i=0;
while(i<((CMainFrame*)pMainFrame)->m_strDownloadFileExt.GetLength())
{
ch = ((CMainFrame*)pMainFrame)->m_strDownloadFileExt.GetAt(i);
if(ext.GetAt(j)!=ch && ch!='?')
{
i+=j+1;
j=0;
}
else
{
j++;
i++;
}
if(j>=l)
return TRUE;
}
return FALSE;
}else
return FALSE;
}
/////////////////////////////////////////////////////////////////////////////
// Pre-startup code
/*
#ifdef AFX_INIT_SEG
#pragma code_seg(AFX_INIT_SEG)
#endif
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -