Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1736 lines
48 KiB

  1. /////////////////////////////////////////////////////////////////////////////
  2. //
  3. //
  4. // BLHost.cpp - CBLHost implementation
  5. /////////////////////////////////////////////////////////////////////////////
  6. #include "pch.hxx"
  7. #include <shlobj.h>
  8. #include <shlobjp.h>
  9. #include <windowsx.h>
  10. #include <shlwapi.h>
  11. #include <shlwapip.h>
  12. #include <ieguidp.h>
  13. #include <mshtml.h>
  14. #include <mshtmdid.h>
  15. #include <ExDispID.h>
  16. #include "bactrl.h"
  17. #include "baprop.h"
  18. #include "baui.h"
  19. #include "msoert.h"
  20. #include "BLHost.h"
  21. #include "hotlinks.h"
  22. #include "Guid.h"
  23. #include "resource.h"
  24. // Insert your server name
  25. #define STARTUP_URL "http://localhost/BlFrame.htm"
  26. #define SEARCH_PANE_INDICATOR "#_mysearch"
  27. const int c_cxBorder = 0;
  28. const int c_cyBorder = 0;
  29. const int c_cxTextBorder = 4;
  30. const int c_cyTextBorder = 2;
  31. const int c_cyClose = 3;
  32. const int c_cySplit = 4;
  33. const int c_cxSplit = 3;
  34. const int c_cxTextSpace = 1;
  35. const int c_cxTriangle = 14;
  36. const int c_cyIEDelta = 5;
  37. // --------------------------------------------------------------------------------
  38. // SAFECAST - Insures that a cast is valid, otherwise it won't compile
  39. // --------------------------------------------------------------------------------
  40. #define SAFECAST(_src, _type) (((_type)(_src)==(_src)?0:0), (_type)(_src))
  41. LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam);
  42. HMENU LoadPopupMenu(UINT id);
  43. HRESULT MenuUtil_EnablePopupMenu(HMENU hPopup, CIEMsgAb* pTarget);
  44. static const TBBUTTON c_tbIECont[] =
  45. {
  46. { I_IMAGENONE, ID_CONT_FILE, TBSTATE_ENABLED, BTNS_AUTOSIZE | BTNS_WHOLEDROPDOWN | BTNS_SHOWTEXT, {0,0}, 0, 0 },
  47. { I_IMAGENONE, ID_SHOWALLCONTACT, TBSTATE_ENABLED, BTNS_AUTOSIZE | BTNS_DROPDOWN | BTNS_SHOWTEXT, {0, 0}, 0, 1}
  48. };
  49. CBLHost::CBLHost()
  50. : _cRef(1),
  51. _hwndParent(NULL),
  52. m_hWnd(NULL),
  53. m_hwndContact(NULL),
  54. _dwViewMode(0),
  55. _dwBandID(0),
  56. _dwWBCookie(0),
  57. _pSite(NULL),
  58. m_pUnkSite(NULL)
  59. {
  60. HDC hdc;
  61. InterlockedIncrement(&g_cDllRefCount);
  62. m_pIMsgrAB = NULL;
  63. m_hbr3DFace = CreateSolidBrush(GetSysColor(COLOR_3DFACE));
  64. m_hbrStaticText = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  65. m_hbr3DHighFace = CreateSolidBrush(GetSysColor(COLOR_3DLIGHT));
  66. LOGFONT lf;
  67. // Figure out which font to use
  68. SystemParametersInfo(SPI_GETICONTITLELOGFONT, sizeof(LOGFONT), &lf, FALSE);
  69. // Create the fonts
  70. m_hFont = CreateFontIndirect(&lf);
  71. lf.lfWeight = FW_BOLD;
  72. m_hBoldFont = CreateFontIndirect(&lf);
  73. lf.lfUnderline = (BYTE) TRUE;
  74. m_hUnderlineFont = CreateFontIndirect(&lf);
  75. m_cyTitleBar = 32;
  76. m_fHighlightIndicator = FALSE;
  77. m_fHighlightPressed = FALSE;
  78. m_fButtonPressed = FALSE;
  79. m_fViewMenuPressed = FALSE;
  80. m_fButtonHighLight = FALSE;
  81. m_fShowLoginPart = FALSE;
  82. m_fStateChange = FALSE;
  83. m_TextHeight = 0;
  84. ZeroMemory(&m_rcTitleButton, sizeof(RECT));
  85. ZeroMemory(&m_rcTextButton, sizeof(RECT));
  86. m_hWndLogin = NULL;
  87. // m_hWndClick = NULL;
  88. m_fStrsAdded = FALSE;
  89. m_lStrOffset = 0;
  90. // Link colors
  91. if(!LookupLinkColors(&m_clrLink, NULL))
  92. m_clrLink = 0;
  93. if(!LookupLinkColors(NULL, &m_clrBack))
  94. m_clrBack = RGB(255, 255, 255);
  95. }
  96. CBLHost::~CBLHost()
  97. {
  98. Cleanup();
  99. }
  100. ///////////////////////////////////////////////////////////////////////////
  101. //
  102. // IUnknown Methods
  103. //
  104. ///////////////////////////////////////////////////////////////////////////
  105. //
  106. // CBLHost::QueryInterface()
  107. //
  108. ///////////////////////////////////////////////////////////////////////////
  109. STDMETHODIMP CBLHost::QueryInterface(REFIID riid, LPVOID* ppvObject)
  110. {
  111. *ppvObject= NULL;
  112. if (IsEqualIID(riid, IID_IUnknown))
  113. {
  114. *ppvObject = this;
  115. }
  116. else if (IsEqualIID(riid, IID_IOleWindow) || IsEqualIID(riid, IID_IDockingWindow))
  117. {
  118. *ppvObject = static_cast<IDockingWindow*>(this);
  119. }
  120. else if (IsEqualIID(riid, IID_IInputObject))
  121. {
  122. *ppvObject = static_cast<IInputObject*>(this);
  123. }
  124. else if (IsEqualIID(riid, IID_IObjectWithSite))
  125. {
  126. *ppvObject = static_cast<IObjectWithSite*>(this);
  127. }
  128. else if (IsEqualIID(riid, IID_IDeskBand))
  129. {
  130. *ppvObject = static_cast<IDeskBand*>(this);
  131. }
  132. else if (IsEqualIID(riid, IID_IPersist))
  133. {
  134. *ppvObject = static_cast<IPersist*>(this);
  135. }
  136. else if (IsEqualIID(riid, IID_IPersistStream))
  137. {
  138. *ppvObject = static_cast<IPersistStream*>(this);
  139. }
  140. else if (IsEqualIID(riid, IID_IContextMenu))
  141. {
  142. *ppvObject = static_cast<IContextMenu*>(this);
  143. }
  144. else if (IsEqualIID(riid, IID_IOleClientSite))
  145. {
  146. *ppvObject = static_cast<IOleClientSite*>(this);
  147. }
  148. else if (IsEqualIID(riid, IID_IOleInPlaceSite))
  149. {
  150. *ppvObject = static_cast<IOleInPlaceSite*>(this);
  151. }
  152. else if (IsEqualIID(riid, IID_IOleControlSite))
  153. {
  154. *ppvObject = static_cast<IOleControlSite*>(this);
  155. }
  156. else if (IsEqualIID(riid, IID_IOleCommandTarget))
  157. {
  158. *ppvObject = static_cast<IOleCommandTarget*>(this);
  159. }
  160. else if (IsEqualIID(riid, IID_IDispatch) || IsEqualIID(riid, DIID_DWebBrowserEvents2))
  161. {
  162. *ppvObject = static_cast<IDispatch*>(this);
  163. }
  164. if (*ppvObject)
  165. {
  166. static_cast<LPUNKNOWN>(*ppvObject)->AddRef();
  167. return S_OK;
  168. }
  169. return E_NOINTERFACE;
  170. }
  171. ///////////////////////////////////////////////////////////////////////////
  172. //
  173. // CBLHost::AddRef()
  174. //
  175. ///////////////////////////////////////////////////////////////////////////
  176. STDMETHODIMP_(ULONG) CBLHost::AddRef()
  177. {
  178. return (ULONG)InterlockedIncrement(&_cRef);
  179. }
  180. ///////////////////////////////////////////////////////////////////////////
  181. //
  182. // CBLHost::Release()
  183. //
  184. ///////////////////////////////////////////////////////////////////////////
  185. STDMETHODIMP_(ULONG) CBLHost::Release()
  186. {
  187. if (0 == InterlockedDecrement(&_cRef))
  188. {
  189. delete this;
  190. return 0;
  191. }
  192. return (ULONG)_cRef;
  193. }
  194. ///////////////////////////////////////////////////////////////////////////
  195. //
  196. // IOleWindow Methods
  197. //
  198. ///////////////////////////////////////////////////////////////////////////
  199. //
  200. // CBLHost::GetWindow()
  201. //
  202. ///////////////////////////////////////////////////////////////////////////
  203. STDMETHODIMP CBLHost::GetWindow(HWND *phwnd)
  204. {
  205. *phwnd = m_hWnd;
  206. return S_OK;
  207. }
  208. ///////////////////////////////////////////////////////////////////////////
  209. //
  210. // CBLHost::ContextSensitiveHelp()
  211. //
  212. ///////////////////////////////////////////////////////////////////////////
  213. STDMETHODIMP CBLHost::ContextSensitiveHelp(BOOL fEnterMode)
  214. {
  215. return E_NOTIMPL;
  216. }
  217. ///////////////////////////////////////////////////////////////////////////
  218. //
  219. // IDockingWindow Methods
  220. //
  221. ///////////////////////////////////////////////////////////////////////////
  222. //
  223. // CBLHost::ShowDW()
  224. //
  225. ///////////////////////////////////////////////////////////////////////////
  226. STDMETHODIMP CBLHost::ShowDW(BOOL fShow)
  227. {
  228. if (m_hWnd)
  229. {
  230. //
  231. // Hide or show the window depending on
  232. // the value of the fShow parameter.
  233. //
  234. if (fShow)
  235. ShowWindow(m_hWnd, SW_SHOW);
  236. else
  237. ShowWindow(m_hWnd, SW_HIDE);
  238. }
  239. AddButtons(fShow);
  240. return S_OK;
  241. }
  242. void CBLHost::UpdateButtonArray(TBBUTTON *ptbDst, const TBBUTTON *ptbSrc, int ctb, LONG_PTR lStrOffset)
  243. {
  244. memcpy(ptbDst, ptbSrc, ctb*sizeof(TBBUTTON));
  245. if (lStrOffset == -1)
  246. {
  247. // handle failure case
  248. for (int i = 0; i < ctb; i++)
  249. ptbDst[i].iString = 0;
  250. }
  251. else
  252. {
  253. for (int i = 0; i < ctb; i++)
  254. ptbDst[i].iString += lStrOffset;
  255. }
  256. }
  257. void CBLHost::AddButtons(BOOL fAdd)
  258. {
  259. IExplorerToolbar* piet;
  260. _ASSERT(m_pUnkSite);
  261. if (SUCCEEDED(m_pUnkSite->QueryInterface(IID_IExplorerToolbar, (void**)&piet)))
  262. {
  263. if (fAdd)
  264. {
  265. piet->SetCommandTarget((IUnknown*)SAFECAST(this, IOleCommandTarget*), &CLSID_BLHost, 0);
  266. if (!m_fStrsAdded)
  267. {
  268. LONG_PTR cbOffset;
  269. piet->AddString(&CLSID_BLHost, g_hLocRes, idsToolBar, &cbOffset);
  270. m_lStrOffset = cbOffset;
  271. m_fStrsAdded = TRUE;
  272. }
  273. // piet->SetImageList(&CGID_SearchBand, _himlNormal, _himlHot, NULL); // set image list
  274. TBBUTTON tbCont[ARRAYSIZE(c_tbIECont)];
  275. UpdateButtonArray(tbCont, c_tbIECont, ARRAYSIZE(c_tbIECont), m_lStrOffset);
  276. CIEMsgAb *pMsgrAb = (CIEMsgAb *) m_pIMsgrAB;
  277. if(pMsgrAb && pMsgrAb->HideViewMenu())
  278. tbCont[1].fsState = TBSTATE_HIDDEN;
  279. piet->AddButtons(&CLSID_BLHost, ARRAYSIZE(tbCont), tbCont);
  280. }
  281. else
  282. piet->SetCommandTarget(NULL, NULL, 0);
  283. piet->Release();
  284. }
  285. }
  286. ///////////////////////////////////////////////////////////////////////////
  287. //
  288. // CBLHost::CloseDW()
  289. //
  290. ///////////////////////////////////////////////////////////////////////////
  291. STDMETHODIMP CBLHost::CloseDW(DWORD dwReserved)
  292. {
  293. ShowDW(FALSE);
  294. if (IsWindow(m_hWnd))
  295. DestroyWindow(m_hWnd);
  296. m_hWnd = NULL;
  297. return S_OK;
  298. }
  299. ///////////////////////////////////////////////////////////////////////////
  300. //
  301. // CBLHost::ResizeBorderDW()
  302. //
  303. ///////////////////////////////////////////////////////////////////////////
  304. STDMETHODIMP CBLHost::ResizeBorderDW(LPCRECT prcBorder, IUnknown* punkToolbarSite,
  305. BOOL fReserved)
  306. {
  307. // This method is never called for Band Objects.
  308. return E_NOTIMPL;
  309. }
  310. ///////////////////////////////////////////////////////////////////////////
  311. //
  312. // IInputObject Methods
  313. //
  314. ///////////////////////////////////////////////////////////////////////////
  315. //
  316. // CBLHost::UIActivateIO()
  317. //
  318. ///////////////////////////////////////////////////////////////////////////
  319. STDMETHODIMP CBLHost::UIActivateIO(BOOL fActivate, LPMSG lpMsg)
  320. {
  321. _ASSERT(m_pIMsgrAB);
  322. HRESULT hr = E_FAIL;
  323. if (m_pIMsgrAB)
  324. hr = ((CIEMsgAb*) m_pIMsgrAB)->UIActivateIO(fActivate, lpMsg);
  325. return hr;
  326. }
  327. ///////////////////////////////////////////////////////////////////////////
  328. //
  329. // CBLHost::HasFocusIO()
  330. //
  331. // If this window or one of its decendants has the focus, return S_OK. Return
  332. // S_FALSE if we don't have the focus.
  333. //
  334. ///////////////////////////////////////////////////////////////////////////
  335. STDMETHODIMP CBLHost::HasFocusIO(void)
  336. {
  337. HWND hwnd = GetFocus();
  338. HWND hwndTmp;
  339. ((CIEMsgAb *) m_pIMsgrAB)->GetWindow(&hwndTmp);
  340. // See if the focus has been set to any of the children
  341. //
  342. while (hwnd && hwndTmp)
  343. {
  344. if (hwnd == hwndTmp)
  345. return S_OK;
  346. hwndTmp = ::GetWindow(hwndTmp, GW_CHILD);
  347. }
  348. return S_FALSE;
  349. }
  350. ///////////////////////////////////////////////////////////////////////////
  351. //
  352. // CBLHost::TranslateAcceleratorIO()
  353. //
  354. // If the accelerator is translated, return S_OK or S_FALSE otherwise.
  355. //
  356. ///////////////////////////////////////////////////////////////////////////
  357. STDMETHODIMP CBLHost::TranslateAcceleratorIO(LPMSG pMsg)
  358. {
  359. _RPT0(_CRT_WARN, "TranslateAcceleratorIO\n");
  360. return E_NOTIMPL;
  361. }
  362. ///////////////////////////////////////////////////////////////////////////
  363. //
  364. // IObjectWithSite Methods
  365. //
  366. ///////////////////////////////////////////////////////////////////////////
  367. //
  368. // CBLHost::SetSite()
  369. //
  370. ///////////////////////////////////////////////////////////////////////////
  371. STDMETHODIMP CBLHost::SetSite(IUnknown* pUnkSite)
  372. {
  373. TEXTMETRIC tm;
  374. HRESULT hr = S_OK;
  375. CIEMsgAb *pMsgrAb = NULL;
  376. // Assert(FALSE);
  377. // If punkSite is not NULL, a new site is being set.
  378. if (pUnkSite)
  379. {
  380. //
  381. // If a IInputObjectSite pointer is being held, release it.
  382. //
  383. if (_pSite)
  384. {
  385. _pSite->Release();
  386. _pSite = NULL;
  387. }
  388. if(m_pUnkSite)
  389. m_pUnkSite->Release();
  390. m_pUnkSite = pUnkSite;
  391. // Get the parent window.
  392. IOleWindow* pOleWindow;
  393. if (SUCCEEDED(pUnkSite->QueryInterface(IID_IOleWindow,
  394. (LPVOID*)&pOleWindow)))
  395. {
  396. pOleWindow->GetWindow(&_hwndParent);
  397. pOleWindow->Release();
  398. }
  399. _ASSERT(_hwndParent);
  400. if (!_hwndParent)
  401. return E_FAIL;
  402. if (!RegisterAndCreateWindow())
  403. return E_FAIL;
  404. // Get and keep the IInputObjectSite pointer.
  405. hr = pUnkSite->QueryInterface(IID_IInputObjectSite,
  406. (LPVOID*)&_pSite);
  407. _ASSERT(SUCCEEDED(hr));
  408. hr = CreateIEMsgAbCtrl(&m_pIMsgrAB);
  409. /* // Create and initialize the WebBrowser control that we are hosting.
  410. hr = CoCreateInstance(CLSID_MsgrAb, NULL, CLSCTX_INPROC,
  411. IID_IMsgrAb, (LPVOID*)&m_pMsgrAB);
  412. // Get the rectangle of the client area*/
  413. _ASSERT(m_hWnd);
  414. // Get the metrics of this font
  415. HDC hdc = GetDC(m_hWnd);
  416. SelectFont(hdc, m_hFont);
  417. GetTextMetrics(hdc, &tm);
  418. if(!ANSI_AthLoadString(idsTitleMenu, m_szTitleMenu, ARRAYSIZE(m_szTitleMenu)))
  419. m_szTitleMenu[0] = '\0';
  420. if(!ANSI_AthLoadString(idsButtonText, m_szButtonText, ARRAYSIZE(m_szButtonText)))
  421. m_szButtonText[0] = '\0';
  422. // if(!AthLoadString(idsLoginText, m_szInstallText, ARRAYSIZE(m_szInstallText)))
  423. // m_szInstallText[0] = '\0';
  424. if(!AthLoadString(idsClickText, m_wszClickText, ARRAYSIZE(m_wszClickText)))
  425. m_wszClickText[0] = L'\0';
  426. if(!AthLoadString(idsAttemptText, m_wszAttemptText, ARRAYSIZE(m_wszAttemptText)))
  427. m_wszAttemptText[0] = L'\0';
  428. if(!AthLoadString(idsWaitText, m_wszWaitText, ARRAYSIZE(m_wszWaitText)))
  429. m_wszWaitText[0] = L'\0';
  430. // Calculate the height
  431. m_cyTitleBar = 0; //tm.tmHeight + (2 * c_cyBorder) + (2 * c_cyTextBorder) + c_cyIEDelta;
  432. m_TextHeight = tm.tmHeight;
  433. pMsgrAb = (CIEMsgAb *) m_pIMsgrAB;
  434. // Calculate the height
  435. RECT rc = {2 * c_cxBorder, 2 * c_cyBorder, 0, m_cyTitleBar - c_cyBorder};
  436. SIZE s;
  437. GetTextExtentPoint32(hdc, m_szTitleMenu, lstrlen(m_szTitleMenu), &s);
  438. m_rcTitleButton = rc;
  439. m_rcTitleButton.right = c_cxTriangle + (2 * c_cxTextBorder) + s.cx + (2 * c_cxBorder);
  440. RECT rcClient = { 0, 0, 0/*100*/, 0/*500*/ };
  441. GetClientRect(m_hWnd, &rcClient);
  442. m_hwndContact = pMsgrAb->CreateControlWindow(m_hWnd, rcClient);
  443. // m_pIMsgrAB->Release(); // CreateControl.. add reference
  444. // Calculate "Show All" button rect
  445. m_rcTextButton.left = m_rcTitleButton.right + c_cxTextSpace;
  446. m_rcTextButton.top = m_rcTitleButton.top;
  447. m_rcTextButton.bottom = m_rcTitleButton.bottom;
  448. GetTextExtentPoint32(hdc, m_szButtonText, lstrlen(m_szButtonText), &s);
  449. m_rcTextButton.right = c_cxTriangle + m_rcTextButton.left + (2 * c_cxTextBorder) + s.cx + (2 * c_cxBorder);
  450. m_hWndLogin = CreateWindow(_T("Button"), _T("_Login"),
  451. WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | BS_OWNERDRAW /*| ES_MULTILINE | ES_READONLY*/,
  452. 0, 0, 0, 0, m_hWnd, (HMENU) ID_LOGIN_MESSENGER, g_hLocRes, NULL);
  453. SendMessage(m_hWndLogin, WM_SETFONT, (WPARAM) m_hUnderlineFont, MAKELPARAM(TRUE, 0));
  454. /* SendMessage(m_hWndLogin, WM_SETFONT, (WPARAM) m_hFont, MAKELPARAM(TRUE, 0));
  455. m_hWndClick = CreateWindow(_T("Button"), _T("_Click"),
  456. WS_CHILD | WS_TABSTOP | WS_CLIPSIBLINGS | BS_OWNERDRAW,
  457. 0, 0, 0, 0, m_hWnd, (HMENU) ID_LOGIN_MESSENGER, g_hLocRes, NULL);
  458. SendMessage(m_hWndClick, WM_SETFONT, (WPARAM) m_hUnderlineFont, MAKELPARAM(TRUE, 0)); */
  459. }
  460. if(pMsgrAb)
  461. hr = pMsgrAb->SetSite(pUnkSite);
  462. return hr;
  463. }
  464. ///////////////////////////////////////////////////////////////////////////
  465. //
  466. // CBLHost::GetSite()
  467. //
  468. ///////////////////////////////////////////////////////////////////////////
  469. STDMETHODIMP CBLHost::GetSite(REFIID riid, void** ppvSite)
  470. {
  471. *ppvSite = NULL;
  472. if (_pSite)
  473. return _pSite->QueryInterface(riid, ppvSite);
  474. return E_FAIL;
  475. }
  476. ///////////////////////////////////////////////////////////////////////////
  477. //
  478. // IDeskBand implementation
  479. //
  480. ///////////////////////////////////////////////////////////////////////////
  481. //
  482. // CBLHost::GetBandInfo()
  483. //
  484. ///////////////////////////////////////////////////////////////////////////
  485. STDMETHODIMP CBLHost::GetBandInfo(DWORD dwBandID,
  486. DWORD dwViewMode,
  487. DESKBANDINFO* pdbi)
  488. {
  489. if (pdbi)
  490. {
  491. _dwBandID = dwBandID;
  492. _dwViewMode = dwViewMode;
  493. if (pdbi->dwMask & DBIM_MINSIZE)
  494. {
  495. pdbi->ptMinSize.x = MIN_SIZE_X;
  496. pdbi->ptMinSize.y = MIN_SIZE_Y;
  497. }
  498. if (pdbi->dwMask & DBIM_MAXSIZE)
  499. {
  500. pdbi->ptMaxSize.x = -1;
  501. pdbi->ptMaxSize.y = -1;
  502. }
  503. if (pdbi->dwMask & DBIM_INTEGRAL)
  504. {
  505. pdbi->ptIntegral.x = 1;
  506. pdbi->ptIntegral.y = 1;
  507. }
  508. if (pdbi->dwMask & DBIM_ACTUAL)
  509. {
  510. pdbi->ptActual.x = 0;
  511. pdbi->ptActual.y = 0;
  512. }
  513. if (pdbi->dwMask & DBIM_TITLE)
  514. {
  515. if(!AthLoadString(idsButtontext, pdbi->wszTitle, 256))
  516. pdbi->wszTitle[0] = L'\0';
  517. }
  518. if (pdbi->dwMask & DBIM_MODEFLAGS)
  519. pdbi->dwModeFlags = DBIMF_VARIABLEHEIGHT;
  520. if (pdbi->dwMask & DBIM_BKCOLOR)
  521. {
  522. // Use the default background color by removing this flag.
  523. pdbi->dwMask &= ~DBIM_BKCOLOR;
  524. }
  525. return S_OK;
  526. }
  527. return E_INVALIDARG;
  528. }
  529. ///////////////////////////////////////////////////////////////////////////
  530. //
  531. // IPersistStream Methods
  532. //
  533. // This is only supported to allow the desk band to be dropped on the
  534. // desktop and to prevent multiple instances of the desk band from showing
  535. // up in the context menu. This desk band doesn't actually persist any data.
  536. //
  537. ///////////////////////////////////////////////////////////////////////////
  538. //
  539. // CBLHost::GetClassID()
  540. //
  541. ///////////////////////////////////////////////////////////////////////////
  542. STDMETHODIMP CBLHost::GetClassID(LPCLSID pClassID)
  543. {
  544. *pClassID = CLSID_BLHost;
  545. return S_OK;
  546. }
  547. ///////////////////////////////////////////////////////////////////////////
  548. //
  549. // CBLHost::IsDirty()
  550. //
  551. ///////////////////////////////////////////////////////////////////////////
  552. STDMETHODIMP CBLHost::IsDirty(void)
  553. {
  554. return S_FALSE;
  555. }
  556. ///////////////////////////////////////////////////////////////////////////
  557. //
  558. // CBLHost::Load()
  559. //
  560. ///////////////////////////////////////////////////////////////////////////
  561. STDMETHODIMP CBLHost::Load(LPSTREAM pStream)
  562. {
  563. return S_OK;
  564. }
  565. ///////////////////////////////////////////////////////////////////////////
  566. //
  567. // CBLHost::Save()
  568. //
  569. ///////////////////////////////////////////////////////////////////////////
  570. STDMETHODIMP CBLHost::Save(LPSTREAM pStream, BOOL fClearDirty)
  571. {
  572. return S_OK;
  573. }
  574. ///////////////////////////////////////////////////////////////////////////
  575. //
  576. // CBLHost::GetSizeMax()
  577. //
  578. ///////////////////////////////////////////////////////////////////////////
  579. STDMETHODIMP CBLHost::GetSizeMax(ULARGE_INTEGER *pul)
  580. {
  581. return E_NOTIMPL;
  582. }
  583. ///////////////////////////////////////////////////////////////////////////
  584. //
  585. // IContextMenu Methods
  586. //
  587. ///////////////////////////////////////////////////////////////////////////
  588. //
  589. // CBLHost::QueryContextMenu()
  590. //
  591. ///////////////////////////////////////////////////////////////////////////
  592. STDMETHODIMP CBLHost::QueryContextMenu(HMENU hmenu,
  593. UINT indexMenu,
  594. UINT idCmdFirst,
  595. UINT idCmdLast,
  596. UINT uFlags)
  597. {
  598. if (!(CMF_DEFAULTONLY & uFlags))
  599. {
  600. InsertMenu(hmenu, indexMenu, MF_STRING | MF_BYPOSITION,
  601. idCmdFirst + IDM_REFRESH, TEXT("&Refresh"));
  602. InsertMenu(hmenu, indexMenu + 1, MF_STRING | MF_BYPOSITION,
  603. idCmdFirst + IDM_OPENINWINDOW, TEXT("&Open in Window"));
  604. return MAKE_HRESULT(SEVERITY_SUCCESS, 0,
  605. USHORT(IDM_OPENINWINDOW + 1));
  606. }
  607. return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0));
  608. }
  609. ///////////////////////////////////////////////////////////////////////////
  610. //
  611. // CBLHost::InvokeCommand()
  612. //
  613. ///////////////////////////////////////////////////////////////////////////
  614. STDMETHODIMP CBLHost::InvokeCommand(LPCMINVOKECOMMANDINFO lpici)
  615. {
  616. return E_NOTIMPL;
  617. }
  618. ///////////////////////////////////////////////////////////////////////////
  619. //
  620. // CBLHost::GetCommandString()
  621. //
  622. ///////////////////////////////////////////////////////////////////////////
  623. STDMETHODIMP CBLHost::GetCommandString(UINT_PTR idCmd, UINT uType, UINT* pwReserved,
  624. LPSTR pszName, UINT cchMax)
  625. {
  626. HRESULT hr = E_INVALIDARG;
  627. switch(uType)
  628. {
  629. case GCS_HELPTEXT:
  630. switch(idCmd)
  631. {
  632. case IDM_REFRESH:
  633. StrCpyN(pszName, TEXT("Refreshes the search window"), cchMax);
  634. hr = NOERROR;
  635. break;
  636. case IDM_OPENINWINDOW:
  637. StrCpyN(pszName, TEXT("Open a new instance of the Internet Explorer window"), cchMax);
  638. hr = NOERROR;
  639. break;
  640. }
  641. break;
  642. case GCS_VERB:
  643. switch(idCmd)
  644. {
  645. case IDM_REFRESH:
  646. StrCpyN(pszName, TEXT("Refresh"), cchMax);
  647. hr = NOERROR;
  648. break;
  649. case IDM_OPENINWINDOW:
  650. StrCpyN(pszName, TEXT("Open in Window"), cchMax);
  651. hr = NOERROR;
  652. break;
  653. }
  654. break;
  655. case GCS_VALIDATE:
  656. hr = NOERROR;
  657. break;
  658. }
  659. return hr;
  660. }
  661. ///////////////////////////////////////////////////////////////////////////
  662. //
  663. // IOleClientSite Methods
  664. //
  665. ///////////////////////////////////////////////////////////////////////////
  666. //
  667. // CBLHost::SaveObject()
  668. //
  669. ///////////////////////////////////////////////////////////////////////////
  670. STDMETHODIMP CBLHost::SaveObject()
  671. {
  672. return E_NOTIMPL;
  673. }
  674. ///////////////////////////////////////////////////////////////////////////
  675. //
  676. // CBLHost::GetMoniker()
  677. //
  678. ///////////////////////////////////////////////////////////////////////////
  679. STDMETHODIMP CBLHost::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER* ppmk)
  680. {
  681. return E_NOTIMPL;
  682. }
  683. ///////////////////////////////////////////////////////////////////////////
  684. //
  685. // CBLHost::GetContainer()
  686. //
  687. ///////////////////////////////////////////////////////////////////////////
  688. STDMETHODIMP CBLHost::GetContainer(LPOLECONTAINER* ppContainer)
  689. {
  690. *ppContainer = NULL;
  691. return E_NOINTERFACE;
  692. }
  693. ///////////////////////////////////////////////////////////////////////////
  694. //
  695. // CBLHost::ShowObject()
  696. //
  697. ///////////////////////////////////////////////////////////////////////////
  698. STDMETHODIMP CBLHost::ShowObject()
  699. {
  700. return S_OK;
  701. }
  702. ///////////////////////////////////////////////////////////////////////////
  703. //
  704. // CBLHost::OnShowWindow()
  705. //
  706. ///////////////////////////////////////////////////////////////////////////
  707. STDMETHODIMP CBLHost::OnShowWindow(BOOL fShow)
  708. {
  709. return S_OK;
  710. }
  711. ///////////////////////////////////////////////////////////////////////////
  712. //
  713. // CBLHost::RequestNewObjectLayout()
  714. //
  715. ///////////////////////////////////////////////////////////////////////////
  716. STDMETHODIMP CBLHost::RequestNewObjectLayout()
  717. {
  718. return E_NOTIMPL;
  719. }
  720. ///////////////////////////////////////////////////////////////////////////
  721. //
  722. // IOleInPlaceSite Methods
  723. //
  724. ///////////////////////////////////////////////////////////////////////////
  725. //
  726. // CBLHost::CanInPlaceActivate()
  727. //
  728. ///////////////////////////////////////////////////////////////////////////
  729. STDMETHODIMP CBLHost::CanInPlaceActivate(void)
  730. {
  731. return S_OK;
  732. }
  733. ///////////////////////////////////////////////////////////////////////////
  734. //
  735. // CBLHost::OnInPlaceActivate()
  736. //
  737. ///////////////////////////////////////////////////////////////////////////
  738. STDMETHODIMP CBLHost::OnInPlaceActivate(void)
  739. {
  740. return S_OK;
  741. }
  742. ///////////////////////////////////////////////////////////////////////////
  743. //
  744. // CBLHost::OnUIActivate()
  745. //
  746. ///////////////////////////////////////////////////////////////////////////
  747. STDMETHODIMP CBLHost::OnUIActivate(void)
  748. {
  749. return S_OK;
  750. }
  751. ///////////////////////////////////////////////////////////////////////////
  752. //
  753. // CBLHost::GetWindowContext()
  754. //
  755. ///////////////////////////////////////////////////////////////////////////
  756. STDMETHODIMP CBLHost::GetWindowContext(IOleInPlaceFrame** ppFrame, IOleInPlaceUIWindow** ppIIPUIWin,
  757. LPRECT lprcPosRect, LPRECT lprcClipRect,
  758. LPOLEINPLACEFRAMEINFO lpFrameInfo)
  759. {
  760. *ppFrame = NULL;
  761. *ppIIPUIWin = NULL;
  762. GetClientRect(m_hWnd, lprcPosRect);
  763. GetClientRect(m_hWnd, lprcClipRect);
  764. return S_OK;
  765. }
  766. ///////////////////////////////////////////////////////////////////////////
  767. //
  768. // CBLHost::Scroll()
  769. //
  770. ///////////////////////////////////////////////////////////////////////////
  771. STDMETHODIMP CBLHost::Scroll(SIZE scrollExtent)
  772. {
  773. return E_NOTIMPL;
  774. }
  775. ///////////////////////////////////////////////////////////////////////////
  776. //
  777. // CBLHost::OnUIDeactivate()
  778. //
  779. ///////////////////////////////////////////////////////////////////////////
  780. STDMETHODIMP CBLHost::OnUIDeactivate(BOOL fUndoable)
  781. {
  782. return E_NOTIMPL;
  783. }
  784. ///////////////////////////////////////////////////////////////////////////
  785. //
  786. // CBLHost::OnInPlaceDeactivate()
  787. //
  788. ///////////////////////////////////////////////////////////////////////////
  789. STDMETHODIMP CBLHost::OnInPlaceDeactivate(void)
  790. {
  791. return E_NOTIMPL;
  792. }
  793. ///////////////////////////////////////////////////////////////////////////
  794. //
  795. // CBLHost::DiscardUndoState()
  796. //
  797. ///////////////////////////////////////////////////////////////////////////
  798. STDMETHODIMP CBLHost::DiscardUndoState(void)
  799. {
  800. return E_NOTIMPL;
  801. }
  802. ///////////////////////////////////////////////////////////////////////////
  803. //
  804. // CBLHost::DeactivateAndUndo()
  805. //
  806. ///////////////////////////////////////////////////////////////////////////
  807. STDMETHODIMP CBLHost::DeactivateAndUndo(void)
  808. {
  809. return E_NOTIMPL;
  810. }
  811. ///////////////////////////////////////////////////////////////////////////
  812. //
  813. // CBLHost::OnPosRectChange()
  814. //
  815. ///////////////////////////////////////////////////////////////////////////
  816. STDMETHODIMP CBLHost::OnPosRectChange(LPCRECT lprcPosRect)
  817. {
  818. return S_OK;
  819. }
  820. ///////////////////////////////////////////////////////////////////////////
  821. //
  822. // IOleControlSite Methods
  823. //
  824. ///////////////////////////////////////////////////////////////////////////
  825. //
  826. // CBLHost::OnControlInfoChanged()
  827. //
  828. ///////////////////////////////////////////////////////////////////////////
  829. STDMETHODIMP CBLHost::OnControlInfoChanged(void)
  830. {
  831. return E_NOTIMPL;
  832. }
  833. ///////////////////////////////////////////////////////////////////////////
  834. //
  835. // CBLHost::LockInPlaceActive()
  836. //
  837. ///////////////////////////////////////////////////////////////////////////
  838. STDMETHODIMP CBLHost::LockInPlaceActive(BOOL fLock)
  839. {
  840. return E_NOTIMPL;
  841. }
  842. ///////////////////////////////////////////////////////////////////////////
  843. //
  844. // CBLHost::GetExtendedControl()
  845. //
  846. ///////////////////////////////////////////////////////////////////////////
  847. STDMETHODIMP CBLHost::GetExtendedControl(LPDISPATCH* ppDisp)
  848. {
  849. return E_NOTIMPL;
  850. }
  851. ///////////////////////////////////////////////////////////////////////////
  852. //
  853. // CBLHost::TransformCoords()
  854. //
  855. ///////////////////////////////////////////////////////////////////////////
  856. STDMETHODIMP CBLHost::TransformCoords(POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags)
  857. {
  858. return E_NOTIMPL;
  859. }
  860. ///////////////////////////////////////////////////////////////////////////
  861. //
  862. // CBLHost::TranslateAccelerator()
  863. //
  864. ///////////////////////////////////////////////////////////////////////////
  865. STDMETHODIMP CBLHost::TranslateAccelerator(LPMSG lpMsg, DWORD grfModifiers)
  866. {
  867. return E_NOTIMPL;
  868. }
  869. ///////////////////////////////////////////////////////////////////////////
  870. //
  871. // CBLHost::OnFocus()
  872. //
  873. ///////////////////////////////////////////////////////////////////////////
  874. STDMETHODIMP CBLHost::OnFocus(BOOL fGotFocus)
  875. {
  876. _RPT1(_CRT_WARN, "OnFocus: %s\n", fGotFocus ? "True" : "False");
  877. if (_pSite)
  878. _pSite->OnFocusChangeIS(static_cast<IInputObject*>(this), fGotFocus);
  879. return S_OK;
  880. }
  881. ///////////////////////////////////////////////////////////////////////////
  882. //
  883. // CBLHost::ShowPropertyFrame()
  884. //
  885. ///////////////////////////////////////////////////////////////////////////
  886. STDMETHODIMP CBLHost::ShowPropertyFrame(void)
  887. {
  888. return E_NOTIMPL;
  889. }
  890. ///////////////////////////////////////////////////////////////////////////
  891. //
  892. // Private Methods
  893. //
  894. ///////////////////////////////////////////////////////////////////////////
  895. //
  896. // CBLHost::GetTypeInfoCount()
  897. //
  898. ///////////////////////////////////////////////////////////////////////////
  899. STDMETHODIMP CBLHost::GetTypeInfoCount(UINT* pctinfo)
  900. {
  901. return E_NOTIMPL;
  902. }
  903. ///////////////////////////////////////////////////////////////////////////
  904. //
  905. // CBLHost::GetTypeInfo()
  906. //
  907. ///////////////////////////////////////////////////////////////////////////
  908. STDMETHODIMP CBLHost::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo)
  909. {
  910. return E_NOTIMPL;
  911. }
  912. ///////////////////////////////////////////////////////////////////////////
  913. //
  914. // CBLHost::GetIDsOfNames()
  915. //
  916. ///////////////////////////////////////////////////////////////////////////
  917. STDMETHODIMP CBLHost::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames,
  918. LCID lcid,DISPID* rgDispId)
  919. {
  920. return E_NOTIMPL;
  921. }
  922. ///////////////////////////////////////////////////////////////////////////
  923. //
  924. // CBLHost::Invoke()
  925. //
  926. ///////////////////////////////////////////////////////////////////////////
  927. STDMETHODIMP CBLHost::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags,
  928. DISPPARAMS* pDispParams, VARIANT* pVarResult,
  929. EXCEPINFO* pExcepInfo, UINT* puArgErr)
  930. {
  931. if (IID_NULL != riid)
  932. return DISP_E_UNKNOWNINTERFACE;
  933. if (!pDispParams)
  934. return DISP_E_PARAMNOTOPTIONAL;
  935. static bool sbIsAnchor = false;
  936. switch (dispIdMember)
  937. {
  938. //
  939. // The parameters for this DISPID:
  940. // [0]: New status bar text - VT_BSTR
  941. //
  942. case DISPID_STATUSTEXTCHANGE:
  943. if (pDispParams->cArgs && pDispParams->rgvarg[0].vt != VT_BSTR)
  944. {
  945. *puArgErr = 0;
  946. return DISP_E_TYPEMISMATCH;
  947. }
  948. break;
  949. default:
  950. return DISP_E_MEMBERNOTFOUND;
  951. }
  952. return S_OK;
  953. }
  954. ///////////////////////////////////////////////////////////////////////////
  955. //
  956. // Private Methods
  957. //
  958. ///////////////////////////////////////////////////////////////////////////
  959. //
  960. // CBLHost::WndProc()
  961. //
  962. ///////////////////////////////////////////////////////////////////////////
  963. LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMessage,
  964. WPARAM wParam, LPARAM lParam)
  965. {
  966. if (uMessage == WM_NCCREATE)
  967. {
  968. LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam;
  969. SetWindowLongPtr(hWnd, GWLP_USERDATA, (LONG_PTR)lpcs->lpCreateParams);
  970. }
  971. CBLHost* pThis = reinterpret_cast<CBLHost*>(
  972. GetWindowLongPtr(hWnd, GWLP_USERDATA));
  973. if (pThis)
  974. return pThis->WndProc(hWnd, uMessage, wParam, lParam);
  975. else
  976. return DefWindowProc(hWnd, uMessage, wParam, lParam);
  977. }
  978. LRESULT CBLHost::WndProc(HWND hWnd, UINT uMessage,
  979. WPARAM wParam, LPARAM lParam)
  980. {
  981. switch (uMessage)
  982. {
  983. case WM_NCCREATE:
  984. {
  985. // Set the window handle
  986. m_hWnd = hWnd;
  987. }
  988. break;
  989. case WM_PAINT:
  990. return OnPaint();
  991. case WM_MOUSEMOVE:
  992. return OnMouseMove(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), (UINT) wParam);
  993. case WM_TIMER:
  994. OnTimer((UINT) wParam);
  995. return(0);
  996. case WM_LBUTTONDOWN:
  997. OnLButtonDown(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), (UINT) wParam);
  998. return(0);
  999. case WM_LBUTTONUP:
  1000. OnLButtonUp(GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam), (UINT) wParam);
  1001. return(0);
  1002. case WM_COMMAND:
  1003. return OnCommand(wParam, lParam);
  1004. case WM_SETFOCUS:
  1005. return OnSetFocus();
  1006. case WM_KILLFOCUS:
  1007. return OnKillFocus();
  1008. case WM_DRAWITEM:
  1009. return OnDrawItem(wParam, lParam);
  1010. case WM_SIZE:
  1011. return OnSize();
  1012. // case WM_DESTROY:
  1013. //
  1014. // If you decided to implement the Open in Window context
  1015. // menu item and you are using Internet Explorer 5,
  1016. // be careful. WM_DESTROY will get sent to the band for
  1017. // each window. You'll want to keep a count of the number
  1018. // of windows open and only call Cleanup() if WM_DESTROY
  1019. // is meant for the first window.
  1020. //
  1021. // Cleanup();
  1022. // break;
  1023. case WM_LOCAL_STATUS_CHANGED:
  1024. m_fStateChange = TRUE;
  1025. return OnSize();
  1026. case WM_MSGR_LOGRESULT:
  1027. case WM_MSGR_LOGOFF:
  1028. case WM_MSGR_SHUTDOWN:
  1029. m_fStateChange = FALSE;
  1030. return OnSize();
  1031. return 0;
  1032. }
  1033. return DefWindowProc(hWnd, uMessage, wParam, lParam);
  1034. }
  1035. LRESULT CBLHost::OnDrawItem(WPARAM wParam, LPARAM lParam)
  1036. {
  1037. LPDRAWITEMSTRUCT pdis = (LPDRAWITEMSTRUCT) lParam;
  1038. RECT rc = pdis->rcItem;
  1039. WCHAR wszStr[RESSTRMAX];
  1040. HBRUSH hbr3DFace = NULL;
  1041. StrCpyNW(wszStr, m_fStateChange ? m_wszWaitText : m_wszClickText, ARRAYSIZE(wszStr));
  1042. hbr3DFace = CreateSolidBrush(GetSysColor(COLOR_WINDOW));
  1043. FillRect(pdis->hDC, &(pdis->rcItem), hbr3DFace);
  1044. SetBkColor(pdis->hDC, GetSysColor(COLOR_WINDOW));
  1045. DeleteObject(hbr3DFace);
  1046. if(!m_fStateChange)
  1047. {
  1048. SetTextColor(pdis->hDC, m_clrLink);
  1049. SelectFont(pdis->hDC, m_hUnderlineFont);
  1050. }
  1051. else
  1052. SelectFont(pdis->hDC, m_hBoldFont);
  1053. DrawTextW(pdis->hDC, wszStr, -1, &rc, DT_WORDBREAK | DT_VCENTER | DT_CENTER );
  1054. return 0;
  1055. }
  1056. void CBLHost::OnLButtonUp(int x, int y, UINT keyFlags)
  1057. {
  1058. #if 0
  1059. POINT pt = {x, y};
  1060. if(PtInRect(&m_rcTextButton, pt))
  1061. {
  1062. ((CIEMsgAb*)m_pIMsgrAB)->Exec(NULL, ID_SHOWALLCONTACT, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  1063. m_fButtonPressed = FALSE;
  1064. InvalidateRect(m_hWnd, &m_rcTextButton, TRUE);
  1065. }
  1066. #endif
  1067. }
  1068. void CBLHost::OnLButtonDown(int x, int y, UINT keyFlags)
  1069. {
  1070. }
  1071. void CBLHost::OnTimer(UINT id)
  1072. {
  1073. #if 0
  1074. // RECT rcClient;
  1075. POINT pt;
  1076. DWORD dw;
  1077. dw = GetMessagePos();
  1078. pt.x = LOWORD(dw);
  1079. pt.y = HIWORD(dw);
  1080. ScreenToClient(m_hWnd, &pt);
  1081. if (id == IDT_PANETIMER)
  1082. {
  1083. // GetClientRect(m_hWnd, &rcClient);
  1084. // No need to handle mouse in client area, OnMouseMove will catch this. We
  1085. // only need to catch the mouse moving out of the client area.
  1086. if (!(PtInRect(&m_rcTitleButton, pt) || PtInRect(&m_rcTextButton, pt)) && !m_fHighlightPressed)
  1087. {
  1088. KillTimer(m_hWnd, IDT_PANETIMER);
  1089. m_fHighlightIndicator = FALSE;
  1090. m_fButtonHighLight = FALSE;
  1091. m_fButtonPressed = FALSE;
  1092. InvalidateRect(m_hWnd, &m_rcTitleButton, TRUE);
  1093. InvalidateRect(m_hWnd, &m_rcTextButton, TRUE);
  1094. }
  1095. }
  1096. #endif
  1097. }
  1098. LRESULT CBLHost::OnMouseMove(int x, int y, UINT keyFlags)
  1099. {
  1100. #if 0
  1101. POINT pt = {x, y};
  1102. if (m_fHighlightIndicator != PtInRect(&m_rcTitleButton, pt))
  1103. {
  1104. m_fHighlightIndicator = !m_fHighlightIndicator;
  1105. if(m_fHighlightIndicator)
  1106. m_fButtonHighLight = FALSE;
  1107. InvalidateRect(m_hWnd, &m_rcTitleButton, TRUE);
  1108. InvalidateRect(m_hWnd, &m_rcTextButton, TRUE);
  1109. if (m_fHighlightIndicator)
  1110. SetTimer(m_hWnd, IDT_PANETIMER, ELAPSE_MOUSEOVERCHECK, NULL);
  1111. else
  1112. KillTimer(m_hWnd, IDT_PANETIMER);
  1113. }
  1114. else if (m_fButtonHighLight != PtInRect(&m_rcTextButton, pt))
  1115. {
  1116. m_fButtonHighLight = !m_fButtonHighLight;
  1117. if(m_fButtonHighLight)
  1118. m_fHighlightIndicator = FALSE;
  1119. InvalidateRect(m_hWnd, &m_rcTextButton, TRUE);
  1120. InvalidateRect(m_hWnd, &m_rcTitleButton, TRUE);
  1121. if (m_fButtonHighLight)
  1122. SetTimer(m_hWnd, IDT_PANETIMER, ELAPSE_MOUSEOVERCHECK, NULL);
  1123. else
  1124. KillTimer(m_hWnd, IDT_PANETIMER);
  1125. }
  1126. #endif
  1127. return(S_OK);
  1128. }
  1129. ///////////////////////////////////////////////////////////////////////////
  1130. //
  1131. // CBLHost::OnPaint()
  1132. //
  1133. ///////////////////////////////////////////////////////////////////////////
  1134. LRESULT CBLHost::OnPaint(void)
  1135. {
  1136. PAINTSTRUCT ps;
  1137. // Start painting
  1138. HDC hdc = BeginPaint(m_hWnd, &ps);
  1139. SelectFont(hdc, m_hFont);
  1140. EndPaint(m_hWnd, &ps);
  1141. return 0;
  1142. }
  1143. ///////////////////////////////////////////////////////////////////////////
  1144. //
  1145. // CBLHost::OnCommand()
  1146. //
  1147. ///////////////////////////////////////////////////////////////////////////
  1148. LRESULT CBLHost::OnCommand(WPARAM wParam, LPARAM lParam)
  1149. {
  1150. _RPT0(_CRT_WARN, "CBLHost::OnCommand\n");
  1151. UINT id = LOWORD(wParam);
  1152. if(id == ID_LOGIN_MESSENGER && !((CIEMsgAb*)m_pIMsgrAB)->IsMessengerInstalled())
  1153. {
  1154. // redirect browser pane
  1155. IServiceProvider* psp;
  1156. // if invoked from within a browser reuse it, else open a new browser
  1157. HRESULT hres = IUnknown_QueryService(m_pUnkSite, SID_STopLevelBrowser, IID_IServiceProvider, (LPVOID*)&psp);
  1158. if (SUCCEEDED(hres))
  1159. {
  1160. IWebBrowser2* pwb2 = NULL;
  1161. hres = psp->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (LPVOID*)&pwb2);
  1162. psp->Release();
  1163. if (SUCCEEDED(hres))
  1164. {
  1165. // we don't care about the error here
  1166. VARIANT varEmpty = {0};
  1167. pwb2->Navigate(L"http://www.microsoft.com/isapi/redir.dll?prd=ie&Plcid=0x0409&Pver=6.0&Clcid=0x0409&Ar=getmms", &varEmpty, &varEmpty, &varEmpty, &varEmpty);
  1168. pwb2->Release();
  1169. }
  1170. }
  1171. return(hres);
  1172. }
  1173. if((id == ID_LOGIN_MESSENGER) && m_fStateChange)
  1174. return 0; // id = ID_LOGOFF_MESSENGER;
  1175. if(m_pIMsgrAB)
  1176. ((CIEMsgAb*)m_pIMsgrAB)->Exec(NULL, id, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  1177. return 0;
  1178. }
  1179. ///////////////////////////////////////////////////////////////////////////
  1180. //
  1181. // CBLHost::FocusChange()
  1182. //
  1183. ///////////////////////////////////////////////////////////////////////////
  1184. void CBLHost::FocusChange(BOOL fFocus)
  1185. {
  1186. _RPT1(_CRT_WARN, "FocusChange: %s\n", fFocus ? "True" : "False");
  1187. // Inform the input object site that the focus has changed
  1188. //
  1189. if (_pSite)
  1190. _pSite->OnFocusChangeIS(static_cast<IDockingWindow*>(this), fFocus);
  1191. }
  1192. ///////////////////////////////////////////////////////////////////////////
  1193. //
  1194. // CBLHost::SetFocus()
  1195. //
  1196. ///////////////////////////////////////////////////////////////////////////
  1197. LRESULT CBLHost::OnSetFocus(void)
  1198. {
  1199. _RPT0(_CRT_WARN, "OnSetFocus\n");
  1200. FocusChange(TRUE);
  1201. return 0;
  1202. }
  1203. ///////////////////////////////////////////////////////////////////////////
  1204. //
  1205. // CBLHost::OnKillFocus()
  1206. //
  1207. ///////////////////////////////////////////////////////////////////////////
  1208. LRESULT CBLHost::OnKillFocus(void)
  1209. {
  1210. _RPT0(_CRT_WARN, "OnKillFocus\n");
  1211. FocusChange(FALSE);
  1212. return 0;
  1213. }
  1214. ///////////////////////////////////////////////////////////////////////////
  1215. //
  1216. // CBLHost::OnSize()
  1217. //
  1218. ///////////////////////////////////////////////////////////////////////////
  1219. LRESULT CBLHost::OnSize(void)
  1220. {
  1221. HRESULT hr = E_FAIL;
  1222. if (m_pIMsgrAB)
  1223. {
  1224. RECT rcClient;
  1225. HWND hWndTmp = NULL;
  1226. GetClientRect(m_hWnd, &rcClient);
  1227. CIEMsgAb *pMsgrAb = (CIEMsgAb *) m_pIMsgrAB;
  1228. if(pMsgrAb)
  1229. {
  1230. pMsgrAb->GetWindow(&hWndTmp);
  1231. m_fShowLoginPart = !pMsgrAb->DontShowMessenger();
  1232. if(m_fShowLoginPart && m_hWndLogin /* && m_hWndClick*/)
  1233. {
  1234. SetWindowPos(m_hWndLogin, NULL, rcClient.left, m_cyTitleBar, rcClient.right,
  1235. m_TextHeight*2,
  1236. SWP_NOACTIVATE | SWP_NOZORDER);
  1237. SendMessage(m_hWndLogin, WM_SETFONT, (WPARAM) m_hUnderlineFont, MAKELPARAM(TRUE, 0));
  1238. SetWindowTextW(m_hWndLogin, m_fStateChange ? m_wszAttemptText : m_wszClickText);
  1239. SetWindowPos(hWndTmp, NULL, 0, m_cyTitleBar + m_TextHeight*2, rcClient.right - rcClient.left,
  1240. rcClient.bottom - rcClient.top - m_cyTitleBar - m_TextHeight*2,
  1241. SWP_NOACTIVATE | SWP_NOZORDER);
  1242. ShowWindow(m_hWndLogin, SW_SHOW);
  1243. ShowWindow(hWndTmp, SW_SHOW);
  1244. }
  1245. else
  1246. {
  1247. if(m_hWndLogin)
  1248. ShowWindow(m_hWndLogin, SW_HIDE);
  1249. SetWindowPos(hWndTmp, NULL, 0, m_cyTitleBar, rcClient.right - rcClient.left,
  1250. rcClient.bottom - rcClient.top - m_cyTitleBar,
  1251. SWP_NOACTIVATE | SWP_NOZORDER);
  1252. ShowWindow(hWndTmp, SW_SHOW);
  1253. }
  1254. }
  1255. }
  1256. return hr;
  1257. }
  1258. ///////////////////////////////////////////////////////////////////////////
  1259. //
  1260. // CBLHost::RegisterAndCreateWindow()
  1261. //
  1262. ///////////////////////////////////////////////////////////////////////////
  1263. BOOL CBLHost::RegisterAndCreateWindow(void)
  1264. {
  1265. // If the window doesn't exist yet, create it now.
  1266. if (!m_hWnd)
  1267. {
  1268. // Can't create a child window without a parent.
  1269. if (!_hwndParent)
  1270. return FALSE;
  1271. // If the window class has not been registered, then do so.
  1272. WNDCLASS wc;
  1273. if (!GetClassInfo(g_hLocRes, EB_CLASS_NAME, &wc))
  1274. {
  1275. ZeroMemory(&wc, sizeof(wc));
  1276. wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
  1277. wc.lpfnWndProc = MainWndProc;
  1278. wc.cbClsExtra = 0;
  1279. wc.cbWndExtra = 0;
  1280. wc.hInstance = g_hLocRes;
  1281. wc.hIcon = NULL;
  1282. wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1283. wc.hbrBackground = NULL;
  1284. wc.lpszMenuName = NULL;
  1285. wc.lpszClassName = EB_CLASS_NAME;
  1286. if (!RegisterClass(&wc))
  1287. {
  1288. // If RegisterClass fails, CreateWindow below will fail.
  1289. }
  1290. }
  1291. // RECT rc;
  1292. // GetClientRect(m_hWnd, &rc);
  1293. // Create the window. The WndProc will set m_hWnd.
  1294. CreateWindowEx(0,
  1295. EB_CLASS_NAME,
  1296. NULL,
  1297. WS_CHILD | WS_CLIPSIBLINGS, // No border
  1298. 0, // rc.left,
  1299. 0, // rc.top,
  1300. 0, // rc.right - rc.left,
  1301. 0, // rc.bottom - rc.top,
  1302. _hwndParent,
  1303. NULL,
  1304. g_hLocRes,
  1305. (LPVOID)this);
  1306. }
  1307. return (NULL != m_hWnd);
  1308. }
  1309. ///////////////////////////////////////////////////////////////////////////
  1310. //
  1311. // CBLHost::GetConnectionPoint()
  1312. //
  1313. ///////////////////////////////////////////////////////////////////////////
  1314. HRESULT CBLHost::GetConnectionPoint(LPUNKNOWN pUnk, REFIID riid, LPCONNECTIONPOINT* ppCP)
  1315. {
  1316. return E_NOTIMPL;
  1317. }
  1318. ///////////////////////////////////////////////////////////////////////////
  1319. //
  1320. // CBLHost::Cleanup()
  1321. //
  1322. // Description: This method releases all interfaces we are holding onto.
  1323. // This has to be done here because Internet Explorer is not
  1324. // releasing all of our interfaces. Therefore, our ref count
  1325. // never reaches 0 and we never delete ourself.
  1326. //
  1327. ///////////////////////////////////////////////////////////////////////////
  1328. void CBLHost::Cleanup(void)
  1329. {
  1330. UnregisterClass(EB_CLASS_NAME, g_hLocRes);
  1331. if (m_pIMsgrAB)
  1332. {
  1333. while(m_pIMsgrAB->Release() != 0)
  1334. ;
  1335. // m_pIMsgrAB->Release();
  1336. // m_pIMsgrAB = NULL;
  1337. }
  1338. if (m_hFont != 0)
  1339. DeleteObject(m_hFont);
  1340. if (m_hUnderlineFont != 0)
  1341. DeleteObject(m_hUnderlineFont);
  1342. if (m_hBoldFont != 0)
  1343. DeleteObject(m_hBoldFont);
  1344. if (m_hbr3DFace)
  1345. DeleteObject(m_hbr3DFace);
  1346. if (m_hbrStaticText)
  1347. DeleteObject(m_hbrStaticText);
  1348. if (m_hbr3DHighFace)
  1349. DeleteObject(m_hbr3DHighFace);
  1350. /* if (_pSite)
  1351. {
  1352. _pSite->Release();
  1353. _pSite = NULL;
  1354. }
  1355. if(m_pUnkSite)
  1356. {
  1357. m_pUnkSite->Release();
  1358. m_pUnkSite = NULL;
  1359. } */
  1360. InterlockedDecrement(&g_cDllRefCount);
  1361. }
  1362. HRESULT STDMETHODCALLTYPE CBLHost::QueryStatus(const GUID *pguidCmdGroup,
  1363. ULONG cCmds,
  1364. OLECMD *prgCmds,
  1365. OLECMDTEXT *pCmdText)
  1366. {
  1367. prgCmds->cmdf = OLECMDF_SUPPORTED | OLECMDF_ENABLED;
  1368. return S_OK;
  1369. }
  1370. HRESULT STDMETHODCALLTYPE CBLHost::Exec(const GUID *pguidCmdGroup,
  1371. DWORD nCmdID,
  1372. DWORD nCmdExecOpt,
  1373. VARIANTARG *pvaIn,
  1374. VARIANTARG *pvaOut)
  1375. {
  1376. UINT id;
  1377. HMENU hMenu = NULL;
  1378. POINT pt = {0, 0};
  1379. if(pvaIn)
  1380. {
  1381. pt.x = GET_X_LPARAM(pvaIn->lVal);
  1382. pt.y = GET_Y_LPARAM(pvaIn->lVal) - 2;
  1383. }
  1384. else
  1385. return (S_OK);
  1386. switch (nCmdID)
  1387. {
  1388. case ID_CONT_FILE:
  1389. hMenu = LoadPopupMenu(IDR_BA_TITLE_POPUP);
  1390. MenuUtil_EnablePopupMenu(hMenu, (CIEMsgAb*) m_pIMsgrAB);
  1391. id = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
  1392. pt.x, pt.y, 0, m_hWnd, NULL);
  1393. if (id)
  1394. {
  1395. ((CIEMsgAb*)m_pIMsgrAB)->Exec(NULL, id, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  1396. }
  1397. UpdateWindow(m_hWnd);
  1398. break;
  1399. case ID_SHOWALLCONTACT:
  1400. if(nCmdExecOpt != OLECMDEXECOPT_PROMPTUSER)
  1401. ((CIEMsgAb*)m_pIMsgrAB)->Exec(NULL, ID_SHOWALLCONTACT, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  1402. else
  1403. {
  1404. hMenu = LoadPopupMenu(IDR_POPUP_VIEW);
  1405. MenuUtil_EnablePopupMenu(hMenu, (CIEMsgAb*) m_pIMsgrAB);
  1406. id = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_LEFTALIGN | TPM_LEFTBUTTON | TPM_RIGHTBUTTON,
  1407. pt.x, pt.y, 0, m_hWnd, NULL);
  1408. if (id)
  1409. {
  1410. ((CIEMsgAb*)m_pIMsgrAB)->Exec(NULL, id, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
  1411. }
  1412. UpdateWindow(m_hWnd);
  1413. }
  1414. break;
  1415. default:
  1416. break;
  1417. }
  1418. if(hMenu)
  1419. {
  1420. BOOL bMenuDestroyed = DestroyMenu(hMenu);
  1421. _ASSERT(bMenuDestroyed);
  1422. }
  1423. return S_OK;
  1424. }