Beispiel #1
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;
}
Beispiel #2
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;
}
Beispiel #3
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);
}
// @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;
}
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;
}