// IDocHostUIHandler STDMETHODIMP IEView::ShowContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdTarget, IDispatch *pdispReserved) { IOleCommandTarget * pOleCommandTarget; IOleWindow * pOleWindow; HWND hSPWnd; if (builder == NULL) { // return S_OK; } if (SUCCEEDED(pcmdTarget->QueryInterface(IID_IOleCommandTarget, (void**)&pOleCommandTarget))) { if (SUCCEEDED(pOleCommandTarget->QueryInterface(IID_IOleWindow, (void**)&pOleWindow))) { pOleWindow->GetWindow(&hSPWnd); HMENU hMenu; hMenu = GetSubMenu(LoadMenu(hInstance, MAKEINTRESOURCE(IDR_CONTEXTMENU)),0); CallService(MS_LANGPACK_TRANSLATEMENU,(WPARAM)hMenu,0); if (dwID == 5) { // anchor EnableMenuItem(hMenu, ID_MENU_COPYLINK, MF_BYCOMMAND | MF_ENABLED); } else if (dwID == 4) { // text select EnableMenuItem(hMenu, ID_MENU_COPY, MF_BYCOMMAND | MF_ENABLED); } else if (dwID == 1) { // control (image) EnableMenuItem(hMenu, ID_MENU_SAVEIMAGE, MF_BYCOMMAND | MF_ENABLED); } if (builder!=NULL) { } int iSelection = TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, ppt->x, ppt->y, 0, hwnd, (RECT*)NULL); DestroyMenu(hMenu); if (iSelection == ID_MENU_CLEARLOG) { clear(NULL); } else { SendMessage(hSPWnd, WM_COMMAND, iSelection, (LPARAM) NULL); } pOleWindow->Release(); } pOleCommandTarget->Release(); } return S_OK; }
STDMETHODIMP ExplorerBar::SetSite( IUnknown *inPunkSite ) { AFX_MANAGE_STATE( AfxGetStaticModuleState() ); HRESULT err; // Release the old interfaces. if( mWebBrowser ) { mWebBrowser->Release(); mWebBrowser = NULL; } if( mSite ) { mSite->Release(); mSite = NULL; } // A non-NULL site means we're setting the site. Otherwise, the site is being released (done above). if( !inPunkSite ) { err = S_OK; goto exit; } // Get the parent window. IOleWindow * oleWindow; mParentWindow = NULL; err = inPunkSite->QueryInterface( IID_IOleWindow, (LPVOID *) &oleWindow ); require( SUCCEEDED( err ), exit ); err = oleWindow->GetWindow( &mParentWindow ); oleWindow->Release(); require_noerr( err, exit ); require_action( mParentWindow, exit, err = E_FAIL ); // Get the IInputObject interface. err = inPunkSite->QueryInterface( IID_IInputObjectSite, (LPVOID *) &mSite ); require( SUCCEEDED( err ), exit ); check( mSite ); // Get the IWebBrowser2 interface. IOleCommandTarget * oleCommandTarget; err = inPunkSite->QueryInterface( IID_IOleCommandTarget, (LPVOID *) &oleCommandTarget ); require( SUCCEEDED( err ), exit ); IServiceProvider * serviceProvider; err = oleCommandTarget->QueryInterface( IID_IServiceProvider, (LPVOID *) &serviceProvider ); oleCommandTarget->Release(); require( SUCCEEDED( err ), exit ); err = serviceProvider->QueryService( SID_SWebBrowserApp, IID_IWebBrowser2, (LPVOID *) &mWebBrowser ); serviceProvider->Release(); require( SUCCEEDED( err ), exit ); // Create the main window. err = SetupWindow(); require_noerr( err, exit ); exit: return( err ); }
// IDocHostUIHandler STDMETHODIMP IEView::ShowContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdTarget, IDispatch *pdispReserved) { IOleCommandTarget * pOleCommandTarget; IOleWindow * pOleWindow; HWND hSPWnd; if (builder == NULL) { return S_OK; } if (SUCCEEDED(pcmdTarget->QueryInterface(IID_IOleCommandTarget, (void**)&pOleCommandTarget))) { if (SUCCEEDED(pOleCommandTarget->QueryInterface(IID_IOleWindow, (void**)&pOleWindow))) { pOleWindow->GetWindow(&hSPWnd); HMENU hMenu; hMenu = GetSubMenu(LoadMenu(hInstance, MAKEINTRESOURCE(IDR_CONTEXTMENU)),0); CallService(MS_LANGPACK_TRANSLATEMENU,(WPARAM)hMenu,0); if (dwID == 5) { // anchor EnableMenuItem(hMenu, ID_MENU_COPYLINK, MF_BYCOMMAND | MF_ENABLED); } if (dwID == 4) { // text select EnableMenuItem(hMenu, ID_MENU_COPY, MF_BYCOMMAND | MF_ENABLED); } if (builder!=NULL) { } int iSelection = TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, ppt->x, ppt->y, 0, hwnd, (RECT*)NULL); DestroyMenu(hMenu); if (iSelection == ID_MENU_CLEARLOG) { /* IEVIEWEVENT event; event.cbSize = sizeof(IEVIEWEVENT); event.dwFlags=0; event.codepage = CP_ACP; BSTR selection = (BSTR)getSelection(&event); if (selection == NULL) { MessageBoxW(NULL, L"", L"NULL SELECTION", MB_OK); } else if (wcslen(selection)==0) { MessageBoxW(NULL, selection, L"EMPTY SELECTION", MB_OK); } else { MessageBoxW(NULL, selection, L"SELECTION", MB_OK); } event.dwFlags=IEEF_NO_UNICODE; char *selectionA = (char *)getSelection(&event); if (selectionA == NULL) { MessageBoxA(NULL, "", "NULL SELECTION", MB_OK); } else if (strlen(selectionA)==0) { MessageBoxA(NULL, selectionA, "EMPTY SELECTION", MB_OK); } else { MessageBoxA(NULL, selectionA, "SELECTION", MB_OK); } */ clear(); } else { SendMessage(hSPWnd, WM_COMMAND, iSelection, (LPARAM) NULL); } pOleWindow->Release(); } pOleCommandTarget->Release(); } return S_OK; }