view.cpp
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 25k
Category:

Windows Kernel

Development Platform:

Visual C++

  1. //+----------------------------------------------------------------------------
  2. //
  3. //  HTML property pages
  4. //
  5. //  Microsoft Windows
  6. //  Copyright (C) Microsoft Corporation, 1992 - 1997.
  7. //
  8. //  File:      view.cpp
  9. //
  10. //  Contents:  CPropView view object class implimentation
  11. //
  12. //  History:   22-Jan-97 EricB      Created.
  13. //
  14. //-----------------------------------------------------------------------------
  15. #include "pch.h"
  16. #include "view.h"
  17. #include "SiteObj.h"
  18. #pragma hdrstop
  19. #define WM_USER_DOINIT (WM_USER + 1000)
  20. #define WM_USER_CONNECTSINK (WM_USER + 1001)
  21. const TCHAR c_szCtrlClass[] = TEXT("HtmlPropViewClass");
  22. const TCHAR c_szCtrlName[]  = TEXT("HtmlPropViewName");
  23. //+----------------------------------------------------------------------------
  24. //
  25. //  Method:     CPropView::Create
  26. //
  27. //  Sysnopsis:  Creates an instance of the web view host window.
  28. //
  29. //-----------------------------------------------------------------------------
  30. HRESULT
  31. CPropView::Create(HWND hWndOwner, HINSTANCE hInstance, LPCTSTR pszUrl,
  32.                   CPropView ** ppObj)
  33. {
  34.     HRESULT hr;
  35.     WNDCLASS wc;
  36.     CPropView * pView = new CPropView;
  37.     if (pView == NULL)
  38.     {
  39.         TRACE(TEXT("CPropView::Create object allocation failedn"));
  40.         *ppObj = NULL;
  41.         return E_OUTOFMEMORY;
  42.     }
  43.     pView->m_hInst = hInstance;
  44.     pView->m_pszUrl = pszUrl;
  45.     //
  46.     // The class isn't registered, so register it.
  47.     //
  48.     wc.style         = 0;
  49.     wc.lpfnWndProc   = CPropView::StaticWndProc;
  50.     wc.cbClsExtra    = 0;
  51.     wc.cbWndExtra    = 0;
  52.     wc.hInstance     = hInstance;
  53.     wc.hIcon         = NULL;
  54.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW);
  55.     wc.hbrBackground = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
  56.     wc.lpszMenuName  = NULL;
  57.     wc.lpszClassName = c_szCtrlClass;
  58.     RegisterClass(&wc);
  59.     pView->m_hWnd = CreateWindow(c_szCtrlClass,
  60.                                  c_szCtrlName,
  61.                                  WS_CHILD,
  62.                                  0, 0, 0, 0,
  63.                                  hWndOwner,
  64.                                  (HMENU)1,           // child ID
  65.                                  hInstance,
  66.                                  pView);            // lpParam
  67.     if (pView->m_hWnd == NULL)
  68.     {
  69.         hr = HRESULT_FROM_WIN32(GetLastError());
  70.         TRACE(TEXT("CPropView::Create: CreateWindow failed with error 0x%xn"), hr);
  71.         delete pView;
  72.         *ppObj = NULL;
  73.         return hr;
  74.     }
  75.     ShowWindow(pView->m_hWnd, SW_SHOW);
  76.     UpdateWindow(pView->m_hWnd);
  77.     *ppObj = pView;
  78.     return S_OK;
  79. }
  80. //+----------------------------------------------------------------------------
  81. //
  82. //  Method:     CPropView::CPropView
  83. //
  84. //-----------------------------------------------------------------------------
  85. CPropView::CPropView() :
  86.     m_cRef(0),
  87.     m_hWnd(NULL),
  88.     m_pSite(NULL),
  89.     m_pszUrl(NULL),
  90.     m_pIOleIPActiveObject(NULL),
  91.     m_fCreated(FALSE)
  92. {
  93. #ifdef _DEBUG
  94.     strcpy(szClass, "CPropView");
  95. #endif
  96. }
  97. //+----------------------------------------------------------------------------
  98. //
  99. //  Method:     CPropView::~CPropView
  100. //
  101. //-----------------------------------------------------------------------------
  102. CPropView::~CPropView()
  103. {
  104.     ASSERT(m_cRef == 0);
  105. }
  106. //+----------------------------------------------------------------------------
  107. //
  108. //  Method:     CPropView::CreateDocObject
  109. //
  110. //  Sysnopsis:  Create and initialise the site for the HTML Doc Object.
  111. //
  112. //-----------------------------------------------------------------------------
  113. BOOL
  114. CPropView::CreateDocObject(LPCTSTR pchPath)
  115. {    
  116.     m_pSite = new CSite(m_hWnd, this);
  117.     if (NULL == m_pSite)
  118.     {
  119.         return FALSE;
  120.     }
  121.     m_pSite->AddRef();  //So we can free with Release
  122.     /*
  123.      * Now tell the site to create an object in it using the filename
  124.      * and the storage we opened.  The site will create a sub-storage
  125.      * for the doc object's use.
  126.      */
  127.     // Ask the Site to Create the Activex Document
  128.     //
  129.     if (!m_pSite->Create(pchPath))
  130.     {
  131.         return FALSE;
  132.     }
  133.     // We created the thing, now activate it with "Show"
  134.     //
  135.     m_pSite->Activate(OLEIVERB_SHOW);
  136.     // Send command to Trident to set it into Browse mode.
  137.     // This may not be needed since it appears to be the default.
  138.     //ExecCommand( IDM_BROWSEMODE );
  139.     // Post a message to connect the event sinks. This has to be done after
  140.     // Trident has fully loaded the URL, hence the post message.
  141.     // BUGBUG: it would be better to detect the load completed event on the
  142.     // document.
  143.     PostMessage(m_hWnd, WM_USER_CONNECTSINK, 0, 0);
  144.     
  145.     return TRUE;        
  146. }
  147. //+----------------------------------------------------------------------------
  148. //
  149. //  Method:     CPropView::IOleInPlaceFrame::GetWindow
  150. //
  151. //  Sysnopsis:  Retrieves the handle of the window associated with the object
  152. //              on which this interface is implemented.
  153. //
  154. //-----------------------------------------------------------------------------
  155. STDMETHODIMP
  156. CPropView::GetWindow(HWND * phWnd)
  157. {
  158.     *phWnd = m_hWnd;
  159.     return NOERROR;
  160. }
  161. //+----------------------------------------------------------------------------
  162. //
  163. //  Method:     CPropView::IOleInPlaceFrame::ContextSensitiveHelp
  164. //
  165. //  Sysnopsis:  Instructs the object on which this interface is implemented to
  166. //              enter or leave a context-sensitive help mode.
  167. //
  168. //-----------------------------------------------------------------------------
  169. STDMETHODIMP
  170. CPropView::ContextSensitiveHelp(BOOL fEnterMode)
  171. {
  172.     return NOERROR;
  173. }
  174. //+----------------------------------------------------------------------------
  175. //
  176. //  Method:     CPropView::IOleInPlaceFrame::GetBorder
  177. //
  178. //  Sysnopsis:  Returns the rectangle in which the container is willing to
  179. //              negotiate about an object's adornments.
  180. //
  181. //-----------------------------------------------------------------------------
  182. STDMETHODIMP
  183. CPropView::GetBorder(LPRECT prcBorder)
  184. {
  185.     if (NULL == prcBorder)
  186. {
  187.         return E_INVALIDARG;
  188. }
  189.     //We return all the client area space
  190.     //
  191.     GetClientRect(m_hWnd, prcBorder);
  192.     return NOERROR;
  193. }
  194. //+----------------------------------------------------------------------------
  195. //
  196. //  Method:     CPropView::IOleInPlaceFrame::RequestBorderSpace
  197. //
  198. //  Sysnopsis:  Asks the container if it can surrender the amount of space
  199. //              in pBW that the object would like for it's adornments.  The
  200. //              container does nothing but validate the spaces on this call.
  201. //
  202. //-----------------------------------------------------------------------------
  203. STDMETHODIMP
  204. CPropView::RequestBorderSpace(LPCBORDERWIDTHS /*pBW*/)
  205. {
  206.     // We have no border space restrictions
  207.     //
  208.     return NOERROR;
  209. }
  210. //+----------------------------------------------------------------------------
  211. //
  212. //  Method:     CPropView::IOleInPlaceFrame::SetBorderSpace
  213. //
  214. //  Sysnopsis:  Called when the object now officially requests that the
  215. //              container surrender border space it previously allowed
  216. //              in RequestBorderSpace.  The container should resize windows
  217. //              appropriately to surrender this space.
  218. //
  219. //-----------------------------------------------------------------------------
  220. STDMETHODIMP
  221. CPropView::SetBorderSpace(LPCBORDERWIDTHS /*pBW*/)
  222. {
  223. // We turn off the Trident UI so we ignore all of this.
  224.     //
  225.     return NOERROR;
  226. }
  227. //+----------------------------------------------------------------------------
  228. //
  229. //  Method:     CPropView::IOleInPlaceFrame::SetActiveObject
  230. //
  231. //  Sysnopsis:  Provides the container with the object's
  232. //              IOleInPlaceActiveObject pointer.
  233. //
  234. //-----------------------------------------------------------------------------
  235. STDMETHODIMP
  236. CPropView::SetActiveObject(LPOLEINPLACEACTIVEOBJECT pIIPActiveObj,
  237.                            LPCOLESTR /*pszObj*/)
  238. {
  239. // If we already have an active Object then release it.
  240.     if (NULL != m_pIOleIPActiveObject)
  241. {
  242.         m_pIOleIPActiveObject->Release();
  243. }
  244.     //NULLs m_pIOleIPActiveObject if pIIPActiveObj is NULL
  245.     m_pIOleIPActiveObject = pIIPActiveObj;
  246.     if (NULL != m_pIOleIPActiveObject)
  247. {
  248.         m_pIOleIPActiveObject->AddRef();
  249. m_pIOleIPActiveObject->GetWindow(&m_hWndObj);
  250. }
  251.     return NOERROR;
  252. }
  253. //+----------------------------------------------------------------------------
  254. //
  255. //  Method:     CPropView::IOleInPlaceFrame::InsertMenus
  256. //
  257. //  Sysnopsis:  Instructs the container to place its in-place menu items where
  258. //              necessary in the given menu and to fill in elements 0, 2, and 4
  259. //              of the OLEMENUGROUPWIDTHS array to indicate how many top-level
  260. //              items are in each group.
  261. //
  262. //-----------------------------------------------------------------------------
  263. STDMETHODIMP
  264. CPropView::InsertMenus(HMENU /*hMenu*/, LPOLEMENUGROUPWIDTHS /*pMGW*/)
  265. {
  266. // Trident Menus are  turned off so we don't expect any merging to go on.
  267.     //
  268. return E_NOTIMPL;
  269. }
  270. //+----------------------------------------------------------------------------
  271. //
  272. //  Method:     CPropView::IOleInPlaceFrame::SetMenu
  273. //
  274. //  Sysnopsis:  Instructs the container to replace whatever menu it's currently
  275. //              using with the given menu and to call OleSetMenuDescritor so
  276. //              OLE knows to whom to dispatch messages.
  277. //
  278. //-----------------------------------------------------------------------------
  279. STDMETHODIMP
  280. CPropView::SetMenu(HMENU /*hMenu*/, HOLEMENU /*hOLEMenu*/, HWND /*hWndObj*/)
  281. {
  282. // Trident Menus are  turned off so we don't expect any merging to go on.
  283.     //
  284. return E_NOTIMPL;
  285. }
  286. //+----------------------------------------------------------------------------
  287. //
  288. //  Method:     CPropView::IOleInPlaceFrame::RemoveMenus
  289. //
  290. //  Sysnopsis:  Asks the container to remove any menus it put into hMenu in
  291. //              InsertMenus.
  292. //
  293. //-----------------------------------------------------------------------------
  294. STDMETHODIMP
  295. CPropView::RemoveMenus(HMENU /*hMenu*/)
  296. {
  297. // Trident Menus are  turned off so we don't expect any merging to go on.
  298.     //
  299. return E_NOTIMPL;
  300. }
  301. //+----------------------------------------------------------------------------
  302. //
  303. //  Method:     CPropView::IOleInPlaceFrame::SetStatusText
  304. //
  305. //  Sysnopsis:  Asks the container to place some text in a status line, if one
  306. //              exists.  If the container does not have a status line it
  307. //              should return E_FAIL here in which case the object could
  308. //              display its own.
  309. //
  310. //-----------------------------------------------------------------------------
  311. STDMETHODIMP
  312. CPropView::SetStatusText(LPCOLESTR pszText)
  313. {
  314.     return E_FAIL;
  315. }
  316. //+----------------------------------------------------------------------------
  317. //
  318. //  Method:     CPropView::IOleInPlaceFrame::EnableModeless
  319. //
  320. //  Sysnopsis:  Instructs the container to show or hide any modeless popup
  321. //              windows that it may be using.
  322. //
  323. //-----------------------------------------------------------------------------
  324. STDMETHODIMP
  325. CPropView::EnableModeless(BOOL /*fEnable*/)
  326. {
  327.     return NOERROR;
  328. }
  329. //+----------------------------------------------------------------------------
  330. //
  331. //  Method:     CPropView::IOleInPlaceFrame::TranslateAccelerator
  332. //
  333. //  Sysnopsis:  When dealing with an in-place object from an EXE server, this
  334. //              is called to give the container a chance to process accelerators
  335. //              after the server has looked at the message.
  336. //
  337. // Parameters:
  338. //  pMSG            LPMSG for the container to examine.
  339. //  wID             WORD the identifier in the container's
  340. //                  accelerator table (from IOleInPlaceSite
  341. //                  ::GetWindowContext) for this message (OLE does
  342. //                  some translation before calling).
  343. //
  344. // Return Value:
  345. //  HRESULT         NOERROR if the keystroke was used,
  346. //                  S_FALSE otherwise.
  347. //
  348. //-----------------------------------------------------------------------------
  349. STDMETHODIMP
  350. CPropView::TranslateAccelerator(LPMSG /*pMSG*/, WORD /*wID*/)
  351. {
  352. // this could be forwarded to the top level frame
  353.     return S_FALSE;
  354. }
  355. //+----------------------------------------------------------------------------
  356. //
  357. //  Method:     CPropView::IOleCommandTarget:: QueryStatus
  358. //
  359. //  Sysnopsis:  
  360. //
  361. //-----------------------------------------------------------------------------
  362. STDMETHODIMP
  363. CPropView::QueryStatus(const GUID* pguidCmdGroup, ULONG cCmds,
  364.        OLECMD * prgCmds, OLECMDTEXT * pCmdText)
  365. {
  366.     if (pguidCmdGroup != NULL)
  367. {
  368. // It's a nonstandard group!!
  369.         return OLECMDERR_E_UNKNOWNGROUP;
  370. }
  371.     MSOCMD*     pCmd;
  372.     INT         c;
  373.     HRESULT     hr = S_OK;
  374.     // By default command text is NOT SUPPORTED.
  375.     if (pCmdText && (pCmdText->cmdtextf != OLECMDTEXTF_NONE))
  376. {
  377.         pCmdText->cwActual = 0;
  378. }
  379.     // Loop through each command in the ary, setting the status of each.
  380.     for (pCmd = prgCmds, c = cCmds; --c >= 0; pCmd++)
  381.     {
  382.         // By default command status is NOT SUPPORTED.
  383.         pCmd->cmdf = 0;
  384.         switch (pCmd->cmdID)
  385.         {
  386. case OLECMDID_SETPROGRESSTEXT:
  387. case OLECMDID_SETTITLE:
  388. pCmd->cmdf = OLECMDF_SUPPORTED;
  389. break;
  390.         }
  391.     }
  392.     return (hr);
  393. }
  394.         
  395. //+----------------------------------------------------------------------------
  396. //
  397. //  Method:     CPropView::IOleCommandTarget::Exec
  398. //
  399. //  Sysnopsis:  
  400. //
  401. //-----------------------------------------------------------------------------
  402. STDMETHODIMP
  403. CPropView::Exec(const GUID * pguidCmdGroup, DWORD nCmdID, DWORD /*nCmdexecopt*/,
  404.                 VARIANTARG * pvaIn, VARIANTARG * /*pvaOut*/)
  405. {
  406.     HRESULT hr = S_OK;
  407.     if (pguidCmdGroup == NULL)
  408.     {
  409.         //USES_CONVERSION;
  410. #ifdef YANK
  411.         switch (nCmdID)
  412.         {
  413. case OLECMDID_SAVE:
  414. // We don't support any save stuff!
  415. hr = OLECMDERR_E_NOTSUPPORTED;
  416. break;
  417. case OLECMDID_SETPROGRESSTEXT:
  418. if (pvaIn && V_VT(pvaIn) == VT_BSTR)
  419. {
  420. CFrameWnd* pFrame = GetTopLevelFrame();
  421. if (pFrame != NULL)
  422. {
  423. pFrame->SetMessageText(OLE2T(V_BSTR(pvaIn)));
  424. }
  425. }
  426. else
  427. {
  428. hr = OLECMDERR_E_NOTSUPPORTED;
  429. }
  430. break;
  431. case OLECMDID_UPDATECOMMANDS:
  432. // MFC updates stuff in it's idle so we don't bother forcing the update here
  433. hr = OLECMDERR_E_NOTSUPPORTED;
  434. break;
  435. case OLECMDID_SETTITLE:
  436. if (pvaIn && V_VT(pvaIn) == VT_BSTR)
  437. {
  438. CCarrotDoc* pDoc = GetDocument();
  439. ASSERT_VALID(pDoc);
  440. pDoc->SetTitle(OLE2T(V_BSTR(pvaIn)));
  441. }
  442. else
  443. {
  444. hr = OLECMDERR_E_NOTSUPPORTED;
  445. }
  446. break;
  447. default:
  448. hr = OLECMDERR_E_NOTSUPPORTED;
  449. break;
  450.         }
  451. #endif // YANK
  452.         hr = OLECMDERR_E_NOTSUPPORTED;
  453.     }
  454.     else
  455.     {
  456.         hr = OLECMDERR_E_UNKNOWNGROUP;
  457.     }
  458.     return hr;
  459. }
  460. //+----------------------------------------------------------------------------
  461. // Helper functions on IOleCommandTarget of the object
  462. //-----------------------------------------------------------------------------
  463. //+----------------------------------------------------------------------------
  464. //
  465. //  Method:     CPropView::GetCommandStatus
  466. //
  467. //  Sysnopsis:  
  468. //
  469. //-----------------------------------------------------------------------------
  470. DWORD
  471. CPropView::GetCommandStatus(ULONG ucmdID)
  472. {
  473. DWORD dwReturn = 0;
  474. if (m_pSite != NULL)
  475. {
  476. LPOLECOMMANDTARGET pCommandTarget = m_pSite->GetCommandTarget();
  477. if (pCommandTarget != NULL)
  478. {
  479. HRESULT hr = S_OK;
  480. MSOCMD msocmd;
  481. msocmd.cmdID = ucmdID;
  482. msocmd.cmdf  = 0;
  483. hr = pCommandTarget->QueryStatus(&CMDSETID_Forms3, 1, &msocmd, NULL);
  484. dwReturn = msocmd.cmdf;
  485. }
  486. }
  487. return dwReturn;
  488. }
  489. //+----------------------------------------------------------------------------
  490. //
  491. //  Method:     CPropView::ExecCommand
  492. //
  493. //  Sysnopsis:  
  494. //
  495. //-----------------------------------------------------------------------------
  496. void
  497. CPropView::ExecCommand(ULONG ucmdID)
  498. {
  499. if (m_pSite != NULL)
  500. {
  501. LPOLECOMMANDTARGET pCommandTarget = m_pSite->GetCommandTarget();
  502. if (pCommandTarget != NULL)
  503. {
  504. HRESULT hr = S_OK;
  505. hr = pCommandTarget->Exec(&CMDSETID_Forms3,
  506. ucmdID,
  507. MSOCMDEXECOPT_DONTPROMPTUSER,
  508. NULL,
  509. NULL);
  510. }
  511. }
  512. }
  513. //+----------------------------------------------------------------------------
  514. // CPropView message handlers
  515. //-----------------------------------------------------------------------------
  516. //+----------------------------------------------------------------------------
  517. //
  518. //  Method:     CPropView::OnCreate
  519. //
  520. //-----------------------------------------------------------------------------
  521. int CPropView::OnCreate(HWND hWnd) 
  522. {
  523.     //
  524.     // Post a message to complete the initialization.
  525.     //
  526.     PostMessage(hWnd, WM_USER_DOINIT, 0, 0);
  527. return 0;
  528. }
  529. //+----------------------------------------------------------------------------
  530. //
  531. //  Method:     CPropView::OnDoInit
  532. //
  533. //-----------------------------------------------------------------------------
  534. LRESULT
  535. CPropView::OnDoInit()
  536. {
  537.     // create the Trident ActiveX Document
  538.     //
  539.     if (m_fCreated == FALSE)
  540.     {
  541.         m_fCreated = TRUE;
  542.         if (!CreateDocObject(m_pszUrl))
  543.         {
  544.             MessageBox(m_hWnd, TEXT("Invalid URL"), TEXT("Error"), MB_ICONEXCLAMATION);
  545.         }
  546.         TRACE(TEXT("CPropView::OnDoInit: calling OnSizen"));
  547.         OnSize();
  548.     }
  549.     return 0;
  550. }
  551. //+----------------------------------------------------------------------------
  552. //
  553. //  Method:     CPropView::OnSize
  554. //
  555. //  Sysnopsis:  Tell the site to tell the object.
  556. //
  557. //-----------------------------------------------------------------------------
  558. void
  559. CPropView::OnSize(void)
  560. {
  561. if (NULL != m_pSite)
  562. {
  563.         TRACE(TEXT("CPropView::OnSize: calling m_pSite->UpdateObjectRectsn"));
  564.      m_pSite->UpdateObjectRects();
  565. }
  566. }
  567. //+----------------------------------------------------------------------------
  568. //
  569. //  Method:     CPropView::OnSetFocus
  570. //
  571. //-----------------------------------------------------------------------------
  572. void
  573. CPropView::OnSetFocus(void)
  574. {
  575. // Give the focus to the ActiveX Document window
  576.     if (m_hWndObj != NULL)
  577. {
  578. ::SetFocus(m_hWndObj);
  579. }
  580. }
  581. //+----------------------------------------------------------------------------
  582. //
  583. //  Method:     CPropView::OnPaint
  584. //
  585. //-----------------------------------------------------------------------------
  586. void
  587. CPropView::OnPaint() 
  588. {
  589. #ifdef YANK
  590.     if (m_pSite != NULL)
  591.     {
  592.         HDC hDC = GetDC(m_hWnd);
  593.         m_pSite->Draw(hDC);
  594.         ReleaseDC(m_hWnd, hDC);
  595.     }
  596. #endif // YANK
  597. }
  598. //+----------------------------------------------------------------------------
  599. //
  600. //  Method:     CPropView::OnDestroy
  601. //
  602. //  Sysnopsis:  On view window shutdown, close the site object.
  603. //
  604. //-----------------------------------------------------------------------------
  605. void
  606. CPropView::OnDestroy(void)
  607. {
  608.     if (m_pSite != NULL)
  609.     {
  610.         CSite *pSite = m_pSite; //Prevents reentry
  611.         m_pSite = NULL;
  612.         pSite->Close(); // Closes object
  613.         ReleaseInterface(pSite);
  614.     }
  615. }
  616. //+----------------------------------------------------------------------------
  617. //
  618. //  Method:     CPropView::StaticWndProc
  619. //
  620. //  Sysnopsis:  static window procedure
  621. //
  622. //-----------------------------------------------------------------------------
  623. long CALLBACK
  624. CPropView::StaticWndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  625. {
  626.     CPropView *pThis = (CPropView *)GetWindowLong(hWnd, GWL_USERDATA);
  627.     if (uMsg == WM_CREATE)
  628.     {
  629.         LPCREATESTRUCT pcs = (LPCREATESTRUCT)lParam;
  630.         pThis = (CPropView *) pcs->lpCreateParams;
  631.         SetWindowLong(hWnd, GWL_USERDATA, (LONG)pThis);
  632.     }
  633.     if (pThis != NULL)
  634.     {
  635.         return pThis->WndProc(hWnd, uMsg, wParam, lParam);
  636.     }
  637.     else
  638.     {
  639.         return DefWindowProc(hWnd, uMsg, wParam, lParam);
  640.     }
  641. }
  642. //+----------------------------------------------------------------------------
  643. //
  644. //  Method:     CPropView::WndProc
  645. //
  646. //  Sysnopsis:  per-instance window proc
  647. //
  648. //-----------------------------------------------------------------------------
  649. LRESULT
  650. CPropView::WndProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
  651. {
  652.     LRESULT lr;
  653.     switch (uMsg)
  654.     {
  655.     case WM_CREATE:
  656.         lr = OnCreate(hWnd);
  657.         return lr;
  658.     case WM_USER_DOINIT:
  659.         return OnDoInit();
  660.     case WM_USER_CONNECTSINK:
  661.         m_pSite->ConnectSink();
  662.         return 0;
  663.     case WM_SETFOCUS:
  664.         OnSetFocus();
  665.         break;
  666. //    case WM_SHOWWINDOW:
  667. //    case WM_MOVE:
  668. //    case WM_WINDOWPOSCHANGED:
  669.     case WM_SIZE:
  670.         OnSize();
  671.         break;
  672.     case WM_DESTROY:
  673.         OnDestroy();
  674.         break;
  675.     default:
  676.         return DefWindowProc(hWnd, uMsg, wParam, lParam);
  677.     }
  678.     return DefWindowProc(hWnd, uMsg, wParam, lParam);
  679. }
  680. //+----------------------------------------------------------------------------
  681. //
  682. //  Method:     CPropView::IUnknown::QueryInterface
  683. //
  684. //-----------------------------------------------------------------------------
  685. STDMETHODIMP
  686. CPropView::QueryInterface(REFIID riid, void **ppv)
  687. {
  688.     *ppv = NULL;
  689.     if (IID_IUnknown == riid || IID_IOleInPlaceUIWindow == riid ||
  690.         IID_IOleWindow == riid || IID_IOleInPlaceFrame == riid)
  691. {
  692.         *ppv = (IOleInPlaceFrame *)this;
  693. }
  694. if (IID_IOleCommandTarget == riid)
  695. {
  696.         *ppv = (IOleCommandTarget *)this;
  697. }
  698.     if (NULL != *ppv)
  699.     {
  700.         ((LPUNKNOWN)*ppv)->AddRef();
  701.         return NOERROR;
  702.     }
  703.     return E_NOINTERFACE;
  704. }
  705. //+----------------------------------------------------------------------------
  706. //
  707. //  Method:     CPropView::IUnknown::AddRef
  708. //
  709. //-----------------------------------------------------------------------------
  710. STDMETHODIMP_(ULONG)
  711. CPropView::AddRef(void)
  712. {
  713.     return ++m_cRef;
  714. }
  715. //+----------------------------------------------------------------------------
  716. //
  717. //  Method:     CPropView::IUnknown::Release
  718. //
  719. //-----------------------------------------------------------------------------
  720. STDMETHODIMP_(ULONG)
  721. CPropView::Release(void)
  722. {
  723. // Debug check to see we don't fall below 0
  724. ASSERT(m_cRef != 0);
  725.     return --m_cRef;
  726.     if (0 != --m_cRef)
  727.     {
  728.         return m_cRef;
  729.     }
  730.     delete this;
  731.     return 0;
  732. }
  733. //+----------------------------------------------------------------------------
  734. //
  735. //  Method:     CPropView::OnApply
  736. //
  737. //  Sysnopsis:  On Apply button press, call the DoApply script subroutine on
  738. //              the loaded HTML page.
  739. //
  740. //-----------------------------------------------------------------------------
  741. void 
  742. CPropView::OnApply(void)
  743. {
  744.     // Note, GetObjectUnknown doesn't increment the refcount, so a release
  745.     // is not needed.
  746.     //
  747.     IUnknown * pUnk = m_pSite->GetObjectUnknown();
  748.     if (pUnk == NULL)
  749.     {
  750.         TRACE(TEXT("CPropView::OnApply: couldn't get Trident IUnknown!n"));
  751.         return;
  752.     }
  753.     HRESULT hr = S_OK;
  754.     IHTMLDocument * pHTMLDocument;
  755.     hr = pUnk->QueryInterface(IID_IHTMLDocument, (void **)&pHTMLDocument);
  756.     if (FAILED(hr))
  757.     {
  758.         TRACE(TEXT("CPropView::OnApply: QI(IID_IHTMLDocument) failed with error 0x%xn"), hr);
  759.         return;
  760.     }
  761.     IDispatch * pDispatch;
  762.     hr = pHTMLDocument->get_Script(&pDispatch);
  763.     if (FAILED(hr))
  764.     {
  765.         pHTMLDocument->Release();
  766.         TRACE(TEXT("CPropView::OnApply: get_Script failed with error 0x%xn"), hr);
  767.         return;
  768.     }
  769.     OLECHAR * pszName = L"DoApply";
  770.     DISPID dispid;
  771.     hr = pDispatch->GetIDsOfNames(IID_NULL, &pszName, 1, LOCALE_SYSTEM_DEFAULT,
  772.                                   &dispid);
  773.     if (FAILED(hr))
  774.     {
  775.         pDispatch->Release();
  776.         pHTMLDocument->Release();
  777.         if (hr == DISP_E_UNKNOWNNAME)
  778.         {
  779.             //
  780.             // No DoApply sub on the page.
  781.             //
  782.             return;
  783.         }
  784.         TRACE(TEXT("CPropView::OnApply: GetIdsOfName failed with error 0x%xn"), hr);
  785.         return;
  786.     }
  787.     DISPPARAMS dispparamsNoArgs = {NULL, NULL, 0, 0};
  788.     hr = pDispatch->Invoke(dispid, IID_NULL, LOCALE_SYSTEM_DEFAULT,
  789.                            DISPATCH_METHOD, &dispparamsNoArgs, NULL, NULL,
  790.                            NULL);
  791.     if (FAILED(hr))
  792.     {
  793.         TRACE(TEXT("CPropView::OnApply: Invoke failed with error 0x%xn"), hr);
  794.     }
  795.     pDispatch->Release();
  796.     pHTMLDocument->Release();
  797. }