Exemple #1
0
HRESULT CConnect::OnConnection(LPDISPATCH Application, ext_ConnectMode ConnectMode, LPDISPATCH AddInInst, SAFEARRAY **custom)
{
	TSAUTO();
	Application->QueryInterface(__uuidof(IDispatch), reinterpret_cast<LPVOID*>(&this->m_spApplication));
	AddInInst->QueryInterface(__uuidof(IDispatch), reinterpret_cast<LPVOID*>(&this->m_spAddInInstance));
	//是否显示按钮
	CRegKey key;
	DWORD dwValue;
	if(key.Open(HKEY_CURRENT_USER, _T("Software\\WordEncLock")) == ERROR_SUCCESS){
		if (key.QueryValue(dwValue, _T("silent")) == ERROR_SUCCESS){
			if (dwValue == 1){
				g_sIsSilent = TRUE;
			}
		}
	}
	key.Close();
	if (g_sIsSilent){
		return S_OK;
	}
	CComQIPtr<_Application> spApp(Application);
	ATLASSERT(spApp);
	if (!spApp){//获取失败说明是excel
		//g_sIsSilent = TRUE;
		return S_OK;
	}
	g_Application = spApp;
	
	HRESULT hr;
	CComPtr<Office::_CommandBars>  spCmdBars; 
	hr =  g_Application->get_CommandBars(&spCmdBars);
	if(FAILED(hr))
		return hr;
	ATLASSERT(spCmdBars);

	// now we add a new toolband to Word
	// to which we''ll add 2 buttons
	CComVariant vName("");
	CComPtr<Office::CommandBar> spNewCmdBar;

	CComVariant vPos(1); 
	CComVariant vTemp(VARIANT_TRUE); // menu is temporary        
	CComVariant vEmpty(DISP_E_PARAMNOTFOUND, VT_ERROR);            
	spNewCmdBar = spCmdBars->Add(vName, vPos, vEmpty, vTemp);

	CComPtr < Office::CommandBarControls> spBarControls;
	spBarControls = spNewCmdBar->GetControls();
	ATLASSERT(spBarControls);


	CComVariant vToolBarType(1);
	CComVariant vShow(VARIANT_TRUE);
	CComPtr<Office::CommandBarControl>  spNewBar; 

	// add first button
	spNewBar = spBarControls->Add(vToolBarType,vEmpty,vEmpty,vEmpty,vShow); 
	ATLASSERT(spNewBar);

	CComQIPtr < Office::_CommandBarButton> spCmdButton(spNewBar);

	ATLASSERT(spCmdButton);
	m_spButton = spCmdButton;
	AppEvents::DispEventAdvise(m_spButton);

	HBITMAP hBmp =(HBITMAP)::LoadImage(g_hModule,
		MAKEINTRESOURCE(IDB_BITMAP1),IMAGE_BITMAP,0,0,LR_LOADMAP3DCOLORS);
	::OpenClipboard(NULL);
	::EmptyClipboard();
	::SetClipboardData(CF_BITMAP, (HANDLE)hBmp);
	::CloseClipboard();
	::DeleteObject(hBmp);        

	spCmdButton->PutStyle(Office::msoButtonIconAndWrapCaption);
	hr = spCmdButton->PasteFace();
	if (FAILED(hr))
		return hr;
	spCmdButton->PutVisible(VARIANT_TRUE); 
	spCmdButton->PutCaption(OLESTR("Word安全锁")); 
	spCmdButton->PutEnabled(VARIANT_TRUE);
	spCmdButton->PutTooltipText(OLESTR("Word安全锁")); 
	spCmdButton->PutTag(OLESTR("给Word文档加密")); 
	spNewCmdBar->PutVisible(VARIANT_TRUE); 
	return S_OK;
}
Exemple #2
0
BOOL CMFCCefDemoApp::InitInstance()
{
	// 创建 shell 管理器,以防对话框包含
	// 任何 shell 树视图控件或 shell 列表视图控件。
	//CShellManager *pShellManager = new CShellManager;

	// 激活“Windows Native”视觉管理器,以便在 MFC 控件中启用主题
	//CMFCVisualManager::SetDefaultManager(RUNTIME_CLASS(CMFCVisualManagerWindows));

	// 标准初始化
	// 如果未使用这些功能并希望减小
	// 最终可执行文件的大小,则应移除下列
	// 不需要的特定初始化例程
	// 更改用于存储设置的注册表项
	// TODO:  应适当修改该字符串,
	// 例如修改为公司或组织名
	SetRegistryKey(_T("应用程序向导生成的本地应用程序"));

	// Cef 初始化
	class CefAppEmplyImpl : public CefApp
	{
	public:
		CefAppEmplyImpl(){}
		~CefAppEmplyImpl(){}
	protected:
		IMPLEMENT_REFCOUNTING(CefAppEmplyImpl);
	};
	CefRefPtr<CefApp>		spApp(new /*CWebApp*/CefAppEmplyImpl);

	//CefMainArgs main_args(this->m_hInstance);
	CefMainArgs main_args(::GetModuleHandle(NULL));
	int exit_code = CefExecuteProcess(main_args, spApp.get(), NULL);
	if (exit_code >= 0) {
		// The sub-process has completed so return here.
		return exit_code;
	}

	CefRefPtr<CefCommandLine>			CommandLine;
	CefSettings							settings;
	CefSettingsTraits::init(&settings);
	settings.command_line_args_disabled = false;
	settings.single_process = false;
	//中文支持
	// http://blog.sina.com.cn/s/blog_dad2c54101019dav.html
	CefString(&settings.locale).FromASCII("zh-cn");
	//settings.multi_threaded_message_loop = CommandLine->HasSwitch("multi-threaded-message-loop");
	settings.multi_threaded_message_loop = true;

	CefInitialize(main_args, settings, spApp.get(), NULL);


	{
		// 如果一个运行在 Windows XP 上的应用程序清单指定要
		// 使用 ComCtl32.dll 版本 6 或更高版本来启用可视化方式,
		//则需要 InitCommonControlsEx()。  否则,将无法创建窗口。
		INITCOMMONCONTROLSEX InitCtrls;
		InitCtrls.dwSize = sizeof(InitCtrls);
		// 将它设置为包括所有要在应用程序中使用的
		// 公共控件类。
		InitCtrls.dwICC = ICC_WIN95_CLASSES;
		InitCommonControlsEx(&InitCtrls);
		CWinApp::InitInstance();
		AfxEnableControlContainer();
	}



	{
		CMFCCefDemoDlg dlg;
		m_pMainWnd = &dlg;
		INT_PTR nResponse = dlg.DoModal();
		if (nResponse == IDOK)
		{
			// TODO:  在此放置处理何时用
			//  “确定”来关闭对话框的代码
		}
		else if (nResponse == IDCANCEL)
		{
			// TODO:  在此放置处理何时用
			//  “取消”来关闭对话框的代码
		}
		else if (nResponse == -1)
		{
			TRACE(traceAppMsg, 0, "警告: 对话框创建失败,应用程序将意外终止。\n");
			TRACE(traceAppMsg, 0, "警告: 如果您在对话框上使用 MFC 控件,则无法 #define _AFX_NO_MFC_CONTROLS_IN_DIALOGS。\n");
		}
	}
	CefShutdown();

	//CMFCCefDemoDlg* pDlg = new CMFCCefDemoDlg;
	//m_pMainWnd = pDlg;
	//pDlg->Create(MAKEINTRESOURCE(IDD_MFCCEFDEMO_DIALOG), NULL);
	//m_pMainWnd->ShowWindow(SW_SHOWNORMAL);
	//m_pMainWnd->UpdateWindow();
	//{
	//	// Run the CEF message loop. This function will block until the application
	//	// recieves a WM_QUIT message.
	//	CefRunMessageLoop();

	//	CefShutdown();
	//}

// 	// 删除上面创建的 shell 管理器。
// 	if (pShellManager != NULL)
// 	{
// 		delete pShellManager;
// 	}

	

	// 由于对话框已关闭,所以将返回 FALSE 以便退出应用程序,
	//  而不是启动应用程序的消息泵。
	return FALSE;
}