📄 fixedhtmlview.cpp
字号:
}
CString CFixedHtmlView::GetFullName()
{
return m_wndBrowser.GetFullName();
}
*/
void CFixedHtmlView::GoHome()
{
//m_wndBrowser.GoHome();
if(m_pBrowserApp != NULL)
m_pBrowserApp->GoHome();
}
void CFixedHtmlView::Stop()
{
//m_wndBrowser.Stop();
if(m_pBrowserApp != NULL)
m_pBrowserApp->Stop();
}
void CFixedHtmlView::GoBack()
{
//((IWebBrowser2*)m_wndBrowser.GetApplication())->GoBack();
if(m_pBrowserApp != NULL)
m_pBrowserApp->GoBack();
}
void CFixedHtmlView::GoForward()
{
//((IWebBrowser2*)m_wndBrowser.GetApplication())->GoForward();
if(m_pBrowserApp != NULL)
m_pBrowserApp->GoForward();
}
/*void CFixedHtmlView::GoSearch()
{
m_wndBrowser.GoSearch();
}*/
void CFixedHtmlView::Refresh()
{
//m_wndBrowser.Refresh();
if(m_pBrowserApp != NULL)
m_pBrowserApp->Refresh();
}
void CFixedHtmlView::Refresh2(int nLevel)
{
// m_wndBrowser.Refresh2(COleVariant((long) nLevel, VT_I4));
if(m_pBrowserApp != NULL)
m_pBrowserApp->Refresh2(COleVariant((long) nLevel, VT_I4));
}
/////////////////////////////////////////////////////////////////////////////
// CFixedHtmlView event reflectors
void CFixedHtmlView::NavigateComplete2(LPDISPATCH /* pDisp */, VARIANT* URL)
{
ASSERT(V_VT(URL) == VT_BSTR);
USES_CONVERSION;
CString str = OLE2T(V_BSTR(URL));
OnNavigateComplete2(str);
}
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);
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);
LPBYTE lpByte = array.GetData();
memcpy(lpByte, pVoid, dwSize);
safe.UnaccessData();
}
// make real parameters out of the notification
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);
}
void CFixedHtmlView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
UNUSED_ALWAYS(pDisp);
ASSERT(V_VT(URL) == VT_BSTR);
CString str(V_BSTR(URL));
OnDocumentComplete(str);
}
//event
void CFixedHtmlView::OnFilePrint()
{
// TODO: Add your command handler code here
LPOLECOMMANDTARGET lpTarget = NULL;
LPDISPATCH lpDisp = GetHtmlDocument();
if (lpDisp != NULL)
{
// the control will handle all printing UI
if (SUCCEEDED(lpDisp->QueryInterface(IID_IOleCommandTarget,
(LPVOID*) &lpTarget)))
{
lpTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL, NULL);
lpTarget->Release();
}
lpDisp->Release();
}
}
/////////////////////////////////////////////////////////////////////////////
// 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)
{
// 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, CByteArray& 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();
if (!CView::Create(lpszClassName, lpszWindowName,
dwStyle, rect, pParentWnd, nID, pContext))
{
return FALSE;
}
if(!m_wndBrowser.Create ("Browser", WS_VISIBLE|WS_CHILD|WS_TABSTOP, CRect (0,0,100,100), this, IDC_BROWSER_CONTROL))
{//11/7
DestroyWindow();
return FALSE;
}
//11/7
LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);
if (!SUCCEEDED(hr))
{
m_pBrowserApp = NULL;
m_wndBrowser.DestroyWindow();
DestroyWindow();
return FALSE;
}
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);
// allow tooltip messages to be filtered
if (CView::PreTranslateMessage(pMsg))
return TRUE;
// 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();
}
// don't call IsDialogMessage if form is empty
if (::GetWindow(m_hWnd, GW_CHILD) == NULL)
return FALSE;
// filter both messages to dialog and from children
return PreTranslateInput(pMsg);
}
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
if(message == WM_DESTROY)
GetParentFrame()->PostMessage(WM_CLOSE);
}
void CFixedHtmlView::OnFilePrintpreview()
{
// TODO: Add your command handler code here
LPOLECOMMANDTARGET lpTarget = NULL;
LPDISPATCH lpDisp = GetHtmlDocument();
if (lpDisp != NULL)
{
// the control will handle all printing UI
if (SUCCEEDED(lpDisp->QueryInterface(IID_IOleCommandTarget,
(LPVOID*) &lpTarget)))
{
lpTarget->Exec(NULL, OLECMDID_PRINTPREVIEW, 0, NULL, NULL);
lpTarget->Release();
}
lpDisp->Release();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -