void CSysProgressDlg::Stop() { if ((m_isVisible)&&(m_bValid)) { m_pIDlg->StopProgressDialog(); //Sometimes the progress dialog sticks around after stopping it, //until the mouse pointer is moved over it or some other triggers. //This process finds the hwnd of the progress dialog and hides it //immediately. IOleWindow *pOleWindow; HRESULT hr=m_pIDlg->QueryInterface(IID_IOleWindow,(LPVOID *)&pOleWindow); if(SUCCEEDED(hr)) { HWND hDlgWnd; hr=pOleWindow->GetWindow(&hDlgWnd); if(SUCCEEDED(hr)) { ShowWindow(hDlgWnd, SW_HIDE); } pOleWindow->Release(); } m_isVisible = false; m_pIDlg->Release(); m_bValid = false; } }
void WINAPI duFlash::OnCreate() { IUnknown *pControl = NULL; IUnknown *pContainer = NULL; HRESULT hr = CreateAxControl(this->GetHwnd(), L"ShockwaveFlash.ShockwaveFlash", &pControl, &pContainer); if (FAILED(hr)) return; AxAdviseAll(this, pControl); hr = pControl->QueryInterface(__uuidof(IShockwaveFlash), (void **)&m_pFlash); hr = m_pFlash->put_Movie(m_szURL); hr = m_pFlash->put_AllowFullScreen(L"true"); IOleWindow *pOleWindow = NULL; hr = pControl->QueryInterface(IID_IOleWindow, (void **)&pOleWindow); HWND hWndObject = NULL; pOleWindow->GetWindow(&hWndObject); pOleWindow->Release(); Attach(hWndObject); m_pContainer = pContainer; m_pContainer->AddRef(); pControl->Release(); pContainer->Release(); }
HRESULT CSysProgressDlg::ShowModeless(HWND hWndParent) { EnsureValid(); HRESULT hr = E_FAIL; if (m_bValid) { hr = m_pIDlg->StartProgressDialog(hWndParent, NULL, m_dwDlgFlags, NULL); if (SUCCEEDED(hr)) { m_isVisible = true; // The progress window can be remarkably slow to display, particularly // if its parent is blocked. // This process finds the hwnd for the progress window and gives it a kick... IOleWindow *pOleWindow; HRESULT hr=m_pIDlg->QueryInterface(IID_IOleWindow,(LPVOID *)&pOleWindow); if(SUCCEEDED(hr)) { HWND hDlgWnd; hr=pOleWindow->GetWindow(&hDlgWnd); if(SUCCEEDED(hr)) { ShowWindow(hDlgWnd, SW_NORMAL); } pOleWindow->Release(); } } } return hr; }
void ProgressDialog::Show() { DWORD flags = PROGDLG_NORMAL | PROGDLG_NOMINIMIZE; HRESULT hr = dialog->StartProgressDialog(GetDesktopWindow(), 0, flags, 0); if (!SUCCEEDED(hr)) return; dialog->Timer(PDTIMER_RESET, 0); IOleWindow* pIWnd = 0; if (dialog->QueryInterface(IID_IOleWindow, (void**)&pIWnd) != S_OK) return; HWND windowHandle; if (pIWnd->GetWindow(&windowHandle) != S_OK) { pIWnd->Release(); return; } // Get the center of the screen. this->dialogWindow = windowHandle; HDC hScreenDC = CreateCompatibleDC(0); int screenWidth = GetDeviceCaps(hScreenDC, HORZRES); int screenHeight = GetDeviceCaps(hScreenDC, VERTRES); DeleteDC(hScreenDC); // Get the dialog size. RECT dialogRect; GetWindowRect(dialogWindow, &dialogRect); // Calculate center position for the dialog and reposition it. int centerX = ( screenWidth - (dialogRect.right - dialogRect.left)) / 2; int centerY = ( screenHeight - (dialogRect.bottom - dialogRect.top)) / 2; SetWindowPos(this->dialogWindow, 0, centerX, centerY-20, 0, 0, SWP_NOSIZE | SWP_NOZORDER); }
HRESULT CustomContextMenu(POINT *ppt, IUnknown *pcmdtReserved) { IOleWindow *oleWnd = NULL; HWND hwnd = NULL; HMENU hMainMenu = NULL; HMENU hPopupMenu = NULL; HRESULT hr = 0; INT iSelection = 0; if ((ppt == NULL) || (pcmdtReserved == NULL)) goto error; hr = pcmdtReserved->QueryInterface(IID_IOleWindow, (void**)&oleWnd); if ( (hr != S_OK) || (oleWnd == NULL)) goto error; hr = oleWnd->GetWindow(&hwnd); if ( (hr != S_OK) || (hwnd == NULL)) goto error; hMainMenu = LoadMenu(AfxGetInstanceHandle(), MAKEINTRESOURCE(IDR_CUSTOM_POPUP)); if (hMainMenu == NULL) goto error; hPopupMenu = GetSubMenu(hMainMenu, 0); if (hPopupMenu == NULL) goto error; // Show shortcut menu iSelection = ::TrackPopupMenu(hPopupMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, ppt->x, ppt->y, 0, hwnd, (RECT*)NULL); // Send selected shortcut menu item command to shell if (iSelection != 0) (void) ::SendMessage(hwnd, WM_COMMAND, iSelection, NULL); error: if (hMainMenu != NULL) ::DestroyMenu(hMainMenu); return S_OK; }
IFACEMETHODIMP OnFolderChanging(IFileDialog *fd, IShellItem *si) { DBGW(L"OnFolderChanging\n"); if (!once) { once = TRUE; IOleWindow *ow = NULL; if (SUCCEEDED(fd->QueryInterface(&ow))) { HWND hwnd = NULL; ow->GetWindow(&hwnd); ow->Release(); wnd->AttachWnd(hwnd, label); } } return E_NOTIMPL; }
void open_file_dialog::notify_error(const std::wstring &mainInstruction, const std::wstring &text) { IOleWindow *pWindow = NULL; HRESULT hr = dlg_->QueryInterface(IID_PPV_ARGS(&pWindow)); HWND hDlg; pWindow->GetWindow(&hDlg); TaskDialog( hDlg, NULL, L"Error", L"An error occured", text.c_str(), TDCBF_OK_BUTTON, TD_ERROR_ICON, NULL); }
STDMETHODIMP CDeskBand::SetSite(IUnknown* punkSite) { TRACE_ENTER("CDeskBand::SetSite"); //If a site is being held, release it. if (m_pSite) { m_pSite->Release(); m_pSite = NULL; } //If punkSite is not NULL, a new site is being set. if (punkSite) { //Get the parent window. IOleWindow *pOleWindow; m_hwndParent = NULL; if (SUCCEEDED(punkSite->QueryInterface(IID_IOleWindow, (LPVOID*)&pOleWindow))) { pOleWindow->GetWindow(&m_hwndParent); pOleWindow->Release(); } if (!m_hwndParent) return E_FAIL; if (!RegisterAndCreateWindow()) return E_FAIL; //Get and keep the IInputObjectSite pointer. if (SUCCEEDED(punkSite->QueryInterface(IID_IInputObjectSite, (LPVOID*)&m_pSite))) { return S_OK; } return E_FAIL; } TRACE_EXIT(); return S_OK; }
// 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 CDeskBand::SetSite(IUnknown *pUnkSite) { SAFE_RELEASE(m_pInputObjSite); if (NULL == pUnkSite) { return S_OK; } IOleWindow *pOleWindow = NULL; HRESULT hr = pUnkSite->QueryInterface(IID_IOleWindow, reinterpret_cast<void **>(&pOleWindow)); if (SUCCEEDED(hr)) { HWND hParentWnd = NULL; hr = pOleWindow->GetWindow(&hParentWnd); if (SUCCEEDED(hr)) { m_pDeskBandWin->CreateDeskBand(hParentWnd, g_hDllInst, this); } hr = pUnkSite->QueryInterface(IID_PPV_ARGS(&m_pInputObjSite)); } SAFE_RELEASE(pOleWindow); return hr; }
/** * Saves a rendering of the current site by its host container as a PNG file. * This implementation is derived from IECapt. * * @param outputFile the file to save the PNG output as * @link http://iecapt.sourceforge.net/ */ STDMETHODIMP CCoSnapsie::saveSnapshot( BSTR outputFile, BSTR frameId, LONG drawableScrollWidth, LONG drawableScrollHeight, LONG drawableClientWidth, LONG drawableClientHeight, LONG drawableClientLeft, LONG drawableClientTop, LONG frameBCRLeft, LONG frameBCRTop) { HRESULT hr; HWND hwndBrowser; CComPtr<IOleClientSite> spClientSite; CComQIPtr<IServiceProvider> spISP; CComPtr<IWebBrowser2> spBrowser; CComPtr<IDispatch> spDispatch; CComQIPtr<IHTMLDocument2> spDocument; CComPtr<IHTMLWindow2> spScrollableWindow; CComQIPtr<IViewObject2> spViewObject; CComPtr<IHTMLStyle> spStyle; CComQIPtr<IHTMLElement2> spScrollableElement; CComVariant documentHeight; CComVariant documentWidth; CComVariant viewportHeight; CComVariant viewportWidth; GetSite(IID_IUnknown, (void**)&spClientSite); if (spClientSite == NULL) { Error(L"There is no site."); return E_FAIL; } spISP = spClientSite; if (spISP == NULL) { Error(L"Unable to convert client site to service provider."); return E_FAIL; } // from http://support.microsoft.com/kb/257717 hr = spISP->QueryService(IID_IWebBrowserApp, IID_IWebBrowser2, (void **)&spBrowser); if (FAILED(hr)) { // if we can't query the client site for IWebBrowser2, we're probably // in an HTA. Obtain the IHTMLWindow2 interface pointer by directly // querying the client site's service provider. // http://groups.google.com/group/microsoft.public.vc.language/browse_thread/thread/f8987a31d47cccfe/884cb8f13423039e CComPtr<IHTMLWindow2> spWindow; hr = spISP->QueryService(IID_IHTMLWindow2, &spWindow); if (FAILED(hr)) { Error("Failed to obtain IHTMLWindow2 from service provider"); return E_FAIL; } hr = spWindow->get_document(&spDocument); if (FAILED(hr)) { Error("Failed to obtain IHTMLDocument2 from window"); return E_FAIL; } CComQIPtr<IOleWindow> spOleWindow = spDocument; if (spOleWindow == NULL) { Error("Failed to obtain IOleWindow from document"); return E_FAIL; } hr = spOleWindow->GetWindow(&hwndBrowser); if (FAILED(hr)) { Error("Failed to obtain HWND from OLE window"); return E_FAIL; } hwndBrowser = GetAncestor(hwndBrowser, GA_ROOTOWNER); } else { hr = spBrowser->get_HWND((long*)&hwndBrowser); if (FAILED(hr)) { Error("Failed to get HWND for browser (is this a frame?)"); return E_FAIL; } ie = GetAncestor(hwndBrowser, GA_ROOTOWNER); CComPtr<IDispatch> spDispatch; hr = spBrowser->get_Document(&spDispatch); if (FAILED(hr)) return E_FAIL; spDocument = spDispatch; if (spDocument == NULL) return E_FAIL; IServiceProvider* pServiceProvider = NULL; if (SUCCEEDED(spBrowser->QueryInterface( IID_IServiceProvider, (void**)&pServiceProvider))) { IOleWindow* pWindow = NULL; if (SUCCEEDED(pServiceProvider->QueryService( SID_SShellBrowser, IID_IOleWindow, (void**)&pWindow))) { if (SUCCEEDED(pWindow->GetWindow(&hwndBrowser))) { hwndBrowser = FindWindowEx(hwndBrowser, NULL, _T("Shell DocObject View"), NULL); if (hwndBrowser) { hwndBrowser = FindWindowEx(hwndBrowser, NULL, _T("Internet Explorer_Server"), NULL); } } pWindow->Release(); } pServiceProvider->Release(); } } // Nobody else seems to know how to get IViewObject2?! // http://starkravingfinkle.org/blog/2004/09/ spViewObject = spDocument; if (spViewObject == NULL) { Error(L"Unable to convert document to view object."); return E_FAIL; } CComQIPtr<IHTMLDocument5> spDocument5; spDocument->QueryInterface(IID_IHTMLDocument5, (void**)&spDocument5); if (spDocument5 == NULL) { Error(L"Snapsie requires IE6 or greater."); return E_FAIL; } CComBSTR compatMode; spDocument5->get_compatMode(&compatMode); // In non-standards-compliant mode, the BODY element represents the canvas. if (compatMode == L"BackCompat") { CComPtr<IHTMLElement> spBody; spDocument->get_body(&spBody); if (NULL == spBody) { return E_FAIL; } spBody->getAttribute(CComBSTR("scrollHeight"), 0, &documentHeight); spBody->getAttribute(CComBSTR("scrollWidth"), 0, &documentWidth); spBody->getAttribute(CComBSTR("clientHeight"), 0, &viewportHeight); spBody->getAttribute(CComBSTR("clientWidth"), 0, &viewportWidth); } // In standards-compliant mode, the HTML element represents the canvas. else { CComQIPtr<IHTMLDocument3> spDocument3; spDocument->QueryInterface(IID_IHTMLDocument3, (void**)&spDocument3); if (NULL == spDocument3) { Error(L"Unable to get IHTMLDocument3 handle from document."); return E_FAIL; } // The root node should be the HTML element. CComPtr<IHTMLElement> spRootNode; spDocument3->get_documentElement(&spRootNode); if (NULL == spRootNode) { Error(L"Could not retrieve root node."); return E_FAIL; } CComPtr<IHTMLHtmlElement> spHtml; spRootNode->QueryInterface(IID_IHTMLHtmlElement, (void**)&spHtml); if (NULL == spHtml) { Error(L"Root node is not the HTML element."); return E_FAIL; } spRootNode->getAttribute(CComBSTR("scrollHeight"), 0, &documentHeight); spRootNode->getAttribute(CComBSTR("scrollWidth"), 0, &documentWidth); spRootNode->getAttribute(CComBSTR("clientHeight"), 0, &viewportHeight); spRootNode->getAttribute(CComBSTR("clientWidth"), 0, &viewportWidth); } // Figure out how large to make the window. It's not sufficient to just use the dimensions of the scrolled // viewport because the browser chrome occupies space that must be accounted for as well. RECT ieWindowRect; GetWindowRect(ie, &ieWindowRect); int ieWindowWidth = ieWindowRect.right - ieWindowRect.left; int ieWindowHeight = ieWindowRect.bottom - ieWindowRect.top; RECT contentClientRect; GetClientRect(hwndBrowser, &contentClientRect); int contentClientWidth = contentClientRect.right - contentClientRect.left; int contentClientHeight = contentClientRect.bottom - contentClientRect.top; int chromeWidth = ieWindowWidth - contentClientWidth; int chromeHeight = 2 * (ieWindowHeight - contentClientHeight); int imageHeight = documentHeight.intVal; int imageWidth = documentWidth.intVal; maxWidth = imageWidth + chromeWidth; maxHeight = imageHeight + chromeHeight; long originalHeight, originalWidth; spBrowser->get_Height(&originalHeight); spBrowser->get_Width(&originalWidth); // The resize message is being ignored if the window appears to be maximized. There's likely a // way to bypass that. My ghetto way is to unmaximize the window, then move on with setting // the window to the dimensions we really want. This is okay because we revert back to the // original dimensions afterward. BOOL isMaximized = IsZoomed(ie); if (isMaximized) { ShowWindow(ie, SW_SHOWNORMAL); } // Get the path to this DLL so we can load it up with LoadLibrary. TCHAR dllPath[_MAX_PATH]; GetModuleFileName((HINSTANCE) &__ImageBase, dllPath, _MAX_PATH); // Get the path to the Windows hook we use to allow resizing the window greater than the virtual screen resolution. HINSTANCE hinstDLL = LoadLibrary(dllPath); HOOKPROC hkprcSysMsg = (HOOKPROC)GetProcAddress(hinstDLL, "CallWndProc"); if (hkprcSysMsg == NULL) PrintError(L"GetProcAddress"); // Install the Windows hook. nextHook = SetWindowsHookEx(WH_CALLWNDPROC, hkprcSysMsg, hinstDLL, 0); if (nextHook == 0) PrintError(L"SetWindowsHookEx"); spBrowser->put_Height(maxHeight); spBrowser->put_Width(maxWidth); // Capture the window's canvas to a DIB. CImage image; image.Create(imageWidth, imageHeight, 24); CImageDC imageDC(image); hr = PrintWindow(hwndBrowser, imageDC, PW_CLIENTONLY); if (FAILED(hr)) { Error(L"PrintWindow"); } // I'm not sure if PrintWindow captures alpha blending or not. OleDraw does, but I was having // issues with sizing the browser correctly between quirks and standards modes to capture everything we need. // //RECT rcBounds = { 0, 0, imageWidth, imageHeight }; //hr = OleDraw(spViewObject, DVASPECT_DOCPRINT, imageDC, &rcBounds); //if (FAILED(hr)) //{ // Error(L"OleDraw"); //} UnhookWindowsHookEx(nextHook); // Restore the browser to the original dimensions. if (isMaximized) { ShowWindow(ie, SW_MAXIMIZE); } else { spBrowser->put_Height(originalHeight); spBrowser->put_Width(originalWidth); } hr = image.Save(CW2T(outputFile)); if (FAILED(hr)) { PrintError(L"Failed saving image."); return E_FAIL; } return hr; }
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; }
HRESULT ModifyContextMenu(DWORD dwID, POINT *ppt, IUnknown *pcmdtReserved) { ASSERT((ppt != NULL) && (pcmdtReserved != NULL)); if ((ppt == NULL) || (pcmdtReserved == NULL)) return S_OK; //#define IDR_BROWSE_CONTEXT_MENU 24641 //#define IDR_FORM_CONTEXT_MENU 24640 #define SHDVID_GETMIMECSETMENU 27 #define SHDVID_ADDMENUEXTENSIONS 53 HRESULT hr; HINSTANCE hinstSHDOCLC; HWND hwnd; HMENU hMenu; IOleCommandTarget *spCT; IOleWindow *spWnd; MENUITEMINFO mii = {0}; VARIANT var, var1, var2; hr = pcmdtReserved->QueryInterface(IID_IOleCommandTarget, (void**)&spCT); hr = pcmdtReserved->QueryInterface(IID_IOleWindow, (void**)&spWnd); hr = spWnd->GetWindow(&hwnd); hinstSHDOCLC = LoadLibrary(TEXT("SHDOCLC.DLL")); hMenu = LoadMenu(hinstSHDOCLC, MAKEINTRESOURCE(IDR_BROWSE_CONTEXT_MENU)); hMenu = GetSubMenu(hMenu, dwID); // Get the language submenu hr = spCT->Exec(&CGID_ShellDocView, SHDVID_GETMIMECSETMENU, 0, NULL, &var); mii.cbSize = sizeof(mii); mii.fMask = MIIM_SUBMENU; mii.hSubMenu = (HMENU) var.byref; // Add language submenu to Encoding context item SetMenuItemInfo(hMenu, IDM_LANGUAGE, FALSE, &mii); // Insert Shortcut Menu Extensions from registry V_VT(&var1) = VT_PTR; V_BYREF(&var1) = hMenu; V_VT(&var2) = VT_I4; V_I4(&var2) = dwID; hr = spCT->Exec(&CGID_ShellDocView, SHDVID_ADDMENUEXTENSIONS, 0, &var1, &var2); // Remove View Source ::DeleteMenu(hMenu, IDM_VIEWSOURCE, MF_BYCOMMAND); // Remove the item that produces the exta separator ::DeleteMenu(hMenu, IDM_EXTRA_ITEM, MF_BYCOMMAND); // Show shortcut menu int iSelection = ::TrackPopupMenu(hMenu, TPM_LEFTALIGN | TPM_RIGHTBUTTON | TPM_RETURNCMD, ppt->x, ppt->y, 0, hwnd, (RECT*)NULL); // Send selected shortcut menu item command to shell if (iSelection != 0) LRESULT lr = ::SendMessage(hwnd, WM_COMMAND, iSelection, NULL); FreeLibrary(hinstSHDOCLC); return S_OK; }
HRESULT STDMETHODCALLTYPE CAddressBand::SetSite(IUnknown *pUnkSite) { CComPtr<IShellService> shellService; CComPtr<IUnknown> offset34; HWND parentWindow; IOleWindow *oleWindow; HWND toolbar; static const TBBUTTON buttonInfo[] = { {0, 1, TBSTATE_ENABLED, 0} }; HIMAGELIST normalImagelist; HIMAGELIST hotImageList; HINSTANCE shellInstance; HRESULT hResult; fSite.Release(); if (pUnkSite == NULL) return S_OK; hResult = pUnkSite->QueryInterface(IID_IDockingWindowSite, (void **)&fSite); if (FAILED(hResult)) return hResult; parentWindow = NULL; hResult = pUnkSite->QueryInterface(IID_IOleWindow, (void **)&oleWindow); if (SUCCEEDED(hResult)) { oleWindow->GetWindow(&parentWindow); oleWindow->Release(); } if (!::IsWindow(parentWindow)) return E_FAIL; toolbar = CreateWindowEx(WS_EX_TOOLWINDOW, WC_COMBOBOXEXW, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPCHILDREN | WS_TABSTOP | CCS_NODIVIDER | CCS_NOMOVEY, 0, 0, 500, 250, parentWindow, (HMENU)0xa205, _AtlBaseModule.GetModuleInstance(), 0); if (toolbar == NULL) return E_FAIL; SubclassWindow(toolbar); SendMessage(CBEM_SETEXTENDEDSTYLE, CBES_EX_CASESENSITIVE | CBES_EX_NOSIZELIMIT, CBES_EX_CASESENSITIVE | CBES_EX_NOSIZELIMIT); fEditControl = (HWND)SendMessage(CBEM_GETEDITCONTROL, 0, 0); fComboBox = (HWND)SendMessage(CBEM_GETCOMBOCONTROL, 0, 0); #if 1 hResult = CoCreateInstance(CLSID_AddressEditBox, NULL, CLSCTX_INPROC_SERVER, IID_IAddressEditBox, (void **)&fAddressEditBox); if (FAILED(hResult)) return hResult; #else // instantiate new version #endif hResult = fAddressEditBox->QueryInterface(IID_IShellService, (void **)&shellService); if (FAILED(hResult)) return hResult; hResult = fAddressEditBox->Init(toolbar, fEditControl, 8, pUnkSite /*(IAddressBand *)this*/ ); if (FAILED(hResult)) return hResult; hResult = shellService->SetOwner(pUnkSite); if (FAILED(hResult)) return hResult; // TODO: properly initialize this from registry fGoButtonShown = true; shellInstance = GetModuleHandle(_T("shell32.dll")); normalImagelist = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_NORMAL), 20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION); hotImageList = ImageList_LoadImageW(shellInstance, MAKEINTRESOURCE(IDB_GOBUTTON_HOT), 20, 0, RGB(255, 0, 255), IMAGE_BITMAP, LR_CREATEDIBSECTION); fGoButton = CreateWindowEx(WS_EX_TOOLWINDOW, TOOLBARCLASSNAMEW, 0, WS_CHILD | WS_CLIPSIBLINGS | WS_CLIPCHILDREN | TBSTYLE_LIST | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS | CCS_NODIVIDER | CCS_NOPARENTALIGN | CCS_NORESIZE, 0, 0, 0, 0, m_hWnd, NULL, _AtlBaseModule.GetModuleInstance(), NULL); SendMessage(fGoButton, TB_BUTTONSTRUCTSIZE, sizeof(TBBUTTON), 0); SendMessage(fGoButton, TB_SETMAXTEXTROWS, 1, 0); SendMessage(fGoButton, TB_SETIMAGELIST, 0, (LPARAM)normalImagelist); SendMessage(fGoButton, TB_SETHOTIMAGELIST, 0, (LPARAM)hotImageList); SendMessage(fGoButton, TB_ADDSTRINGW, (WPARAM)_AtlBaseModule.GetResourceInstance(), IDS_GOBUTTONLABEL); SendMessage(fGoButton, TB_ADDBUTTONSW, 1, (LPARAM)&buttonInfo); return hResult; }