home *** CD-ROM | disk | FTP | other *** search
/ Team Palmtops 7 / Palmtops_numero07.iso / WinCE / SDKWindowsCE / HandHeldPCPro30 / sdk.exe / Jupiter SDK / data1.cab / MFC / src / viewhtml.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1999-02-19  |  19.8 KB  |  829 lines

  1. // This is a part of the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) 1992-1998 Microsoft Corporation
  3. // All rights reserved.
  4. //
  5. // This source code is only intended as a supplement to the
  6. // Microsoft Foundation Classes Reference and related
  7. // electronic documentation provided with the library.
  8. // See these sources for detailed information regarding the
  9. // Microsoft Foundation Classes product.
  10.  
  11. #include "stdafx.h"
  12.  
  13. #ifdef AFX_HTML_SEG
  14. #pragma code_seg(AFX_HTML_SEG)
  15. #endif
  16.  
  17. #ifdef _DEBUG
  18. #define new DEBUG_NEW
  19. #undef THIS_FILE
  20. static char THIS_FILE[] = __FILE__;
  21. #endif
  22.  
  23. /////////////////////////////////////////////////////////////////////////////
  24. // CHtmlView
  25.  
  26. BEGIN_MESSAGE_MAP(CHtmlView, CFormView)
  27.     //{{AFX_MSG_MAP(CHtmlView)
  28.     ON_WM_SIZE()
  29.     ON_WM_PAINT()
  30.     ON_WM_DESTROY()
  31.     //}}AFX_MSG_MAP
  32.     // Standard printing commands
  33.     ON_COMMAND(ID_FILE_PRINT, OnFilePrint)
  34. END_MESSAGE_MAP()
  35.  
  36. BEGIN_EVENTSINK_MAP(CHtmlView, CFormView)
  37.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 102 /* StatusTextChange */, OnStatusTextChange, VTS_BSTR)
  38.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 108 /* ProgressChange */, OnProgressChange, VTS_I4 VTS_I4)
  39.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 105 /* CommandStateChange */, OnCommandStateChange, VTS_I4 VTS_BOOL)
  40.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 106 /* DownloadBegin */, OnDownloadBegin, VTS_NONE)
  41.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 104 /* DownloadComplete */, OnDownloadComplete, VTS_NONE)
  42.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 113 /* TitleChange */, OnTitleChange, VTS_BSTR)
  43.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 252 /* NavigateComplete2 */, NavigateComplete2, VTS_DISPATCH VTS_PVARIANT)
  44.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 250 /* BeforeNavigate2 */, BeforeNavigate2, VTS_DISPATCH VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PVARIANT VTS_PBOOL)
  45.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 112 /* PropertyChange */, OnPropertyChange, VTS_BSTR)
  46.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 251 /* NewWindow2 */, OnNewWindow2, VTS_PDISPATCH VTS_PBOOL)
  47.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 259 /* DocumentComplete */, DocumentComplete, VTS_DISPATCH VTS_PVARIANT)
  48.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 253 /* OnQuit */, OnQuit, VTS_NONE)
  49.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 254 /* OnVisible */, OnVisible, VTS_BOOL)
  50.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 255 /* OnToolBar */, OnToolBar, VTS_BOOL)
  51.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 256 /* OnMenuBar */, OnMenuBar, VTS_BOOL)
  52.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 257 /* OnStatusBar */, OnStatusBar, VTS_BOOL)
  53.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 258 /* OnFullScreen */, OnFullScreen, VTS_BOOL)
  54.     ON_EVENT(CHtmlView, AFX_IDW_PANE_FIRST, 260 /* OnTheaterMode */, OnTheaterMode, VTS_BOOL)
  55. END_EVENTSINK_MAP()
  56.  
  57. /////////////////////////////////////////////////////////////////////////////
  58. // CHtmlView construction/destruction
  59.  
  60. CHtmlView::CHtmlView()
  61.     : CFormView((LPCTSTR) NULL)
  62. {
  63.     m_pBrowserApp = NULL;
  64. }
  65.  
  66. CHtmlView::~CHtmlView()
  67. {
  68.     if (m_pBrowserApp != NULL)
  69.         m_pBrowserApp->Release();
  70. }
  71.  
  72.  
  73. /////////////////////////////////////////////////////////////////////////////
  74. // CHtmlView drawing
  75.  
  76. void CHtmlView::OnDraw(CDC* /* pDC */)
  77. {
  78.     // this class should never do its own drawing;
  79.     // the browser control should handle everything
  80.  
  81.     ASSERT(FALSE);
  82. }
  83.  
  84. /////////////////////////////////////////////////////////////////////////////
  85. // CHtmlView printing
  86.  
  87. void CHtmlView::OnFilePrint()
  88. {
  89.     // get the HTMLDocument
  90.  
  91.     if (m_pBrowserApp != NULL)
  92.     {
  93.         LPOLECOMMANDTARGET lpTarget = NULL;
  94.         LPDISPATCH lpDisp = GetHtmlDocument();
  95.  
  96.         if (lpDisp != NULL)
  97.         {
  98.             // the control will handle all printing UI
  99.  
  100.             if (SUCCEEDED(lpDisp->QueryInterface(IID_IOleCommandTarget,
  101.                     (LPVOID*) &lpTarget)))
  102.             {
  103.                 lpTarget->Exec(NULL, OLECMDID_PRINT, 0, NULL, NULL);
  104.                 lpTarget->Release();
  105.             }
  106.             lpDisp->Release();
  107.         }
  108.     }
  109. }
  110.  
  111. /////////////////////////////////////////////////////////////////////////////
  112. // CHtmlView diagnostics
  113.  
  114. #ifdef _DEBUG
  115. void CHtmlView::AssertValid() const
  116. {
  117.     CFormView::AssertValid();
  118. }
  119.  
  120. void CHtmlView::Dump(CDumpContext& dc) const
  121. {
  122.     CFormView::Dump(dc);
  123. }
  124. #endif //_DEBUG
  125.  
  126. /////////////////////////////////////////////////////////////////////////////
  127. // CHtmlView message handlers
  128.  
  129. void CHtmlView::OnDestroy()
  130. {
  131.     RELEASE(m_pBrowserApp);
  132. }
  133.  
  134. void CHtmlView::OnSize(UINT nType, int cx, int cy) 
  135. {
  136.     CFormView::OnSize(nType, cx, cy);
  137.  
  138.     if (::IsWindow(m_wndBrowser.m_hWnd))
  139.     {
  140.         // need to push non-client borders out of the client area
  141.         CRect rect;
  142.         GetClientRect(rect);
  143.         ::AdjustWindowRectEx(rect, 
  144.             m_wndBrowser.GetStyle(), FALSE, WS_EX_CLIENTEDGE);
  145.         m_wndBrowser.SetWindowPos(NULL, rect.left, rect.top,
  146.             rect.Width(), rect.Height(), SWP_NOACTIVATE | SWP_NOZORDER);
  147.     }
  148. }
  149.  
  150. void CHtmlView::OnPaint() 
  151. {
  152.     Default();
  153. }
  154.  
  155. /////////////////////////////////////////////////////////////////////////////
  156. // CHtmlView operations
  157.  
  158. BOOL CHtmlView::Create(LPCTSTR lpszClassName, LPCTSTR lpszWindowName,
  159.                         DWORD dwStyle, const RECT& rect, CWnd* pParentWnd,
  160.                         UINT nID, CCreateContext* pContext) 
  161. {
  162.     // create the view window itself
  163.     if (!CView::Create(lpszClassName, lpszWindowName,
  164.                 dwStyle, rect, pParentWnd,    nID, pContext))
  165.     {
  166.         return FALSE;
  167.     }
  168.  
  169.     AfxEnableControlContainer();
  170.     
  171.     RECT rectClient;
  172.     GetClientRect(&rectClient);
  173.  
  174.     // create the control window
  175.     // AFX_IDW_PANE_FIRST is a safe but arbitrary ID
  176.     if (!m_wndBrowser.CreateControl(CLSID_WebBrowser, lpszWindowName,
  177.                 WS_VISIBLE | WS_CHILD, rectClient, this, AFX_IDW_PANE_FIRST))
  178.     {
  179.         DestroyWindow();
  180.         return FALSE;
  181.     }
  182.  
  183.     LPUNKNOWN lpUnk = m_wndBrowser.GetControlUnknown();
  184.     HRESULT hr = lpUnk->QueryInterface(IID_IWebBrowser2, (void**) &m_pBrowserApp);
  185.     if (!SUCCEEDED(hr))
  186.     {
  187.         m_pBrowserApp = NULL;
  188.         m_wndBrowser.DestroyWindow();
  189.         DestroyWindow();
  190.         return FALSE;
  191.     }
  192.  
  193.     return TRUE;
  194. }
  195.  
  196. /////////////////////////////////////////////////////////////////////////////
  197. // CHtmlView properties
  198.  
  199. CString CHtmlView::GetType() const
  200. {
  201.     ASSERT(m_pBrowserApp != NULL);
  202.  
  203.     BSTR bstr;
  204.     m_pBrowserApp->get_Type(&bstr);
  205.     CString retVal(bstr);
  206.     return retVal;
  207. }
  208.  
  209. long CHtmlView::GetLeft() const
  210. {
  211.     ASSERT(m_pBrowserApp != NULL);
  212.  
  213.     long result;
  214.     m_pBrowserApp->get_Left(&result);
  215.     return result;
  216. }
  217.  
  218.  
  219. long CHtmlView::GetTop() const
  220. {
  221.     ASSERT(m_pBrowserApp != NULL);
  222.     long result;
  223.     m_pBrowserApp->get_Top(&result);
  224.     return result;
  225. }
  226.  
  227. int CHtmlView::GetToolBar() const
  228. {
  229.     ASSERT(m_pBrowserApp != NULL);
  230.     int result;
  231.     m_pBrowserApp->get_ToolBar(&result);
  232.     return result;
  233. }
  234.  
  235. long CHtmlView::GetHeight() const
  236. {
  237.     ASSERT(m_pBrowserApp != NULL);
  238.     long result;
  239.     m_pBrowserApp->get_Height(&result);
  240.     return result;
  241. }
  242.  
  243. BOOL CHtmlView::GetVisible() const
  244. {
  245.     ASSERT(m_pBrowserApp != NULL);
  246.  
  247.     VARIANT_BOOL result;
  248.     m_pBrowserApp->get_Visible(&result);
  249.     return result;
  250. }
  251.  
  252. CString CHtmlView::GetLocationName() const
  253. {
  254.     ASSERT(m_pBrowserApp != NULL);
  255.  
  256.     BSTR bstr;
  257.     m_pBrowserApp->get_LocationName(&bstr);
  258.     CString retVal(bstr);
  259.     return retVal;
  260. }
  261.  
  262. CString CHtmlView::GetLocationURL() const
  263. {
  264.     ASSERT(m_pBrowserApp != NULL);
  265.  
  266.     BSTR bstr;
  267.     m_pBrowserApp->get_LocationURL(&bstr);
  268.     CString retVal(bstr);
  269.     return retVal;
  270. }
  271.  
  272. BOOL CHtmlView::GetBusy() const
  273. {
  274.     ASSERT(m_pBrowserApp != NULL);
  275.  
  276.     VARIANT_BOOL result;
  277.     m_pBrowserApp->get_Busy(&result);
  278.     return result;
  279. }
  280.  
  281. READYSTATE CHtmlView::GetReadyState() const
  282. {
  283.     ASSERT(m_pBrowserApp != NULL);
  284.  
  285.     READYSTATE result;
  286.     m_pBrowserApp->get_ReadyState(&result);
  287.     return result;
  288. }
  289.  
  290. BOOL CHtmlView::GetOffline() const
  291. {
  292.     ASSERT(m_pBrowserApp != NULL);
  293.  
  294.     VARIANT_BOOL result;
  295.     m_pBrowserApp->get_Offline(&result);
  296.     return result;
  297. }
  298.  
  299. BOOL CHtmlView::GetSilent() const
  300. {
  301.     ASSERT(m_pBrowserApp != NULL);
  302.  
  303.     VARIANT_BOOL result;
  304.     m_pBrowserApp->get_Silent(&result);
  305.     return result;
  306. }
  307.  
  308. LPDISPATCH CHtmlView::GetApplication() const
  309. {
  310.     ASSERT(m_pBrowserApp != NULL);
  311.  
  312.     LPDISPATCH result;
  313.     m_pBrowserApp->get_Application(&result);
  314.     return result;
  315. }
  316.  
  317.  
  318. LPDISPATCH CHtmlView::GetParentBrowser() const
  319. {
  320.     ASSERT(m_pBrowserApp != NULL);
  321.  
  322.     LPDISPATCH result;
  323.     m_pBrowserApp->get_Parent(&result);
  324.     return result;
  325. }
  326.  
  327. LPDISPATCH CHtmlView::GetContainer() const
  328. {
  329.     ASSERT(m_pBrowserApp != NULL);
  330.  
  331.     LPDISPATCH result;
  332.     m_pBrowserApp->get_Container(&result);
  333.     return result;
  334. }
  335.  
  336. LPDISPATCH CHtmlView::GetHtmlDocument() const
  337. {
  338.     ASSERT(m_pBrowserApp != NULL);
  339.  
  340.     LPDISPATCH result;
  341.     m_pBrowserApp->get_Document(&result);
  342.     return result;
  343. }
  344.  
  345. BOOL CHtmlView::GetTopLevelContainer() const
  346. {
  347.     ASSERT(m_pBrowserApp != NULL);
  348.  
  349.     VARIANT_BOOL result;
  350.     m_pBrowserApp->get_TopLevelContainer(&result);
  351.     return result;
  352. }
  353.  
  354. BOOL CHtmlView::GetMenuBar() const
  355. {
  356.     ASSERT(m_pBrowserApp != NULL);
  357.  
  358.     VARIANT_BOOL result;
  359.     m_pBrowserApp->get_MenuBar(&result);
  360.     return result;
  361. }
  362.  
  363. BOOL CHtmlView::GetFullScreen() const
  364. {
  365.     ASSERT(m_pBrowserApp != NULL);
  366.  
  367.     VARIANT_BOOL result;
  368.     m_pBrowserApp->get_FullScreen(&result);
  369.     return result;
  370. }
  371.  
  372. BOOL CHtmlView::GetStatusBar() const
  373. {
  374.     ASSERT(m_pBrowserApp != NULL);
  375.  
  376.     VARIANT_BOOL result;
  377.     m_pBrowserApp->get_StatusBar(&result);
  378.     return result;
  379. }
  380.  
  381. OLECMDF CHtmlView::QueryStatusWB(OLECMDID cmdID) const
  382. {
  383.     ASSERT(m_pBrowserApp != NULL);
  384.  
  385.     OLECMDF result;
  386.     m_pBrowserApp->QueryStatusWB(cmdID, &result);
  387.     return result;
  388. }
  389.  
  390. void CHtmlView::ExecWB(OLECMDID cmdID, OLECMDEXECOPT cmdexecopt,
  391.     VARIANT* pvaIn, VARIANT* pvaOut)
  392. {
  393.     ASSERT(m_pBrowserApp != NULL);
  394.  
  395.     m_pBrowserApp->ExecWB(cmdID, cmdexecopt, pvaIn, pvaOut);
  396. }
  397.  
  398. BOOL CHtmlView::GetRegisterAsBrowser() const
  399. {
  400.     ASSERT(m_pBrowserApp != NULL);
  401.  
  402.     VARIANT_BOOL result;
  403.     m_pBrowserApp->get_RegisterAsBrowser(&result);
  404.     return result;
  405. }
  406.  
  407. BOOL CHtmlView::GetRegisterAsDropTarget() const
  408. {
  409.     ASSERT(m_pBrowserApp != NULL);
  410.  
  411.     VARIANT_BOOL result;
  412.     m_pBrowserApp->get_RegisterAsDropTarget(&result);
  413.     return result;
  414. }
  415.  
  416. BOOL CHtmlView::GetTheaterMode() const
  417. {
  418.     ASSERT(m_pBrowserApp != NULL);
  419.  
  420.     VARIANT_BOOL result;
  421.     m_pBrowserApp->get_TheaterMode(&result);
  422.     return result;
  423. }
  424.  
  425. BOOL CHtmlView::GetAddressBar() const
  426. {
  427.     ASSERT(m_pBrowserApp != NULL);
  428.  
  429.     VARIANT_BOOL result;
  430.     m_pBrowserApp->get_AddressBar(&result);
  431.     return result;
  432. }
  433.  
  434. /////////////////////////////////////////////////////////////////////////////
  435. // CHtmlView operations
  436.  
  437. BOOL CHtmlView::LoadFromResource(LPCTSTR lpszResource)
  438. {
  439.     HINSTANCE hInstance = AfxGetResourceHandle();
  440.     ASSERT(hInstance != NULL);
  441.  
  442.     CString strResourceURL;
  443.     BOOL bRetVal = TRUE;
  444.     LPTSTR lpszModule = new TCHAR[_MAX_PATH];
  445.  
  446.     if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
  447.     {
  448.         strResourceURL.Format(_T("res://%s/%s"), lpszModule, lpszResource);
  449.         Navigate(strResourceURL, 0, 0, 0);
  450.     }
  451.     else
  452.         bRetVal = FALSE;
  453.  
  454.     delete [] lpszModule;
  455.     return bRetVal;
  456. }
  457.  
  458. BOOL CHtmlView::LoadFromResource(UINT nRes)
  459. {
  460.     HINSTANCE hInstance = AfxGetResourceHandle();
  461.     ASSERT(hInstance != NULL);
  462.  
  463.     CString strResourceURL;
  464.     BOOL bRetVal = TRUE;
  465.     LPTSTR lpszModule = new TCHAR[_MAX_PATH];
  466.  
  467.     if (GetModuleFileName(hInstance, lpszModule, _MAX_PATH))
  468.     {
  469.         strResourceURL.Format(_T("res://%s/%d"), lpszModule, nRes);
  470.         Navigate(strResourceURL, 0, 0, 0);
  471.     }
  472.     else
  473.         bRetVal = FALSE;
  474.  
  475.     delete [] lpszModule;
  476.     return bRetVal;
  477. }
  478.  
  479. void CHtmlView::Navigate(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
  480.     LPCTSTR lpszTargetFrameName /* = NULL */ ,
  481.     LPCTSTR lpszHeaders /* = NULL */, LPVOID lpvPostData /* = NULL */,
  482.     DWORD dwPostDataLen /* = 0 */)
  483. {
  484.     CString strURL(lpszURL);
  485.     BSTR bstrURL = strURL.AllocSysString();
  486.  
  487.     COleSafeArray vPostData;
  488.     if (lpvPostData != NULL)
  489.     {
  490.         if (dwPostDataLen == 0)
  491.             dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);
  492.  
  493.         vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
  494.     }
  495.  
  496.     m_pBrowserApp->Navigate(bstrURL,
  497.         COleVariant((long) dwFlags, VT_I4),
  498.         COleVariant(lpszTargetFrameName, VT_BSTR),
  499.         vPostData,
  500.         COleVariant(lpszHeaders, VT_BSTR));
  501. }
  502.  
  503. void CHtmlView::Navigate2(LPITEMIDLIST pIDL, DWORD dwFlags /* = 0 */,
  504.     LPCTSTR lpszTargetFrameName /* = NULL */)
  505. {
  506.     ASSERT(m_pBrowserApp != NULL);
  507.  
  508.     COleVariant vPIDL(pIDL);
  509.     COleVariant empty;
  510.  
  511.     m_pBrowserApp->Navigate2(vPIDL,
  512.         COleVariant((long) dwFlags, VT_I4),
  513.         COleVariant(lpszTargetFrameName, VT_BSTR),
  514.         empty, empty);
  515. }
  516.  
  517. void CHtmlView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags /* = 0 */,
  518.     LPCTSTR lpszTargetFrameName /* = NULL */,
  519.     LPCTSTR lpszHeaders /* = NULL */,
  520.     LPVOID lpvPostData /* = NULL */, DWORD dwPostDataLen /* = 0 */)
  521. {
  522.     ASSERT(m_pBrowserApp != NULL);
  523.  
  524.     COleSafeArray vPostData;
  525.     if (lpvPostData != NULL)
  526.     {
  527.         if (dwPostDataLen == 0)
  528.             dwPostDataLen = lstrlen((LPCTSTR) lpvPostData);
  529.  
  530.         vPostData.CreateOneDim(VT_UI1, dwPostDataLen, lpvPostData);
  531.     }
  532.  
  533.     COleVariant vURL(lpszURL, VT_BSTR);
  534.     COleVariant vHeaders(lpszHeaders, VT_BSTR);
  535.     COleVariant vTargetFrameName(lpszTargetFrameName, VT_BSTR);
  536.     COleVariant vFlags((long) dwFlags, VT_I4);
  537.  
  538.     m_pBrowserApp->Navigate2(vURL,
  539.         vFlags, vTargetFrameName, vPostData, vHeaders);
  540. }
  541.  
  542. void CHtmlView::Navigate2(LPCTSTR lpszURL, DWORD dwFlags,
  543.     CByteArray& baPostData,    LPCTSTR lpszTargetFrameName /* = NULL */,
  544.     LPCTSTR lpszHeaders /* = NULL */)
  545. {
  546.     ASSERT(m_pBrowserApp != NULL);
  547.     
  548.     COleVariant vPostData = baPostData;
  549.     COleVariant vURL(lpszURL, VT_BSTR);
  550.     COleVariant vHeaders(lpszHeaders, VT_BSTR);
  551.     COleVariant vTargetFrameName(lpszTargetFrameName, VT_BSTR);
  552.     COleVariant vFlags((long) dwFlags, VT_I4);
  553.  
  554.     ASSERT(m_pBrowserApp != NULL);
  555.  
  556.     m_pBrowserApp->Navigate2(vURL, vFlags, vTargetFrameName,
  557.         vPostData, vHeaders);
  558. }
  559.  
  560. void CHtmlView::PutProperty(LPCTSTR lpszProperty, const VARIANT& vtValue)
  561. {
  562.     ASSERT(m_pBrowserApp != NULL);
  563.  
  564.     CString strProp(lpszProperty);
  565.     BSTR bstrProp = strProp.AllocSysString();
  566.     m_pBrowserApp->PutProperty(bstrProp, vtValue);
  567.     ::SysFreeString(bstrProp);
  568. }
  569.  
  570. BOOL CHtmlView::GetProperty(LPCTSTR lpszProperty, CString& strValue)
  571. {
  572.     ASSERT(m_pBrowserApp != NULL);
  573.  
  574.     CString strProperty(lpszProperty);
  575.     BSTR bstrProperty = strProperty.AllocSysString();
  576.  
  577.     BOOL bResult = FALSE;
  578.     VARIANT vReturn;
  579.     vReturn.vt = VT_BSTR;
  580.     vReturn.bstrVal = NULL;
  581.     HRESULT hr = m_pBrowserApp->GetProperty(bstrProperty, &vReturn);
  582.  
  583.     if (SUCCEEDED(hr))
  584.     {
  585.         strValue = CString(vReturn.bstrVal);
  586.         bResult = TRUE;
  587.     }
  588.  
  589.     ::SysFreeString(bstrProperty);
  590.     return bResult;
  591. }
  592.  
  593. COleVariant CHtmlView::GetProperty(LPCTSTR lpszProperty)
  594. {
  595.     COleVariant result;
  596.  
  597.     static BYTE parms[] =
  598.         VTS_BSTR;
  599.     m_wndBrowser.InvokeHelper(0x12f, DISPATCH_METHOD,
  600.         VT_VARIANT, (void*)&result, parms, lpszProperty);
  601.  
  602.     return result;
  603. }
  604.  
  605. CString CHtmlView::GetFullName() const
  606. {
  607.     ASSERT(m_pBrowserApp != NULL);
  608.  
  609.     BSTR bstr;
  610.     m_pBrowserApp->get_FullName(&bstr);
  611.     CString retVal(bstr);
  612.     return retVal;
  613. }
  614.  
  615. /////////////////////////////////////////////////////////////////////////////
  616. // CHtmlView event reflectors
  617.  
  618. void CHtmlView::NavigateComplete2(LPDISPATCH /* pDisp */, VARIANT* URL) 
  619. {
  620.     ASSERT(V_VT(URL) == VT_BSTR);
  621.  
  622.     USES_CONVERSION;
  623.  
  624.     CString str = OLE2T(V_BSTR(URL));
  625.     OnNavigateComplete2(str);
  626. }
  627.  
  628. void CHtmlView::BeforeNavigate2(LPDISPATCH /* pDisp */, VARIANT* URL,
  629.         VARIANT* Flags, VARIANT* TargetFrameName,
  630.         VARIANT* PostData, VARIANT* Headers, BOOL* Cancel) 
  631. {
  632.     ASSERT(V_VT(URL) == VT_BSTR);
  633.     ASSERT(V_VT(TargetFrameName) == VT_BSTR);
  634.     ASSERT(V_VT(PostData) == (VT_VARIANT | VT_BYREF));
  635.     ASSERT(V_VT(Headers) == VT_BSTR);
  636.     ASSERT(Cancel != NULL);
  637.  
  638.     USES_CONVERSION;
  639.  
  640.     VARIANT* vtPostedData = V_VARIANTREF(PostData);
  641.     CByteArray array;
  642.     if (V_VT(vtPostedData) & VT_ARRAY)
  643.     {
  644.         // must be a vector of bytes
  645.         ASSERT(vtPostedData->parray->cDims == 1 && vtPostedData->parray->cbElements == 1);
  646.  
  647.         vtPostedData->vt |= VT_UI1;
  648.         COleSafeArray safe(vtPostedData);
  649.  
  650.         DWORD dwSize = safe.GetOneDimSize();
  651.         LPVOID pVoid;
  652.         safe.AccessData(&pVoid);
  653.  
  654.         array.SetSize(dwSize);
  655.         LPBYTE lpByte = array.GetData();
  656.  
  657.         memcpy(lpByte, pVoid, dwSize);
  658.         safe.UnaccessData();
  659.     }
  660.     // make real parameters out of the notification
  661.  
  662.     CString strTargetFrameName(V_BSTR(TargetFrameName));
  663.     CString strURL = V_BSTR(URL);
  664.     CString strHeaders = V_BSTR(Headers);
  665.     DWORD nFlags = V_I4(Flags);
  666.  
  667.     // notify the user's class
  668.     OnBeforeNavigate2(strURL, nFlags, strTargetFrameName,
  669.         array, strHeaders, Cancel);
  670. }
  671.  
  672. void CHtmlView::DocumentComplete(LPDISPATCH pDisp, VARIANT* URL) 
  673. {
  674.     UNUSED_ALWAYS(pDisp);
  675.     ASSERT(V_VT(URL) == VT_BSTR);
  676.  
  677.     CString str(V_BSTR(URL));
  678.     OnDocumentComplete(str);
  679. }
  680.  
  681. /////////////////////////////////////////////////////////////////////////////
  682. // CHtmlView Events
  683.  
  684. void CHtmlView::OnProgressChange(long lProgress, long lProgressMax) 
  685. {
  686.     // user will override to handle this notification
  687.     UNUSED_ALWAYS(lProgress);
  688.     UNUSED_ALWAYS(lProgressMax);
  689. }
  690.  
  691. void CHtmlView::OnCommandStateChange(long lCommand, BOOL bEnable) 
  692. {
  693.     // user will override to handle this notification
  694.     UNUSED_ALWAYS(lCommand);
  695.     UNUSED_ALWAYS(bEnable);
  696. }
  697.  
  698. void CHtmlView::OnDownloadBegin() 
  699. {
  700.     // user will override to handle this notification
  701. }
  702.  
  703. void CHtmlView::OnDownloadComplete() 
  704. {
  705.     // user will override to handle this notification
  706. }
  707.  
  708. void CHtmlView::OnTitleChange(LPCTSTR lpszText) 
  709. {
  710.     // user will override to handle this notification
  711.     UNUSED_ALWAYS(lpszText);
  712. }
  713.  
  714. void CHtmlView::OnPropertyChange(LPCTSTR lpszProperty) 
  715. {
  716.     // user will override to handle this notification
  717.     UNUSED_ALWAYS(lpszProperty);
  718. }
  719.  
  720. void CHtmlView::OnNewWindow2(LPDISPATCH* ppDisp, BOOL* bCancel) 
  721. {
  722.     // default to continuing
  723.     bCancel = FALSE;
  724.  
  725.     // user will override to handle this notification
  726.     UNUSED_ALWAYS(ppDisp);
  727. }
  728.  
  729. void CHtmlView::OnDocumentComplete(LPCTSTR lpszURL) 
  730. {
  731.     // user will override to handle this notification
  732.     UNUSED_ALWAYS(lpszURL);
  733. }
  734.  
  735. void CHtmlView::OnQuit() 
  736. {
  737.     // user will override to handle this notification
  738. }
  739.  
  740. void CHtmlView::OnVisible(BOOL bVisible) 
  741. {
  742.     // user will override to handle this notification
  743.     UNUSED_ALWAYS(bVisible);
  744. }
  745.  
  746. void CHtmlView::OnToolBar(BOOL bToolBar) 
  747. {
  748.     // user will override to handle this notification
  749.     UNUSED_ALWAYS(bToolBar);
  750. }
  751.  
  752. void CHtmlView::OnMenuBar(BOOL bMenuBar) 
  753. {
  754.     // user will override to handle this notification
  755.     UNUSED_ALWAYS(bMenuBar);
  756. }
  757.  
  758. void CHtmlView::OnStatusBar(BOOL bStatusBar) 
  759. {
  760.     // user will override to handle this notification
  761.     UNUSED_ALWAYS(bStatusBar);
  762. }
  763.  
  764. void CHtmlView::OnFullScreen(BOOL bFullScreen) 
  765. {
  766.     // user will override to handle this notification
  767.     UNUSED_ALWAYS(bFullScreen);
  768. }
  769.  
  770. void CHtmlView::OnTheaterMode(BOOL bTheaterMode) 
  771. {
  772.     // user will override to handle this notification
  773.     UNUSED_ALWAYS(bTheaterMode);
  774. }
  775.  
  776. void CHtmlView::OnNavigateComplete2(LPCTSTR lpszURL)
  777. {
  778.     // user will override to handle this notification
  779.     UNUSED_ALWAYS(lpszURL);
  780. }
  781.  
  782. void CHtmlView::OnBeforeNavigate2(LPCTSTR lpszURL, DWORD nFlags,
  783.     LPCTSTR lpszTargetFrameName, CByteArray& baPostData,
  784.     LPCTSTR lpszHeaders, BOOL* bCancel)
  785. {
  786.     // default to continuing
  787.     bCancel = FALSE;
  788.  
  789.     // user will override to handle this notification
  790.     UNUSED_ALWAYS(lpszURL);
  791.     UNUSED_ALWAYS(nFlags);
  792.     UNUSED_ALWAYS(lpszTargetFrameName);
  793.     UNUSED_ALWAYS(baPostData);
  794.     UNUSED_ALWAYS(lpszHeaders);
  795. }
  796.  
  797. void CHtmlView::OnStatusTextChange(LPCTSTR pszText) 
  798. {
  799.     // try to set the status bar text via the frame
  800.  
  801.     CFrameWnd* pFrame = GetParentFrame();
  802.     if (pFrame != NULL)
  803.         pFrame->SetMessageText(pszText);
  804. }
  805.  
  806. /////////////////////////////////////////////////////////////////////////////
  807. // Inline function declarations expanded out-of-line
  808.  
  809. #ifndef _AFX_ENABLE_INLINES
  810.  
  811. // expand inlines for Html functions
  812. static char _szAfxHtmlInl[] = "afxhtml.inl";
  813. #undef THIS_FILE
  814. #define THIS_FILE _szAfxHtmlInl
  815. #define _AFXHTML_INLINE
  816. #include "afxhtml.inl"
  817.  
  818. #endif //!_AFX_ENABLE_INLINES
  819.  
  820. /////////////////////////////////////////////////////////////////////////////
  821. // Pre-startup code
  822.  
  823. #ifdef AFX_INIT_SEG
  824. #pragma code_seg(AFX_INIT_SEG)
  825. #endif
  826.  
  827. IMPLEMENT_DYNCREATE(CHtmlView, CFormView)
  828.  
  829.