Ejemplo n.º 1
0
bool CCPrinter::doPrint(IOleCommandTarget* target, string printTemplatePathStr, bool printOrPreview , bool dontPromptUser){
	
	//将路径解析为宽字符
	std::wstring widestr = std::wstring(printTemplatePathStr.begin(), printTemplatePathStr.end());
	const wchar_t* printTemplatePath = widestr.c_str();
	
	//获取浏览器命名对象
	IOleCommandTarget* pCmdTarg = this->getIOleCommandTarget();

	DWORD nCmdID;
	DWORD nCmdexecopt;
	if (printOrPreview){
	    //如果是直接打印
		nCmdID = IDM_PRINT;
	}
	else{
		nCmdID = IDM_PRINTPREVIEW;
	}
	if (dontPromptUser){
		//如果是不提示用户(即不弹出Windows的打印对话框)
		nCmdexecopt = OLECMDEXECOPT_DONTPROMPTUSER;
	}
	else{
		nCmdexecopt = OLECMDEXECOPT_PROMPTUSER;
	}

	CComVariant vPTPath = printTemplatePathStr.c_str();
	pCmdTarg->Exec(&CGID_MSHTML,
		nCmdID,
		nCmdexecopt,
		&vPTPath,
		NULL);
	return true;
}
Ejemplo n.º 2
0
static int CALLBACK DeleteAllEnumCallback(void* pItem, void* pData)
{
    IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
    TRACE("Releasing SSO %p\n", pOct);
    pOct->Release();
    return TRUE;
}
Ejemplo n.º 3
0
static int CALLBACK ShutdownAllCallback(void* pItem, void* pData)
{
    IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
    TRACE("Shutting down SSO %p\n", pOct);
    pOct->Exec(&CGID_ShellServiceObject, OLECMDID_SAVE, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
    return TRUE;
}
Ejemplo n.º 4
0
static int CALLBACK InitializeAllCallback(void* pItem, void* pData)
{
    IOleCommandTarget * pOct = reinterpret_cast<IOleCommandTarget *>(pItem);
    HRESULT * phr = reinterpret_cast<HRESULT *>(pData);
    TRACE("Initializing SSO %p\n", pOct);
    *phr = pOct->Exec(&CGID_ShellServiceObject, OLECMDID_NEW, OLECMDEXECOPT_DODEFAULT, NULL, NULL);
    return SUCCEEDED(*phr);
}
Ejemplo n.º 5
0
// @pymethod |PyIDocHostUIHandler|ShowUI|Description of ShowUI.
PyObject *PyIDocHostUIHandler::ShowUI(PyObject *self, PyObject *args)
{
	IDocHostUIHandler *pIDHUIH = GetI(self);
	if ( pIDHUIH == NULL )
		return NULL;
	// @pyparm int|dwID||Description for dwID
	// @pyparm <o PyIOleInPlaceActiveObject>|pActiveObject||Description for pActiveObject
	// @pyparm <o PyIOleCommandTarget>|pCommandTarget||Description for pCommandTarget
	// @pyparm <o PyIOleInPlaceFrame>|pFrame||Description for pFrame
	// @pyparm <o PyIOleInPlaceUIWindow>|pDoc||Description for pDoc
	PyObject *obpActiveObject;
	PyObject *obpCommandTarget;
	PyObject *obpFrame;
	PyObject *obpDoc;
	DWORD dwID;
	if ( !PyArg_ParseTuple(args, "lOOOO:ShowUI", &dwID, &obpActiveObject, &obpCommandTarget, &obpFrame, &obpDoc) )
		return NULL;
	IOleInPlaceActiveObject * pActiveObject;
	IOleCommandTarget * pCommandTarget;
	IOleInPlaceFrame * pFrame;
	IOleInPlaceUIWindow * pDoc;
	BOOL bPythonIsHappy = TRUE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpActiveObject, IID_IOleInPlaceActiveObject, (void **)&pActiveObject, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpCommandTarget, IID_IOleCommandTarget, (void **)&pCommandTarget, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpFrame, IID_IOleInPlaceFrame, (void **)&pFrame, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (bPythonIsHappy && !PyCom_InterfaceFromPyInstanceOrObject(obpDoc, IID_IOleInPlaceUIWindow, (void **)&pDoc, TRUE /* bNoneOK */))
		 bPythonIsHappy = FALSE;
	if (!bPythonIsHappy) return NULL;
	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIDHUIH->ShowUI( dwID, pActiveObject, pCommandTarget, pFrame, pDoc );
	if (pActiveObject) pActiveObject->Release();
	if (pCommandTarget) pCommandTarget->Release();
	if (pFrame) pFrame->Release();
	if (pDoc) pDoc->Release();
	PY_INTERFACE_POSTCALL;
	if ( FAILED(hr) )
		return PyCom_BuildPyException(hr, pIDHUIH, IID_IDocHostUIHandler );
	return PyInt_FromLong(hr);
}
Ejemplo n.º 6
0
// @pymethod |PyIOleCommandTarget|Exec|Description of Exec.
PyObject *PyIOleCommandTarget::Exec(PyObject *self, PyObject *args)
{
	PyObject *ret;
	int cmdid, cmdopt;
	PyObject *obVar;
	PyObject *obGUID;
	VARIANT varIn, varOut;
	IOleCommandTarget *pIOCT = GetI(self);
	if ( pIOCT == NULL )
		return NULL;
	if (!PyArg_ParseTuple(args, "OiiO", &obGUID, &cmdid, &cmdopt, &obVar))
		return NULL;

	GUID guid;
	GUID *pguid;
	if (obGUID == Py_None) {
		pguid = NULL;
	} else {
		if (!PyWinObject_AsIID(obGUID, &guid))
			return FALSE;
		pguid = &guid;
	}
	VariantInit(&varIn);
	VariantInit(&varOut);
	if (!PyCom_VariantFromPyObject(obVar, &varIn))
		return NULL;

	HRESULT hr;
	PY_INTERFACE_PRECALL;
	hr = pIOCT->Exec( pguid, cmdid, cmdopt, &varIn, &varOut);
	PY_INTERFACE_POSTCALL;
	
	VariantClear(&varIn);

	if ( FAILED(hr) ) {
		PyCom_BuildPyException(hr, pIOCT, IID_IOleCommandTarget );
		ret = NULL;
	} else {
		ret = PyCom_PyObjectFromVariant(&varOut);
	}
	VariantClear(&varOut);
	return ret;
}
Ejemplo n.º 7
0
// 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;
}
Ejemplo n.º 8
0
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 );
}
Ejemplo n.º 9
0
// 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;
}
Ejemplo n.º 11
0
// @pymethod |PyIOleCommandTarget|QueryStatus|Description of QueryStatus.
PyObject *PyIOleCommandTarget::QueryStatus(PyObject *self, PyObject *args)
{
	PyObject *ret = NULL;
	PyObject *obGUID, *obCmds;
	IOleCommandTarget *pIOCT = GetI(self);
	OLECMD *pCmds = NULL;
	OLECMDTEXT *retText = NULL;
	if ( pIOCT == NULL )
		return NULL;
	if (!PyArg_ParseTuple(args, "OO", &obGUID, &obCmds))
		return NULL;

	GUID guid;
	GUID *pguid;
	if (obGUID == Py_None) {
		pguid = NULL;
	} else {
		if (!PyWinObject_AsIID(obGUID, &guid))
			return FALSE;
		pguid = &guid;
	}
	if (!PySequence_Check(obCmds))
		return PyErr_Format(PyExc_TypeError, "cmds must be a sequence");

	int ncmds = PySequence_Length(obCmds);
	HRESULT hr;
	// From here, exit via 'goto done'
	const unsigned cbCmdText = 1024;
	retText = (OLECMDTEXT *)malloc(cbCmdText);
	if (!retText) {
		PyErr_NoMemory();
		goto done;
	}
	retText->cwBuf = (cbCmdText - sizeof(OLECMDTEXT)) / sizeof(WCHAR);

	pCmds = (OLECMD *)malloc(ncmds * sizeof(OLECMD));
	if (!pCmds) {
		PyErr_NoMemory();
		goto done;
	}
	if (!FillOLECMDsWithSequence(pCmds, ncmds, obCmds))
		goto done;
	{ // scope to prevent goto warning.
	PY_INTERFACE_PRECALL;
	hr = pIOCT->QueryStatus( pguid, ncmds, pCmds, retText );
	PY_INTERFACE_POSTCALL;
	}

	if ( FAILED(hr) ) {
		PyCom_BuildPyException(hr, pIOCT, IID_IOleCommandTarget );
		goto done;
	}
	ret = Py_BuildValue("iN", retText->cmdtextf,
			    PyWinObject_FromWCHAR(retText->rgwz));
done:
	if (retText)
		free(retText);
	if (pCmds)
		free(pCmds);
	return ret;
}