www.pudn.com > TVToolbar_demo > WBToolBar.cpp
///////////////////////////////////////////////////////////////////////////// // WBToolBar.cpp - CWBToolBar implementation ///////////////////////////////////////////////////////////////////////////// // /************************************************************** ** __ __ ** __/_/__________________________________________\_\__ ** __|_ |__ ** (___O) William SerGio & Co., Inc. (O___) **(_____O) www.codearchive.com/~sergio (O_____) **(_____O) Author: Bill SerGio (O_____) ** (__O) (O__) ** |___________________________________________________| ****************************************************************/ /* * (C) Copyright 1997-1999 by William SerGio, All Rights Reserved Worldwide. * 20547 Old Cutler Road, PMB #222, Miami, FL 33189 * www.codearchive.com/~sergio sergio@codearchive.com (305)233-7654 * NO PART of this code may be used for any comercial purposes whatsoever. * Patents Pending regarding design and user interface concepts embodied herein. * * Redistribution and use in source and binary forms, with or without modification, * are permitted under this non-exclusive license for NON-COMMERCIAL USE ONLY * provided that the following conditions are met: * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * 3. Licensee does not utilize the software in a manner which is disparaging * to the Author and/or any products or companies of the Author. * 4. This code/software may NOT be used for any commercial purpose whatsoever * or by any government, federal agency, or, any employee or agent of any * government or federal agency. This software is not designed or intended for * use in on-line control of aircraft, air traffic, aircraft navigation or * aircraft communications; or in design, construction, operation or maintenance * of any nuclear facility. Licensee represents and warrants that it will not use * or redistribute the Software for such purposes. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR FOR EDUCATIONAL PURPOSES ONLY, * 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS, * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION), * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * NOTICE: * Contact author regarding commercial licensing of this code. * The marks: TV Toolbar(tm), TVToolbar(tm), 3D TV Toolbar(tm), 3D TVToolbar(tm), * SlickSkins(tm), VideoSkins(tm), LiquidVideo(tm), Email Anywhere(tm), SpeedE(tm), * Windows SuperCharger(tm), Internet SuperCharger(tm), 1st Place(tm), SpeedD(tm), * Speed Demon(tm), LiquidDesktop(tm), VideoAnywhere(tm) are copyrights and trademarks * of William SerGio & Co., Inc. and may NOT be used in any way whatsoever. * */ #include "stdafx.h" #include "WBToolBar.h" #include "chits.h" #include#include #include #include #include #include //#include #define TB_MAIN 500 //#include in header #include "WBToolBar.h" #include "Guid.h" #include #include #include #include #include #include #pragma comment( lib , "kernel32") #pragma comment( lib , "shell32") #include #pragma comment( lib , "comdlg32") #include //DEFINE_GUID(CGID_IWebBrowserPriv,0xED016940L,0xBD5B,0x11cf,0xBA,0x4E,0x00,0xC0,0x4F,0xD7,0x08,0x16); // Could create an ATL window-some possible advantages // Includes for ATL #pragma comment(lib,"atl.lib") #include #define _ATL_DLL_IMPL #include #include #include #include // You can define lots of various anchors #define TB_SHELL "#_tbshell" // Launch a program file (.exe) #define TB_LOAD "#_tbload" // Load the given toolbar .htm fle #define TB_FIND "#_tbfind" // Pop select toolbar file dialog #define TB_LCHM "#_tblchm" // Pop select toolbar file dialog for CHM files #define VS_LOAD "#_vsload" // Pop select toolbar file dialog #define SK_LOAD "#_skload" // Load the given slick skin .htm fle #define SK_FIND "#_skfind" // Pop select slick skin file dialog #define AB_LOAD "#_abload" // Load the given AppBAr .htm fle #define AB_FIND "#_abfind" // Pop select AppBAr file dialog //static CSkinDlg* m_pMenuDlg; BOOL FileExists(const char *pszPath){ BOOL bRet; CFileStatus status; if (CFile::GetStatus( pszPath, status )) { bRet = TRUE; } else { bRet = FALSE; } return(bRet); } LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam); CWBToolBar::CWBToolBar() : _cRef(1), _hwndParent(NULL), _hWnd(NULL), _hwndWB(NULL), _dwViewMode(0), _dwBandID(0), _dwWBCookie(0), _pSite(NULL), _pIOleIPObject(NULL), _pIOleObject(NULL), _pFrameWB(NULL), _pWebBrowserOC(NULL), _bBandVarH(FALSE), _lBandHeight(24) { InterlockedIncrement(&g_cDllRefCount); } CWBToolBar::~CWBToolBar() { Cleanup(); } ///////////////////////////////////////// // IUnknown Methods ///////////////////////////////////////// /* * CWBToolBar::QueryInterface() * Will this make me queer? */ STDMETHODIMP CWBToolBar::QueryInterface(REFIID riid, LPVOID* ppvObject) { *ppvObject= NULL; if (IsEqualIID(riid, IID_IUnknown)) { *ppvObject = this; } else if (IsEqualIID(riid, IID_IOleWindow) || IsEqualIID(riid, IID_IDockingWindow)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IInputObject)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IObjectWithSite)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IDeskBand)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IPersist)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IPersistStream)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IContextMenu)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IOleClientSite)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IOleInPlaceSite)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IOleControlSite)) { *ppvObject = static_cast (this); } else if (IsEqualIID(riid, IID_IDispatch) || IsEqualIID(riid, DIID_DWebBrowserEvents2)) { *ppvObject = static_cast (this); } if (*ppvObject) { static_cast (*ppvObject)->AddRef(); return S_OK; } return E_NOINTERFACE; } /* * CWBToolBar::AddRef() */ STDMETHODIMP_(ULONG) CWBToolBar::AddRef() { return (ULONG)InterlockedIncrement(&_cRef); } /* * CWBToolBar::Release() */ STDMETHODIMP_(ULONG) CWBToolBar::Release() { if (0 == InterlockedDecrement(&_cRef)) { delete this; return 0; } return (ULONG)_cRef; } ///////////////////////////////////////// // IOleWindow Methods ///////////////////////////////////////// /* * CWBToolBar::GetWindow() */ STDMETHODIMP CWBToolBar::GetWindow(HWND *phwnd) { *phwnd = _hWnd; return S_OK; } /* * CWBToolBar::ContextSensitiveHelp() */ STDMETHODIMP CWBToolBar::ContextSensitiveHelp(BOOL fEnterMode) { return E_NOTIMPL; } ///////////////////////////////////////// // IDockingWindow Methods ///////////////////////////////////////// /* * CWBToolBar::ShowDW() */ STDMETHODIMP CWBToolBar::ShowDW(BOOL fShow) { if (_hWnd) { // Hide/show window based on value of fShow if (fShow) ShowWindow(_hWnd, SW_SHOW); else ShowWindow(_hWnd, SW_HIDE); } return S_OK; } /* * CWBToolBar::CloseDW() */ STDMETHODIMP CWBToolBar::CloseDW(DWORD dwReserved) { ShowDW(FALSE); if (IsWindow(_hWnd)) DestroyWindow(_hWnd); _hWnd = NULL; return S_OK; } /* * CWBToolBar::ResizeBorderDW() */ STDMETHODIMP CWBToolBar::ResizeBorderDW(LPCRECT prcBorder, IUnknown* punkToolbarSite, BOOL fReserved) { // This method is NEVER called for Band Objects // Well, sometimes when we want to be very naughty! return E_NOTIMPL; } ///////////////////////////////////////// // IInputObject Methods ///////////////////////////////////////// /* * CWBToolBar::UIActivateIO() */ STDMETHODIMP CWBToolBar::UIActivateIO(BOOL fActivate, LPMSG lpMsg) { _ASSERT(_pIOleObject); HRESULT hr = E_FAIL; if (_pIOleObject) { RECT rc; GetClientRect(_hwndParent, &rc); // If we are being activated, we must UI Activate the WebBrowser // control in order for all accelerators to work. if (fActivate) hr = _pIOleObject->DoVerb(OLEIVERB_UIACTIVATE, lpMsg, this, 0, _hwndParent, &rc); else hr = _pIOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, lpMsg, this, 0, _hwndParent, &rc); } return hr; } /* * CWBToolBar::HasFocusIO() * * If this window or one of its decendants has focus, * return S_OK. Return S_FALSE if we don't have focus */ STDMETHODIMP CWBToolBar::HasFocusIO(void) { HWND hwnd = GetFocus(); HWND hwndTmp = _hwndWB; // // Check if focus has been set to any children // while (hwnd && hwndTmp) { if (hwnd == hwndTmp) return S_OK; hwndTmp = ::GetWindow(hwndTmp, GW_CHILD); } return S_FALSE; } /* * CWBToolBar::TranslateAcceleratorIO() * * If accelerator is translated, return S_OK * return S_FALSE if NOT translated */ STDMETHODIMP CWBToolBar::TranslateAcceleratorIO(LPMSG pMsg) { _RPT0(_CRT_WARN, "TranslateAcceleratorIO\n"); LPDISPATCH pDisp = NULL; HRESULT hr = S_FALSE; IOleInPlaceActiveObject* pIPO; // Send accelerator messages to WebBrowser control so that // keys such as backspace and delete will work correctly hr = _pWebBrowserOC->get_Application(&pDisp); if (SUCCEEDED(hr)) { hr = pDisp->QueryInterface(IID_IOleInPlaceActiveObject, (LPVOID*)&pIPO); pDisp->Release(); if (SUCCEEDED(hr)) { hr = pIPO->TranslateAccelerator(pMsg); pIPO->Release(); } } return hr; } ///////////////////////////////////////// // IObjectWithSite Methods ///////////////////////////////////////// /* * CWBToolBar::SetSite() */ STDMETHODIMP CWBToolBar::SetSite(IUnknown* pUnkSite) { // If punkSite is not NULL, a new site is being set. if (pUnkSite) { // If pointer IInputObjectSite is being held, release it if (_pSite) { _pSite->Release(); _pSite = NULL; } m_cMapIds = NULL; m_csChm.Empty(); // Get parent window. IOleWindow* pOleWindow; if (SUCCEEDED(pUnkSite->QueryInterface(IID_IOleWindow, (LPVOID*)&pOleWindow))) { pOleWindow->GetWindow(&_hwndParent); pOleWindow->Release(); } _ASSERT(_hwndParent); if (!_hwndParent) return E_FAIL; if (!RegisterAndCreateWindow()) return E_FAIL; // Get and keep IInputObjectSite pointer // HRESULT hr = pUnkSite->QueryInterface(IID_IInputObjectSite, (LPVOID*)&_pSite); _ASSERT(SUCCEEDED(hr)); // Get IWebBrowser2 interface of I.E. to allow us to // in main window and write to status bar, do other shit, etc. // IOleCommandTarget* pCmdTarget; hr = pUnkSite->QueryInterface(IID_IOleCommandTarget, (LPVOID*)&pCmdTarget); if (SUCCEEDED(hr)) { IServiceProvider* pSP; hr = pCmdTarget->QueryInterface(IID_IServiceProvider, (LPVOID*)&pSP); pCmdTarget->Release(); if (SUCCEEDED(hr)) { if (_pFrameWB) { _pFrameWB->Release(); _pFrameWB = NULL; } hr = pSP->QueryService(SID_SWebBrowserApp, IID_IWebBrowser2, (LPVOID*)&_pFrameWB); _ASSERT(_pFrameWB); pSP->Release(); } } // Create and initialize hosted WebBrowser control // hr = CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_INPROC, IID_IOleObject, (LPVOID*)&_pIOleObject); if (hr != S_OK) return E_FAIL; if (_pIOleObject->SetClientSite(this) != S_OK) return E_FAIL; // Get client area // RECT rcClient = { CW_USEDEFAULT, 0, 0, 0 }; GetClientRect(_hWnd, &rcClient); MSG msg; // In-place activate WebBrowser control // hr = _pIOleObject->DoVerb(OLEIVERB_INPLACEACTIVATE, &msg, this, 0, _hWnd, &rcClient); _ASSERT(SUCCEEDED(hr)); if (FAILED(hr)) return E_FAIL; // Get pointer to WebBrowser control // hr = _pIOleObject->QueryInterface(IID_IWebBrowser2, (LPVOID*)&_pWebBrowserOC); _ASSERT(_pWebBrowserOC); if (FAILED(hr)) { return E_FAIL; } else { // Set up an event sink for WebBrowser events if (_pWebBrowserOC) AdviseWBEventSink(); // Risk becoming queer, and QI for in-place object to set size if (_pIOleIPObject) { _pIOleIPObject->Release(); _pIOleIPObject = NULL; } hr = _pWebBrowserOC->QueryInterface(IID_IOleInPlaceObject, (LPVOID*)&_pIOleIPObject); _ASSERT(_pIOleIPObject); if (FAILED(hr)) return E_FAIL; hr = _pIOleIPObject->SetObjectRects(&rcClient, &rcClient); _ASSERT(SUCCEEDED(hr)); // static TCHAR szMediaDir[MAX_PATH]; DWORD dwType; DWORD dwSize = MAX_PATH; HKEY hKey; // Open appropriate registry key LONG lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Software\\TVToolbar\\Settings"), 0, KEY_READ, &hKey ); //if( ERROR_SUCCESS != lResult ) //return E_FAIL; lResult = RegQueryValueEx( hKey, _T("ExeDir"), NULL, &dwType, (BYTE*)gszExeDir, &dwSize ); RegCloseKey( hKey ); //if( ERROR_SUCCESS != lResult ) // return E_FAIL; // Check to see if Toolbar directory is installed in Program Files TCHAR szTBFile[MAX_PATH]; lstrcpy(szTBFile, gszExeDir); lstrcat(szTBFile, _T("\\toolbars\\sergio.htm")); // CRITICAL TO BE SURE IT EXISTS!!! if ( !FileExists(szTBFile) ){return E_FAIL;} // UNSLASH AND USE CODE BELOW FOR COMPRESSED .chm or .its FILES /* UINT mapID = TB_MAIN; _tcscpy( szChmURL, _T("its:") ); _tcscat( szChmURL, gszExeDir ); //_tcscat( szChmURL, _T("\\toolbars\\tbars.chm::html\\TB_MAIN.htm") ); _tcscat( szChmURL, _T("\\toolbars\\tbars.chm") ); _tcscat( szChmURL, _T("::html\\") ); _tcscat( szChmURL, _T("TB_MAIN.htm") ); // Navigate to .htm, .chm, asp, jsp, etc. pages _variant_t vtEmpty; lstrcat( szChmURL, TEXT("#_tbload") ); _bstr_t bstrURL(szChmURL); try { // You can use Navigate2 instead of Navigate, but you must pass a variant //COleVariant vtEmpty; //COleVariant vaURL(szChmURL); //_pWebBrowserOC->Navigate2(vaURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty); // Or, use Navigate with a bstrURL _pWebBrowserOC->Navigate(bstrURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty); } catch( ... ){SysFreeString(bstrURL); return E_FAIL;} */ /* * AUTHOR NOTES: BILL SERGIO * * I used MFC in this dll, but if you don't use MFC, * then you can create a variant url as follows: * This is how you do it without using "COleVariant" * * VARIANT vtEmpty; * vtEmpty.vt = VT_EMPTY; * VARIANT vtURL; * vtURL.vt = VT_BSTR; * vtURL.bstrVal = bstrURL; * hr = pWebBrowser->put_Visible(VARIANT_TRUE); * hr = pWebBrowser->Navigate2(&vtURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty); */ // Navigate to .htm, asp, jsp, etc. pages _variant_t vtEmpty; lstrcat( szTBFile, TEXT("#_tbload") ); _bstr_t bstrURL(szTBFile); try { // You can use Navigate2 instead of Navigate, but you must pass a variant COleVariant vtEmpty; COleVariant vaURL(szTBFile); _pWebBrowserOC->Navigate2(vaURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty); // Or, use Navigate with a bstrURL //_pWebBrowserOC->Navigate(bstrURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty); } catch( ... ){SysFreeString(bstrURL); return E_FAIL;} // Free BSTR SysFreeString(bstrURL); // Get HWND of WebBrowser OC IOleWindow* pWnd; if (SUCCEEDED(_pWebBrowserOC->QueryInterface(IID_IOleWindow, (LPVOID*)&pWnd))) { pWnd->GetWindow(&_hwndWB); } } } return S_OK; } /////////////////////////////////////////////////////////////////////////// // CWBToolBar::GetSite() /////////////////////////////////////////////////////////////////////////// STDMETHODIMP CWBToolBar::GetSite(REFIID riid, void** ppvSite) { *ppvSite = NULL; if (_pSite) return _pSite->QueryInterface(riid, ppvSite); return E_FAIL; } /////////////////////////////////////////////////////////////////////////// // IDeskBand implementation /////////////////////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////////////////////// // CWBToolBar::GetBandInfo() /////////////////////////////////////////////////////////////////////////// STDMETHODIMP CWBToolBar::GetBandInfo(DWORD dwBandID, DWORD dwViewMode, DESKBANDINFO* pdbi) { if (pdbi) { _dwBandID = dwBandID; _dwViewMode = dwViewMode; if (pdbi->dwMask & DBIM_MINSIZE) { pdbi->ptMinSize.x = MIN_SIZE_X; pdbi->ptMinSize.y = _lBandHeight; } if (pdbi->dwMask & DBIM_MAXSIZE) { pdbi->ptMaxSize.x = -1; pdbi->ptMaxSize.y = _lBandHeight; } if (pdbi->dwMask & DBIM_INTEGRAL) { pdbi->ptIntegral.x = 1; pdbi->ptIntegral.y = 1; } if (pdbi->dwMask & DBIM_ACTUAL) { //_lBandHeight = 24; pdbi->ptActual.x = 0; pdbi->ptActual.y = _lBandHeight; } // WS TITLE if (pdbi->dwMask & DBIM_TITLE) { AFX_MANAGE_STATE(AfxGetStaticModuleState()); //CString strTitle((LPCSTR)IDS_TOOLBARNAME); //lstrcpyW(pdbi->wszTitle, T2W((LPTSTR)(LPCTSTR)strTitle)); lstrcpyW(pdbi->wszTitle, L" "); //USES_CONVERSION; //lstrcpyW(pdbi->wszTitle, T2OLE(GetTitle())); } if (pdbi->dwMask & DBIM_MODEFLAGS) { // DBIF_VIEWMODE_FLOATING if ( _bBandVarH ) { pdbi->dwModeFlags = DBIMF_NORMAL | DBIMF_VARIABLEHEIGHT; } else { //pdbi->dwModeFlags = DBIMF_DEBOSSED; pdbi->dwModeFlags = DBIMF_NORMAL ; } } if (pdbi->dwMask & DBIM_BKCOLOR) { // Use the default background color by removing this flag. pdbi->dwMask &= ~DBIM_BKCOLOR; } //pdbi->crBkgnd = COLOR_INACTIVEBORDER; return S_OK; } return E_INVALIDARG; } ///////////////////////////////////////// // IPersistStream Methods ///////////////////////////////////////// // Only implemented to allow desk band to be // dropped onto desktop and to prevent multiple // instances of desk band from appearing in context menu. // This desk band doesn't persist any data in reality ///////////////////////////////////////// /* * CWBToolBar::GetClassID() */ STDMETHODIMP CWBToolBar::GetClassID(LPCLSID pClassID) { *pClassID = CLSID_WBToolBar; return S_OK; } /* * CWBToolBar::IsDirty() */ STDMETHODIMP CWBToolBar::IsDirty(void) { return S_FALSE; } /* * CWBToolBar::Load() */ STDMETHODIMP CWBToolBar::Load(LPSTREAM pStream) { return S_OK; } /* * CWBToolBar::Save() */ STDMETHODIMP CWBToolBar::Save(LPSTREAM pStream, BOOL fClearDirty) { return S_OK; } /* * CWBToolBar::GetSizeMax() */ STDMETHODIMP CWBToolBar::GetSizeMax(ULARGE_INTEGER *pul) { return E_NOTIMPL; } ///////////////////////////////////////// // IContextMenu Methods ///////////////////////////////////////// /* * CWBToolBar::QueryContextMenu() */ STDMETHODIMP CWBToolBar::QueryContextMenu(HMENU hmenu, UINT indexMenu, UINT idCmdFirst, UINT idCmdLast, UINT uFlags) { if (!(CMF_DEFAULTONLY & uFlags)) { InsertMenu(hmenu, indexMenu, MF_STRING | MF_BYPOSITION, idCmdFirst + IDM_REFRESH, _T("&Refresh") ); InsertMenu(hmenu, indexMenu + 1, MF_STRING | MF_BYPOSITION, idCmdFirst + IDM_OPENINWINDOW, _T("&TVToolbar") ); return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(IDM_OPENINWINDOW + 1)); } return MAKE_HRESULT(SEVERITY_SUCCESS, 0, USHORT(0)); } /* * CWBToolBar::InvokeCommand() */ STDMETHODIMP CWBToolBar::InvokeCommand(LPCMINVOKECOMMANDINFO lpici) { switch (LOWORD(lpici->lpVerb)) { case IDM_REFRESH: _pWebBrowserOC->Refresh(); break; case IDM_OPENINWINDOW: { BSTR bstrURL; HRESULT hr = _pWebBrowserOC->get_LocationURL(&bstrURL); if (SUCCEEDED(hr)) { _variant_t vtEmpty; _variant_t vtFlags((long)(navOpenInNewWindow|navNoHistory)); hr = _pWebBrowserOC->Navigate(bstrURL, &vtFlags, &vtEmpty, &vtEmpty, &vtEmpty); } // MUST FREE BSTR!!!! SysFreeString(bstrURL); break; } default: return E_INVALIDARG; } return NOERROR; } /* * CWBToolBar::GetCommandString() */ STDMETHODIMP CWBToolBar::GetCommandString(UINT idCmd, UINT uType, UINT* pwReserved, LPSTR pszName, UINT cchMax) { HRESULT hr = E_INVALIDARG; switch(uType) { case GCS_HELPTEXT: switch(idCmd) { case IDM_REFRESH: //MessageBox(NULL,"Refresh","Refresh",0); pszName = "Refreshes your mother bro!"; //lstrcpy(pszName, L"Refreshes your mother bro!"); hr = NOERROR; break; case IDM_OPENINWINDOW: pszName = "Be a pornographer & open a new I.E. window!"; //lstrcpy(pszName, L("Be a pornographer & open a new I.E. window!")); hr = NOERROR; break; } break; case GCS_VERB: switch(idCmd) { case IDM_REFRESH: //MessageBox(NULL,"Verb_Refresh","Verb_Refresh",0); pszName = "Refresh"; //lstrcpy(pszName, _T("Refresh")); hr = NOERROR; break; case IDM_OPENINWINDOW: pszName = "Open in Window"; //lstrcpy(pszName, _T("Open in Window")); hr = NOERROR; break; } break; case GCS_VALIDATE: hr = NOERROR; break; } return hr; } ///////////////////////////////////////// // IOleClientSite Methods ///////////////////////////////////////// /* * CWBToolBar::SaveObject() */ STDMETHODIMP CWBToolBar::SaveObject() { return E_NOTIMPL; } /* * CWBToolBar::GetMoniker() */ STDMETHODIMP CWBToolBar::GetMoniker(DWORD dwAssign, DWORD dwWhichMoniker, LPMONIKER* ppmk) { return E_NOTIMPL; } /* * CWBToolBar::GetContainer() */ STDMETHODIMP CWBToolBar::GetContainer(LPOLECONTAINER* ppContainer) { *ppContainer = NULL; return E_NOINTERFACE; } /* * WBToolBar::ShowObject() */ STDMETHODIMP CWBToolBar::ShowObject() { return S_OK; } /* * CWBToolBar::OnShowWindow() */ STDMETHODIMP CWBToolBar::OnShowWindow(BOOL fShow) { return S_OK; } /* * CWBToolBar::RequestNewObjectLayout() */ STDMETHODIMP CWBToolBar::RequestNewObjectLayout() { return E_NOTIMPL; } ///////////////////////////////////////// // IOleInPlaceSite Methods ///////////////////////////////////////// /* * CWBToolBar::CanInPlaceActivate() */ STDMETHODIMP CWBToolBar::CanInPlaceActivate(void) { return S_OK; } /* * CWBToolBar::OnInPlaceActivate() */ STDMETHODIMP CWBToolBar::OnInPlaceActivate(void) { return S_OK; } /* * CWBToolBar::OnUIActivate() */ STDMETHODIMP CWBToolBar::OnUIActivate(void) { return S_OK; } /* * CWBToolBar::GetWindowContext() */ STDMETHODIMP CWBToolBar::GetWindowContext(IOleInPlaceFrame** ppFrame, IOleInPlaceUIWindow** ppIIPUIWin, LPRECT lprcPosRect, LPRECT lprcClipRect, LPOLEINPLACEFRAMEINFO lpFrameInfo) { *ppFrame = NULL; *ppIIPUIWin = NULL; GetClientRect(_hWnd, lprcPosRect); GetClientRect(_hWnd, lprcClipRect); return S_OK; } /* * CWBToolBar::Scroll() */ STDMETHODIMP CWBToolBar::Scroll(SIZE scrollExtent) { return E_NOTIMPL; } /* * CWBToolBar::OnUIDeactivate() */ STDMETHODIMP CWBToolBar::OnUIDeactivate(BOOL fUndoable) { return E_NOTIMPL; } /* * CWBToolBar::OnInPlaceDeactivate() */ STDMETHODIMP CWBToolBar::OnInPlaceDeactivate(void) { if (_pIOleIPObject) { _pIOleIPObject->Release(); _pIOleIPObject = NULL; } return S_OK; } /* * CWBToolBar::DiscardUndoState() */ STDMETHODIMP CWBToolBar::DiscardUndoState(void) { return E_NOTIMPL; } /* * CWBToolBar::DeactivateAndUndo() */ STDMETHODIMP CWBToolBar::DeactivateAndUndo(void) { return E_NOTIMPL; } /* * CWBToolBar::OnPosRectChange() */ STDMETHODIMP CWBToolBar::OnPosRectChange(LPCRECT lprcPosRect) { return S_OK; } ///////////////////////////////////////// // IOleControlSite Methods ///////////////////////////////////////// /* * CWBToolBar::OnControlInfoChanged() */ STDMETHODIMP CWBToolBar::OnControlInfoChanged(void) { return E_NOTIMPL; } /* * CWBToolBar::LockInPlaceActive() */ STDMETHODIMP CWBToolBar::LockInPlaceActive(BOOL fLock) { return E_NOTIMPL; } /* * CWBToolBar::GetExtendedControl() */ STDMETHODIMP CWBToolBar::GetExtendedControl(LPDISPATCH* ppDisp) { return E_NOTIMPL; } /* * CWBToolBar::TransformCoords() */ STDMETHODIMP CWBToolBar::TransformCoords(POINTL* pPtlHimetric, POINTF* pPtfContainer, DWORD dwFlags) { return E_NOTIMPL; } /* * CWBToolBar::TranslateAccelerator() */ STDMETHODIMP CWBToolBar::TranslateAccelerator(LPMSG lpMsg, DWORD grfModifiers) { return E_NOTIMPL; } /* * CWBToolBar::OnFocus() */ STDMETHODIMP CWBToolBar::OnFocus(BOOL fGotFocus) { _RPT1(_CRT_WARN, "OnFocus: %s\n", fGotFocus ? "True" : "False"); if (_pSite) _pSite->OnFocusChangeIS(static_cast (this), fGotFocus); return S_OK; } /* * CWBToolBar::ShowPropertyFrame() */ STDMETHODIMP CWBToolBar::ShowPropertyFrame(void) { return E_NOTIMPL; } ///////////////////////////////////////// // Private Methods // The shit you do with those women you aren't going to marry! ///////////////////////////////////////// /* * CWBToolBar::GetTypeInfoCount() */ STDMETHODIMP CWBToolBar::GetTypeInfoCount(UINT* pctinfo) { return E_NOTIMPL; } /* * CWBToolBar::GetTypeInfo() */ STDMETHODIMP CWBToolBar::GetTypeInfo(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) { return E_NOTIMPL; } /* * CWBToolBar::GetIDsOfNames() */ STDMETHODIMP CWBToolBar::GetIDsOfNames(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId) { return E_NOTIMPL; } /* * CWBToolBar::Invoke() */ STDMETHODIMP CWBToolBar::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr) { if (IID_NULL != riid) return DISP_E_UNKNOWNINTERFACE; if (!pDispParams) return DISP_E_PARAMNOTOPTIONAL; static bool sbIsAnchor = false; switch (dispIdMember) { /* * The parameters for this DISPID: * [0]: New status bar text - VT_BSTR * */ case DISPID_STATUSTEXTCHANGE: { if (pDispParams->cArgs && pDispParams->rgvarg[0].vt != VT_BSTR) { *puArgErr = 0; return DISP_E_TYPEMISMATCH; } if (_pFrameWB) _pFrameWB->put_StatusText(pDispParams->rgvarg[0].bstrVal); break; } /* * Parameters for this DISPID are as follows: * [0]: Cancel Flag - VT_BYREF|VT_BOOL * [1]: HTTP Headers - VT_BYREF|VT_VARIANT * [2]: Address of HTTP POST Data - VT_BYREF|VT_VARIANT * [3]: Target frame name - VT_BYREF|VT_VARIANT * [4]: Option flags - VT_BYREF|VT_VARIANT * [5]: URL to navigate to - VT_BYREF|VT_VARIANT * [6]: Object - Frame WebBrowser or * top-level event * * Note: To control which window navigation will occur in, * we sink events for all anchors on page. We navigate * in main window if an anchor is clicked. To determine * where we want navigation to occur, we use in our URL * an indicator known as a fragment identifier (otherwise * known as a bookmark). We can't use the TARGET attribute * because it causes I.E. to open the link in a new window. */ case DISPID_BEFORENAVIGATE2: { _bstr_t bstrURL(*pDispParams->rgvarg[5].pvarVal); //else if (pDispParams->cArgs >= 5 && !strstr(bstrURL, TB_LOAD)) // TESTING: UNSLASH CODE BELOW TO POP MSGBOX FOR TESTING // //HWND pHWND; //_pFrameWB->get_HWND((long *)&pHWND); //::MessageBox(pHWND, "BEFORENAVIGATE2 Fired!", "SerGio' BIG Tool", MB_ICONWARNING); if (!sbIsAnchor) { ManageAnchorsEventSink(Unadvise); } if ( strstr(bstrURL, TB_SHELL) ) { // TB_SHELL "#_tbshell" CString csRawUrl = (char *)bstrURL; CString csData; AfxExtractSubString(csData, csRawUrl, 1, (TCHAR)'%'); this->GetShellPath(csData); *(pDispParams->rgvarg[0].pboolVal) = VARIANT_TRUE; sbIsAnchor = false; } else if ( strstr(bstrURL, SK_FIND) ) { // CFileDialog( // BOOL bOpenFileDialog, // LPCTSTR lpszDefExt = NULL, // LPCTSTR lpszFileName = NULL, // DWORD dwFlags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT, // LPCTSTR lpszFilter = NULL, // CWnd* pParentWnd = NULL ); CFileDialog *pDlg = new CFileDialog( TRUE, NULL, NULL, OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER, _T("Skin Files (*.htm)|*.htm|All Files (*.*)|*.*||")); pDlg->m_ofn.nFilterIndex = 1; CString csInitialDir = gszSSExeDir; csInitialDir += "\\skins\\html"; pDlg->m_ofn.lpstrInitialDir = (LPCSTR)csInitialDir; char szSkin[MAX_PATH]; lstrcpy(szSkin, TEXT("/skin%")); if( pDlg->DoModal()==IDOK ) { lstrcat(szSkin, pDlg->GetPathName()); } delete pDlg; ShellExecute(NULL, "open", gszSSExe, szSkin, NULL, SW_SHOWNORMAL); *(pDispParams->rgvarg[0].pboolVal) = VARIANT_TRUE; sbIsAnchor = false; } else if ( strstr(bstrURL, VS_LOAD) ) { GetShellPath("slickskins"); *(pDispParams->rgvarg[0].pboolVal) = VARIANT_TRUE; sbIsAnchor = false; } else if ( strstr(bstrURL, SK_LOAD) ) { // skins/html/sergio/sergio.htm char szSkin[MAX_PATH]; lstrcpy(szSkin, TEXT("/skin%")); strcat(szSkin, gszSSExeDir); strcat(szSkin, TEXT("\\")); strcat(szSkin, strstr(bstrURL,TEXT("%"))+1); //::MessageBox(NULL,szSkin,szSkin,0); //AfxMessageBox((LPCSTR)gszSSExe); //AfxMessageBox((LPCSTR)szSkin); ShellExecute(NULL, "open", gszSSExe, szSkin, NULL, SW_SHOWNORMAL); *(pDispParams->rgvarg[0].pboolVal) = VARIANT_TRUE; sbIsAnchor = false; } else if ( strstr(bstrURL, TB_FIND) ) { CFileDialog *pDlg = new CFileDialog(TRUE, NULL,NULL,OFN_PATHMUSTEXIST | OFN_FILEMUSTEXIST | OFN_EXPLORER, _T("Toolbar Files (*.htm)|*.htm|(*.chm)|*.chm|All Files (*.*)|*.*||")); pDlg->m_ofn.nFilterIndex = 1; CString csInitialDir = gszExeDir; csInitialDir += "\\toolbars"; pDlg->m_ofn.lpstrInitialDir = (LPCSTR)csInitialDir; if( pDlg->DoModal()==IDOK ) { TCHAR szURL[MAX_PATH]; if ( pDlg->GetFileExt() == "chm" ) { // A CHM OT ITS COMPRESSED STORAGE FILE // tbars.chm::TB_MAIN.htm#_tbload _tcscpy( szURL, _T("its:") ); _tcscat( szURL, pDlg->GetPathName() ); _tcscat( szURL, _T("::TB_MAIN.htm") ); } else { // Not a .chm ot .its compressed file _tcscpy( szURL, pDlg->GetPathName() ); } _tcscat( szURL, TEXT("#_tbload") ); COleVariant vtEmpty; COleVariant vaURL(szURL); try { _pWebBrowserOC->Navigate2(vaURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty); } catch( ... ){} } delete pDlg; *(pDispParams->rgvarg[0].pboolVal) = VARIANT_TRUE; sbIsAnchor = false; } else if ( strstr(bstrURL, TB_LCHM) ) { // LOADS A COMPRESSED HTML FILE, i.e., .chm files or .its file CString csRawUrl; csRawUrl.Empty(); csRawUrl = (LPCSTR)bstrURL; CString csData; csData.Empty(); AfxExtractSubString(csData, csRawUrl, 1, (TCHAR)'%'); TCHAR szURL[MAX_PATH * 2]; _tcscpy( szURL, _T("its:") ); _tcscat( szURL, gszExeDir ); _tcscat( szURL, _T("\\toolbars\\") ); _tcscat( szURL, (LPCSTR)csData ); _tcscat( szURL, _T("#_tbload") ); //_bstr_t bstrURL(szURL); //_variant_t vtEmpty; COleVariant vtEmpty; COleVariant vaURL(szURL); try { _pWebBrowserOC->Navigate2(vaURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty); } catch( ... ){} *(pDispParams->rgvarg[0].pboolVal) = VARIANT_TRUE; sbIsAnchor = false; } else if ( !strstr(bstrURL, TB_LOAD) ) { // LOAD WEB PAGE INTO MAIN BROWSER INSTEAD OF TOOLBAR // _pFrameWB->Navigate2(pDispParams->rgvarg[5].pvarVal, pDispParams->rgvarg[4].pvarVal, pDispParams->rgvarg[3].pvarVal, pDispParams->rgvarg[2].pvarVal, pDispParams->rgvarg[1].pvarVal); *(pDispParams->rgvarg[0].pboolVal) = VARIANT_TRUE; sbIsAnchor = false; } // MUST FREE BSTR!!!! SysFreeString(bstrURL); } break; /* * CONTROL HEIGHT OF TOOLBAR FROM INSIDE HTML!!! * WE READ HEIGHT VALUE FOR TOOLBAR FROM HTML TITLE */ case DISPID_DOCUMENTCOMPLETE: { //_bstr_t bstrURL(*pDispParams->rgvarg[5].pvarVal); //BSTR bstrURL; //ManageFrameAnchorsEventSink(Advise); //_pFrameWB->get_LocationURL(&bstrURL); //::MessageBox(NULL, bstrURL, bstrURL, 0); // MUST FREE BSTR!!!! //SysFreeString(bstrURL); USES_CONVERSION; // Get WebBrowser's document object CComPtr pDisp; HRESULT hr = _pWebBrowserOC->get_Document(&pDisp); if (SUCCEEDED(_pWebBrowserOC->get_Document(&pDisp))) { // Verify we get a pointer to a IHTMLDocument2 interface. To be sure, // let's query for IHTMLDocument2 interface (through smart pointers) CComQIPtr spHTML; spHTML = pDisp; // Previous step is sufficient without // an explicit check against loader module CString csTitleData; CString csID; CString csHeight; // Extract source code of document if (spHTML){ // Skin region name is specified in tag as: // TBARV:36 BSTR bstTitle = NULL; if ( SUCCEEDED( spHTML->get_title(&bstTitle) ) ) { csTitleData = (CString)bstTitle; AfxExtractSubString(csID, csTitleData, 0, (TCHAR)':'); AfxExtractSubString(csHeight, csTitleData, 1, (TCHAR)':'); csID.MakeUpper(); // Check Uranus... Uranus is a dark, gaseous planet in our solar system if ( ( csID == "TBAR" ) || ( csID == "TBARV" ) ) { LONG lTempHeight = 24; lTempHeight = atoi(csHeight); if ( ( lTempHeight > 10 ) && ( lTempHeight < 100 ) ) { _lBandHeight = lTempHeight; } else { _lBandHeight = 24; } if ( csID == "TBARV" ) { _bBandVarH = TRUE; } else { _bBandVarH = FALSE; } } else { _bBandVarH = FALSE; _lBandHeight = 24; } ///////////////////////////////////////// // MAKE SURE WE HAVE THE TOOLBAR! ///////////////////////////////////////// IOleCommandTarget* pCmdTarget; //COleVariant vtItem((long)1); //_variant_t vtPar; if (SUCCEEDED(_pSite->QueryInterface(IID_IOleCommandTarget, (LPVOID*)&pCmdTarget))){ pCmdTarget->Exec(&CGID_DeskBand, DBID_BANDINFOCHANGED, OLECMDEXECOPT_DONTPROMPTUSER, NULL, NULL); pCmdTarget->Release(); } ///////////////////////////////////////// } // MUST deallocate bstr string to free memory SysFreeString(bstTitle); } } } break; case DISPID_NAVIGATECOMPLETE2: ManageAnchorsEventSink(Advise); break; case DISPID_HTMLELEMENTEVENTS_ONCLICK: { sbIsAnchor = true; break; } /* * Parameters for this DISPID: * [0]: Document Title - VT_BSTR */ case DISPID_TITLECHANGE: { if (pDispParams->cArgs && pDispParams->rgvarg[0].vt != VT_BSTR) { *puArgErr = 0; return DISP_E_TYPEMISMATCH; } // Get handle to some window to goof arround! //::SetWindowText(m_hWnd,OLE2T(pDispParams->rgvarg[0].bstrVal)); break; } /* * OVERRIDE SECURITY BULLSHIT!!! * * This sets what you want to BRING DOWN and this is NOT the * the same as the Secuirty Manager which we will ALSO show how to * override in another part of this program---the choise is yours! * MSHTML will also ask for a new user agent via DISPID_AMBIENT_USERAGENT * when navigating to clicked hyperlinks. * This ambient property can be overridden, but it is not used * when programmatically calling Navigate method; it will also * not cause userAgent property of DOM's navigator object or * clientInformation behavior to be altered - this property * will always reflect Internet Explorer's own UserAgent string. * An MFC host of WebBrowser control can easily affect these * ambient properties by overriding the OnAmbientProperty method * of the hosting CWnd- based class: * Change download properties - allow java, allow scripts... * * SLASH/UNSLASH THIS CODE TO CHANGE THESE SECURITY SETTINGS * */ /* * DISPID for Download Control */ //case DISPID_AMBIENT_DLCONTROL: //{ // Respond to this ambient to indicate what we want to // download or allow with page requested(Java applets, ActiveX, etc.) //CComVariant vtResult(static_cast(m_dwDLControl)); //*pvarResult = vtResult; //VARIANT* pVarResult = NULL; //pVarResult->vt = VT_I4; //pVarResult->lVal = DLCTL_NO_SCRIPTS | DLCTL_NO_JAVA // | DLCTL_NO_RUNACTIVEXCTLS | DLCTL_NO_DLACTIVEXCTLS; // Don't ask the user anything---you are in charge! //pVarResult->lVal = DLCTL_SILENT; //} // Change user agent for this web browser host during hyperlinks //case DISPID_AMBIENT_USERAGENT: //{ // CString strUserAgent; // strUserAgent = "KissMyAss"; // pVarResult->vt = VT_BSTR; // pVarResult->bstrVal = strUserAgent.AllocSysString(); //} //case DISPID_AMBIENT_USERMODE: //{ // // put MSHTML into design mode! // V_VT(pVarResult) = VT_BOOL; // V_BOOL(pVarResult) = VARIANT_FALSE; // break; //} /////////////////////////////////////////////////////////// /////////////////////////////////////////////////////////// default: return DISP_E_MEMBERNOTFOUND; } return S_OK; } ///////////////////////////////////////// // Private Methods ///////////////////////////////////////// /* * CWBToolBar::WndProc() */ LRESULT CALLBACK MainWndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { if (uMessage == WM_NCCREATE) { LPCREATESTRUCT lpcs = (LPCREATESTRUCT)lParam; SetWindowLong(hWnd, GWL_USERDATA, (LONG)lpcs->lpCreateParams); } CWBToolBar* pThis = reinterpret_cast ( GetWindowLong(hWnd, GWL_USERDATA)); if (pThis) return pThis->WndProc(hWnd, uMessage, wParam, lParam); else return DefWindowProc(hWnd, uMessage, wParam, lParam); } LRESULT CWBToolBar::WndProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam) { switch (uMessage) { case WM_NCCREATE: { // Set window handle _hWnd = hWnd; } break; case WM_PAINT: return OnPaint(); case WM_COMMAND: return OnCommand(wParam, lParam); case WM_SETFOCUS: return OnSetFocus(); case WM_KILLFOCUS: return OnKillFocus(); case WM_SIZE: return OnSize(); case WM_DESTROY: /* * HARD REFEENCE COUNTNG! * WARNING BRO: If you used Open in the Window context * menu item in I.E. 5 the WM_DESTROY message is sent * to the band for each window so you MUST keep count * of the number of windows open and only call Cleanup() * if WM_DESTROY is intended for the main window */ Cleanup(); return 0; } return DefWindowProc(hWnd, uMessage, wParam, lParam); } /* * CWBToolBar::OnPaint() */ LRESULT CWBToolBar::OnPaint(void) { PAINTSTRUCT ps; BeginPaint(_hWnd, &ps); EndPaint(_hWnd, &ps); /////////////////////////// //PAINTSTRUCT ps; //RECT rc; //BeginPaint(_hWnd, &ps); //GetClientRect(_hWnd, &rc); //SetTextColor(ps.hdc, RGB(255, 255, 255)); //SetBkMode(ps.hdc, TRANSPARENT); //DrawText(ps.hdc, TEXT("SerGio"), -1, &rc, DT_SINGLELINE | DT_LEFT | DT_VCENTER); //EndPaint(_hWnd, &ps); ////////////////////////////// return 0; } /* * CWBToolBar::OnCommand() */ LRESULT CWBToolBar::OnCommand(WPARAM wParam, LPARAM lParam) { _RPT0(_CRT_WARN, "CWBToolBar::OnCommand\n"); return 0; } /* * CWBToolBar::FocusChange() */ void CWBToolBar::FocusChange(BOOL fFocus) { _RPT1(_CRT_WARN, "FocusChange: %s\n", fFocus ? "True" : "False"); // Tell input object site focus has changed // if (_pSite) _pSite->OnFocusChangeIS(static_cast (this), fFocus); } /* * CWBToolBar::SetFocus() */ LRESULT CWBToolBar::OnSetFocus(void) { _RPT0(_CRT_WARN, "OnSetFocus\n"); FocusChange(TRUE); return 0; } /* * CWBToolBar::OnKillFocus() */ LRESULT CWBToolBar::OnKillFocus(void) { _RPT0(_CRT_WARN, "OnKillFocus\n"); FocusChange(FALSE); return 0; } /* * CWBToolBar::OnSize() */ LRESULT CWBToolBar::OnSize(void) { HRESULT hr = E_FAIL; if (_pIOleIPObject) { RECT rcClient; //GetClientRect(_hWnd, &rcClient); GetClientRect(_hwndParent, &rcClient); rcClient.top += -2; rcClient.bottom += 2; hr = _pIOleIPObject->SetObjectRects(&rcClient, &rcClient); _ASSERT(SUCCEEDED(hr)); } return hr; } /* * CWBToolBar::RegisterAndCreateWindow() */ BOOL CWBToolBar::RegisterAndCreateWindow(void) { // If window doesn't exist yet, create it now. if (!_hWnd) { // Can't create a child without a parent // unless you believe in immaculate conception // if (!_hwndParent) return FALSE; // If window class has not been registered, then do so WNDCLASS wc; if (!GetClassInfo(g_hInst, EB_CLASS_NAME, &wc)) { ZeroMemory(&wc, sizeof(wc)); //wc.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS ; wc.style = NULL ; wc.lpfnWndProc = (WNDPROC)MainWndProc; wc.cbClsExtra = 0; wc.cbWndExtra = 0; wc.hInstance = g_hInst; wc.hIcon = NULL; wc.hCursor = LoadCursor(NULL, IDC_ARROW); wc.hbrBackground = NULL; //wc.hbrBackground = (HBRUSH)CreateSolidBrush(RGB(0, 0, 192)); //wc.hbrBackground = (HBRUSH)COLOR_INACTIVEBORDER; wc.hbrBackground = CreateSolidBrush(GetSysColor(COLOR_WINDOW)); wc.lpszMenuName = NULL; wc.lpszClassName = EB_CLASS_NAME; if (!RegisterClass(&wc)) { // If RegisterClass fails, CreateWindow below will fail } } RECT rc; //GetClientRect(_hWnd, &rc); _hwndWB ::GetClientRect(_hwndParent, &rc); // Create the window. The WndProc will set _hWnd // WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN | WS_CLIPSIBLINGS, // YOU CAN ADD WS_CLIPCHILDREN TO REDUCE FLICKER IF NECESSARY CreateWindowEx( NULL, EB_CLASS_NAME, NULL, WS_VISIBLE | WS_CHILD | WS_CLIPCHILDREN, rc.left, rc.top, rc.right - rc.left, rc.bottom - rc.top, _hwndParent, NULL, g_hInst, (LPVOID)this); // create window (optional method) /* CWnd* pParent = CWnd::FromHandle(_hwndParent); ASSERT_VALID(pParent); CRect rc; pParent->GetClientRect(&rc); if (!CWnd::Create(EB_CLASS_NAME, NULL, WS_CHILD|WS_CLIPSIBLINGS, rc, pParent, _dwBandID, NULL)) { //TRACE(_T("Failed to create window!?\n")); return FALSE; } */ } return (NULL != _hWnd); } /* * CWBToolBar::AdviseWBEventSink() */ void CWBToolBar::AdviseWBEventSink(void) { _ASSERT(_pWebBrowserOC); if (_pWebBrowserOC) { LPCONNECTIONPOINT pCP = NULL; // Sink WebBrowser Events if (SUCCEEDED(GetConnectionPoint(_pWebBrowserOC, DIID_DWebBrowserEvents2, &pCP))) { pCP->Advise(static_cast (this), &_dwWBCookie); pCP->Release(); } } } /* * CWBToolBar::AdviseFrameWBEventSink() _pFrameWB * * Unslash the code below to SCRAP SHOPPING CARTS * * My company, William SerGio & Co., Inc. has developed sophisticated * SCRAPPERS for Shopping Carts that run a SINK to the main browser * window which is what the code below does, and "SCRAPS" with the * USER's PERMISSION, all of the items from any shopping carts loaded * inside of the main browser window and sends that information BACK * to your website where our Proprietary Search & Landed Costs Engine * will provide an instant list of COMPETITIVE websites where the SAME * items that a user has placed in any shopping cart can be purchased * for LESS MONEY and a quote of what it will cost to ship the items. * Contact Bill SerGio, for more information if you are interested. */ /* void CWBToolBar::AdviseFrameWBEventSink(void) { _ASSERT(_pFrameWB); if (_pFrameWB) { LPCONNECTIONPOINT pFrameCP = NULL; // Sink WebBrowser Events if (SUCCEEDED(GetConnectionPoint(_pFrameWB, DIID_DWebBrowserEvents2, &pFrameCP))) { pFrameCP->Advise(static_cast (this), &_dwWBCookie); pFrameCP->Release(); } } } */ /* * CWBToolBar::UnadviseWBEventSink() */ void CWBToolBar::UnadviseWBEventSink(void) { _ASSERT(_pWebBrowserOC); if (_pWebBrowserOC) { LPCONNECTIONPOINT pCP = NULL; // Unadvise the WebBrowser Event Sink if (_dwWBCookie && SUCCEEDED(GetConnectionPoint(_pWebBrowserOC, DIID_DWebBrowserEvents2, &pCP))) { pCP->Unadvise(_dwWBCookie); pCP->Release(); --_dwWBCookie; } } } /* * CWBToolBar::UnadviseFrameWBEventSink() * * AUTHOR: BILL SERGIO * * Unslash this code if you want to implement sink in main * browser window to do shit like scrapping shopping carts to * offer comptitive pricing, prevent kids from seeing adult * websites, and killing popup ads. */ /* void CWBToolBar::UnadviseFrameWBEventSink(void) { _ASSERT(_pFrameWB); if (_pFrameWB) { LPCONNECTIONPOINT pFrameCP = NULL; // Unadvise the WebBrowser Event Sink if (_dwWBCookie && SUCCEEDED(GetConnectionPoint(_pFrameWB, DIID_DWebBrowserEvents2, &pFrameCP))) { pFrameCP->Unadvise(_dwWBCookie); pFrameCP->Release(); --_dwWBCookie; } } } */ /* * CWBToolBar::AdviseAnchorsEventSink() * * Description: When a toolbar link is clicked it will automatically * navigate inside the band window so we must sink events * for all anchors in the toolbar's html file. We can't * change navigation in BeforeNavigate2 event handler * because there are some things we want to navigate in * main browser window, such as search results. Certain * anchors contain a target frame name that the I.E. Band * uses to determine where navigation should occur, but we * I.E. doesn't pass the name to us. */ void CWBToolBar::ManageAnchorsEventSink(AdviseType adviseType) { _ASSERT(_pWebBrowserOC); if (adviseType == Unadvise && _stackAnchorCookies.empty()) return; if (_pWebBrowserOC) { // Sink Anchor Events IDispatch* pDisp; if (SUCCEEDED(_pWebBrowserOC->get_Document(&pDisp)) && pDisp) { IHTMLDocument2* pDoc; HRESULT hr = pDisp->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pDoc); pDisp->Release(); if (FAILED(hr)) return; // // Advise all anchors so we can get onclick events. For some // pages, anchors collection is empty so we have to iterate // through entire all collection and advise each anchor tag // IHTMLElementCollection* pElemColl; hr = pDoc->get_all(&pElemColl); pDoc->Release(); if (FAILED(hr)) return; long lNumElems = 0; pElemColl->get_length(&lNumElems); for (int i = 0; i < lNumElems; i++) { _variant_t vtItem((long)i), vtEmpty; hr = pElemColl->item(vtItem, vtEmpty, &pDisp); if (FAILED(hr)) break; // Get IHTMLElement interface IHTMLElement* pElem; hr = pDisp->QueryInterface(IID_IHTMLElement, (LPVOID*)&pElem); pDisp->Release(); if (FAILED(hr)) break; BSTR bstr; hr = pElem->get_tagName(&bstr); // MUST FREE BSTR!!! SysFreeString(bstr); if (SUCCEEDED(hr)) { _bstr_t bstrTagName(bstr); if (!lstrcmpi((LPCSTR)bstrTagName, (LPCSTR)"A")) { LPCONNECTIONPOINT pCP = NULL; if (SUCCEEDED(GetConnectionPoint(pElem, DIID_HTMLAnchorEvents, &pCP))) { if (adviseType == Advise) { DWORD dwCookie; // Connect the event sink hr = pCP->Advise(static_cast (this), &dwCookie); if (SUCCEEDED(hr)) _stackAnchorCookies.push(dwCookie); pCP->Release(); } else if (!_stackAnchorCookies.empty()) { // Disconnect event sink hr = pCP->Unadvise(_stackAnchorCookies.top()); pCP->Release(); _stackAnchorCookies.pop(); } } } // MUST FREE BSTR!!! SysFreeString(bstrTagName); } pElem->Release(); } pElemColl->Release(); } } } /* * CWBToolBar::AdviseFrameAnchorsEventSink() * * AUTHOR: BILL SERGIO * * Unslash this code if you want to implement sink in main * browser window to do shit like scrapping shopping carts to * offer comptitive pricing, prevent kids from seeing adult * websites, and killing popup ads. */ /* void CWBToolBar::ManageFrameAnchorsEventSink(AdviseType adviseType) { //_pFrameWB //pFrameCP _ASSERT(_pFrameWB); if (adviseType == Unadvise && _stackAnchorCookies.empty()) return; if (_pFrameWB) { // Sink Anchor Events IDispatch* pDisp; if (SUCCEEDED(_pFrameWB->get_Document(&pDisp)) && pDisp) { IHTMLDocument2* pDoc; HRESULT hr = pDisp->QueryInterface(IID_IHTMLDocument2, (LPVOID*)&pDoc); pDisp->Release(); if (FAILED(hr)) return; // // Advise all anchors so we can get onclick events. For some // pages, anchors collection is empty so we have to iterate // through entire all collection and advise each anchor tag // IHTMLElementCollection* pElemColl; hr = pDoc->get_all(&pElemColl); pDoc->Release(); if (FAILED(hr)) return; long lNumElems = 0; pElemColl->get_length(&lNumElems); for (int i = 0; i < lNumElems; i++) { _variant_t vtItem((long)i), vtEmpty; hr = pElemColl->item(vtItem, vtEmpty, &pDisp); if (FAILED(hr)) break; // Get the IHTMLElement interface IHTMLElement* pElem; hr = pDisp->QueryInterface(IID_IHTMLElement, (LPVOID*)&pElem); pDisp->Release(); if (FAILED(hr)) break; BSTR bstr; hr = pElem->get_tagName(&bstr); if (SUCCEEDED(hr)) { _bstr_t bstrTagName(bstr); // MUST FREE BSTR!!! SysFreeString(bstr); if (!lstrcmpi(bstrTagName, "A")) { LPCONNECTIONPOINT pFrameCP = NULL; if (SUCCEEDED(GetConnectionPoint(pElem, DIID_HTMLAnchorEvents, &pFrameCP))) { if (adviseType == Advise) { DWORD dwCookie; // Connect the event sink hr = pFrameCP->Advise(static_cast (this), &dwCookie); if (SUCCEEDED(hr)) _stackAnchorCookies.push(dwCookie); pFrameCP->Release(); } else if (!_stackAnchorCookies.empty()) { // Disconnect the event sink hr = pFrameCP->Unadvise(_stackAnchorCookies.top()); pFrameCP->Release(); _stackAnchorCookies.pop(); } } } // MUST FREE BSTR!!! SysFreeString(bstrTagName); } pElem->Release(); } pElemColl->Release(); } } } */ /* * CWBToolBar::GetConnectionPoint() */ HRESULT CWBToolBar::GetConnectionPoint(LPUNKNOWN pUnk, REFIID riid, LPCONNECTIONPOINT* ppCP) { _ASSERT(_pWebBrowserOC); HRESULT hr = E_FAIL; IConnectionPointContainer* pCPC; if (_pWebBrowserOC) { hr = pUnk->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pCPC); if (FAILED(hr)) return hr; hr = pCPC->FindConnectionPoint(riid, ppCP); pCPC->Release(); } return hr; } /* * CWBToolBar::GetFrameConnectionPoint() * * AUTHOR: BILL SERGIO * * Unslash this code if you want to implement sink in main * browser window to do shit like scrapping shopping carts to * offer comptitive pricing, prevent kids from seeing adult * websites, and killing popup ads. */ /* HRESULT CWBToolBar::GetFrameConnectionPoint(LPUNKNOWN pUnk, REFIID riid, LPCONNECTIONPOINT* ppFrameCP) { //_pFrameWB //pFrameCP _ASSERT(_pFrameWB); HRESULT hr = E_FAIL; IConnectionPointContainer* pFrameCPC; if (_pFrameWB) { hr = pUnk->QueryInterface(IID_IConnectionPointContainer, (LPVOID*)&pFrameCPC); if (FAILED(hr)) return hr; hr = pFrameCPC->FindConnectionPoint(riid, ppFrameCP); pFrameCPC->Release(); } return hr; } */ /* * CWBToolBar::Cleanup() * * Description: HARD REFERENCE COUNTING DUDES! * Release all interfaces we are holding onto! * This has to be done HERE because I.E. will NOT * release all of our interfaces! So our ref count * never reaches 0 and we never delete ourself! */ void CWBToolBar::Cleanup(void) { if (_pSite) { _pSite->Release(); _pSite = NULL; } if (_pIOleIPObject) { _pIOleIPObject->Release(); _pIOleIPObject = NULL; } if (_pWebBrowserOC) { UnadviseWBEventSink(); ManageAnchorsEventSink(Unadvise); _pWebBrowserOC->Release(); _pWebBrowserOC = NULL; } if (_pFrameWB) { //UnadviseFrameWBEventSink(); //ManageFrameAnchorsEventSink(Unadvise); _pFrameWB->Release(); _pFrameWB = NULL; } if (_pIOleObject) { _pIOleObject->Release(); _pIOleObject= NULL; } InterlockedDecrement(&g_cDllRefCount); } bool CWBToolBar::GetShellPath(CString csName) { TCHAR szShellFile[MAX_PATH]; static TCHAR strNull[2] = _T(""); //DWORD dwType; DWORD dwSize = MAX_PATH; //DWORD dwRet; DWORD dwType; HKEY hKey; // Open the appropriate registry key LONG lResult = RegOpenKeyEx( HKEY_LOCAL_MACHINE, _T("Software\\TVToolbar\\Shell"), 0, KEY_ALL_ACCESS, &hKey ); if( ERROR_SUCCESS != lResult ) return FALSE; lResult = RegQueryValueEx( hKey, (LPCSTR)csName, NULL, &dwType, (BYTE*)szShellFile, &dwSize ); RegCloseKey( hKey ); //AfxMessageBox( (LPCSTR)szShellFile ); //if( ERROR_SUCCESS != lResult ) // return FALSE; BOOL bOk; STARTUPINFO si; PROCESS_INFORMATION pi; memset(&si,0,sizeof(STARTUPINFO)); si.cb = sizeof(STARTUPINFO); si.wShowWindow = SW_SHOW; if (lResult == ERROR_SUCCESS) { if ( csName == "slickskins" ) { char szSkin[MAX_PATH]; lstrcpy(szSkin, TEXT("/skin%videoskins%")); ShellExecute(NULL, "open", szShellFile, szSkin, NULL, SW_SHOWNORMAL); //bOk = CreateProcess(NULL,szShellFile,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi); } else{ //strcat(lpszExeDir, TEXT("\\slickskins.exe")); bOk = CreateProcess(NULL,szShellFile,NULL,NULL,FALSE,0,NULL,NULL,&si,&pi); } } CloseHandle(pi.hThread); CloseHandle(pi.hProcess); if ( !bOk ) { if ( csName == "manual" ) { CString aa = "C:\\Program Files\\TVToolbar\\manual.chm"; ShellExecute(NULL, "open", aa, NULL, NULL, SW_SHOWNORMAL); } } return TRUE; } HRESULT CWBToolBar::NavigateChm(LPCTSTR lpszChmFile, UINT mapID, LPCTSTR lpszTargetFrameName) { m_csChm = (LPCSTR)lpszChmFile; mapID = TB_MAIN; if (!m_paMapIds) { CHitsFile its; if (FAILED(its.OpenITS(m_csChm))) return STG_E_PATHNOTFOUND ; IStream* pStream; if (FAILED(its.OpenStream("#IVB", &pStream, its.GetStorage()))) { TRACE1("Missing [MAP] section in chm file %s", m_csChm); return STG_E_FILENOTFOUND; } ULONG cbRead; DWORD cbMapIds; if (FAILED(pStream->Read(&cbMapIds, sizeof(DWORD), &cbRead)) || (cbRead != sizeof(DWORD))) { pStream->Release(); return STG_E_READFAULT; } if (!(m_paMapIds = (MAPID*) LocalAlloc(LMEM_FIXED, cbMapIds))) { pStream->Release(); return E_OUTOFMEMORY ; } if (FAILED(pStream->Read(m_paMapIds, cbMapIds, &cbRead)) || (cbRead != (ULONG) cbMapIds)) { pStream->Release(); return STG_E_READFAULT; } pStream->Release(); m_cMapIds = cbMapIds / sizeof(MAPID); } for (int i = 0; i < m_cMapIds; i++) { if (mapID == m_paMapIds[i].mapid) { CHitsFile its; if (FAILED(its.OpenITS(m_csChm))) return STG_E_PATHNOTFOUND ; CStringSubFile ssf(&its); TCHAR szURL[MAX_PATH * 2]; wsprintf(szURL, "its:%s::", (LPCTSTR) m_csChm); ssf.GetString(m_paMapIds[i].offset, szURL + strlen(szURL), sizeof(szURL) - strlen(szURL)); lstrcat(szURL, TEXT("#_tbload")); COleVariant vtEmpty; COleVariant vaURL(szURL); return _pWebBrowserOC->Navigate2(vaURL, &vtEmpty, &vtEmpty, &vtEmpty, &vtEmpty); } } return E_FAIL; } LPTSTR CWBToolBar::StrChr(LPCTSTR psz, TCHAR ch) { while (*psz && *psz != ch) psz = CharNext(psz); return (*psz ? (TCHAR*) psz : NULL); } LPTSTR CWBToolBar::StrRChr(LPCTSTR psz, TCHAR ch) { LPCTSTR pszLastFound = StrChr(psz, ch); if (!pszLastFound) return NULL; while ((psz = StrChr(pszLastFound + 1, ch))) pszLastFound = psz; return (LPTSTR) pszLastFound; } void CWBToolBar::AddTrailingBackslash(LPTSTR psz) { ASSERT(psz && *psz); TCHAR* pszEnd = psz + strlen(psz); if (*(CharPrev(psz, pszEnd)) != '\\' && *(CharPrev(psz, pszEnd)) != '/' && *(CharPrev(psz, pszEnd)) != ':') { *pszEnd++ = '\\'; *pszEnd++ = '\0'; } }