📄 viewh.cpp
字号:
return (result ? TRUE : FALSE);
}
/////////////////////////////////////////////////////////////////////////////
// CHView operations
BOOL CHView::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 CHView::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 CHView::Navigate(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
LPCTSTR lpszTargetFrameName /* = NULL */ ,
LPCTSTR lpszHeaders /* = NULL */, LPVOID lpvPostData /* = NULL */,
DWORD dwPostDataLen /* = 0 */)
{
CString strURL(lpszURL);
BSTR bstrURL = 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 MakeOleVariant(COleVariant &ov, LPCITEMIDLIST pidl)
{
AfxVariantInit(&ov);
if (pidl != NULL)
{
// walk through entries in the list and accumulate their size
UINT cbTotal = 0;
SAFEARRAY *psa = NULL;
LPCITEMIDLIST pidlWalker = pidl;
while (pidlWalker->mkid.cb)
{
cbTotal += pidlWalker->mkid.cb;
pidlWalker = (LPCITEMIDLIST)
(((LPBYTE)pidlWalker) + pidlWalker->mkid.cb);
}
// add the base structure size
cbTotal += sizeof(ITEMIDLIST);
// get a safe array for them
psa = SafeArrayCreateVector(VT_UI1, 0, cbTotal);
// copy it and set members
if (psa != NULL)
{
memcpy(psa->pvData, (LPBYTE) pidl, cbTotal);
ov.vt = VT_ARRAY | VT_UI1;
ov.parray = psa;
}
}
}
void CHView::Navigate2(LPITEMIDLIST pIDL, DWORD dwFlags /* = 0 */,
LPCTSTR lpszTargetFrameName /* = NULL */)
{
ASSERT(m_pBrowserApp != NULL);
// COleVariant vPIDL(pIDL);
COleVariant vPIDL;
MakeOleVariant(vPIDL, pIDL);
COleVariant empty;
m_pBrowserApp->Navigate2(vPIDL,
COleVariant((long) dwFlags, VT_I4),
COleVariant(lpszTargetFrameName, VT_BSTR),
empty, empty);
}
void CHView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
LPCTSTR lpszTargetFrameName /* = NULL */,
LPCTSTR lpszHeaders /* = NULL */,
LPVOID lpvPostData /* = NULL */, DWORD dwPostDataLen /* = 0 */)
{
ASSERT(m_pBrowserApp != NULL);
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 CHView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags,
CByteArray& baPostData, LPCTSTR lpszTargetFrameName /* = NULL */,
LPCTSTR lpszHeaders /* = NULL */)
{
UNUSED_ALWAYS(lpszURL);
UNUSED_ALWAYS(dwFlags);
UNUSED_ALWAYS(lpszTargetFrameName);
UNUSED_ALWAYS(baPostData);
UNUSED_ALWAYS(lpszHeaders);
ASSERT(m_pBrowserApp != NULL);
/*
COleVariant vURL;
m_pBrowserApp->Navigate2(bstrURL,
COleVariant((long) dwFlags, VT_I4),
COleVariant(lpszTargetFrameName, VT_BSTR),
COleVariant(),
COleVariant(lpszHeaders, VT_BSTR));
*/
}
void CHView::PutProperty(LPCTSTR lpszProperty, const VARIANT& vtValue)
{
ASSERT(m_pBrowserApp != NULL);
CString strProp(lpszProperty);
BSTR bstrProp = strProp.AllocSysString();
m_pBrowserApp->PutProperty(bstrProp, vtValue);
::SysFreeString(bstrProp);
}
BOOL CHView::GetProperty(LPCTSTR lpszProperty, CString& strValue)
{
ASSERT(m_pBrowserApp != NULL);
CString strProperty(lpszProperty);
BSTR bstrProperty = strProperty.AllocSysString();
BOOL bResult = FALSE;
VARIANT vReturn;
vReturn.vt = VT_BSTR;
vReturn.bstrVal = NULL;
HRESULT hr = m_pBrowserApp->GetProperty(bstrProperty, &vReturn);
if (SUCCEEDED(hr))
{
strValue = CString(vReturn.bstrVal);
bResult = TRUE;
}
::SysFreeString(bstrProperty);
return bResult;
}
COleVariant CHView::GetProperty(LPCTSTR lpszProperty)
{
COleVariant result;
static BYTE parms[] =
VTS_BSTR;
m_wndBrowser.InvokeHelper(0x12f, DISPATCH_METHOD,
VT_VARIANT, (void*)&result, parms, lpszProperty);
return result;
}
CString CHView::GetFullName() const
{
ASSERT(m_pBrowserApp != NULL);
BSTR bstr;
m_pBrowserApp->get_FullName(&bstr);
CString retVal(bstr);
return retVal;
}
/////////////////////////////////////////////////////////////////////////////
// CHView event reflectors
void CHView::NavigateComplete2(LPDISPATCH /* pDisp */, VARIANT* URL)
{
ASSERT(V_VT(URL) == VT_BSTR);
USES_CONVERSION;
CString str = OLE2T(V_BSTR(URL));
OnNavigateComplete2(str);
}
void CHView::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 CHView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL)
{
UNUSED_ALWAYS(pDisp);
ASSERT(V_VT(URL) == VT_BSTR);
CString str(V_BSTR(URL));
OnDocumentComplete(str);
}
/////////////////////////////////////////////////////////////////////////////
// CHView Events
void CHView::OnProgressChange(long lProgress, long lProgressMax)
{
// user will override to handle this notification
UNUSED_ALWAYS(lProgress);
UNUSED_ALWAYS(lProgressMax);
}
void CHView::OnCommandStateChange(long lCommand, BOOL bEnable)
{
// user will override to handle this notification
UNUSED_ALWAYS(lCommand);
UNUSED_ALWAYS(bEnable);
}
void CHView::OnDownloadBegin()
{
// user will override to handle this notification
}
void CHView::OnDownloadComplete()
{
// user will override to handle this notification
}
void CHView::OnTitleChange(LPCTSTR lpszText)
{
// user will override to handle this notification
UNUSED_ALWAYS(lpszText);
}
void CHView::OnPropertyChange(LPCTSTR lpszProperty)
{
// user will override to handle this notification
UNUSED_ALWAYS(lpszProperty);
}
void CHView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* bCancel)
{
// default to continuing
bCancel = FALSE;
// user will override to handle this notification
UNUSED_ALWAYS(ppDisp);
}
void CHView::OnDocumentComplete(LPCTSTR lpszURL)
{
// user will override to handle this notification
//REVIEW: this needs a reflector
UNUSED_ALWAYS(lpszURL);
}
void CHView::OnQuit()
{
// user will override to handle this notification
}
void CHView::OnVisible(BOOL bVisible)
{
// user will override to handle this notification
UNUSED_ALWAYS(bVisible);
}
void CHView::OnToolBar(BOOL bToolBar)
{
// user will override to handle this notification
UNUSED_ALWAYS(bToolBar);
}
void CHView::OnMenuBar(BOOL bMenuBar)
{
// user will override to handle this notification
UNUSED_ALWAYS(bMenuBar);
}
void CHView::OnStatusBar(BOOL bStatusBar)
{
// user will override to handle this notification
UNUSED_ALWAYS(bStatusBar);
}
void CHView::OnFullScreen(BOOL bFullScreen)
{
// user will override to handle this notification
UNUSED_ALWAYS(bFullScreen);
}
void CHView::OnTheaterMode(BOOL bTheaterMode)
{
// user will override to handle this notification
UNUSED_ALWAYS(bTheaterMode);
}
void CHView::OnNavigateComplete2(LPCTSTR lpszURL)
{
// user will override to handle this notification
UNUSED_ALWAYS(lpszURL);
}
void CHView::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 CHView::OnStatusTextChange(LPCTSTR pszText)
{
// try to set the status bar text via the frame
CWnd* pWnd = GetParent();
CFrameWnd* pFrame = DYNAMIC_DOWNCAST(CFrameWnd, pWnd);
if (pFrame != NULL)
pFrame->SetMessageText(pszText);
}
void CHView::OnInitialUpdate()
{
CView::OnInitialUpdate();
ModifyStyleEx(0,WS_EX_STATICEDGE, SWP_FRAMECHANGED);
Navigate2(csHomePage);
}
BOOL CHView::DestroyWindow()
{
return CView::DestroyWindow();
}
void CHView::OnWebback()
{
GoBack();
}
void CHView::OnUpdateWebback(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CHView::OnWebforward()
{
GoForward();
}
void CHView::OnUpdateWebforward(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CHView::OnWebhome()
{
Navigate2(csHomePage);
}
void CHView::OnUpdateWebhome(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CHView::OnWebrefresh()
{
Refresh();
}
void CHView::OnUpdateWebrefresh(CCmdUI* pCmdUI)
{
// TODO: Add your command update UI handler code here
}
void CHView::OnWebstop()
{
Stop();
}
void CHView::OnUpdateWebstop(CCmdUI* pCmdUI)
{
pCmdUI->Enable(!GetBusy());
}
void CHView::OnRButtonDown(UINT nFlags, CPoint point)
{
CView::OnRButtonDown(nFlags, point);
}
void CHView::OnRButtonUp(UINT nFlags, CPoint point)
{
CView::OnRButtonUp(nFlags, point);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -