⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dsofcontrol.cpp

📁 用于在线office文档编辑的控件。可以在线新建文档、修改文档
💻 CPP
📖 第 1 页 / 共 5 页
字号:
	return;
}

////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::OnComponentActivationChange
//
//  Handles showing/hiding doc object during activation state changes.
//  This is needed to properly handle focus changes when more than one
//  instance of the control is running on the same top-level window.
//
STDMETHODIMP_(void) CDsoFramerControl::OnComponentActivationChange(BOOL fActivate)
{
	TRACE1("CDsoFramerControl::OnComponentActivationChange(%d)\n", fActivate);

	if ((fActivate) && (!m_fComponentActive))
	{
		m_fComponentActive = TRUE;

		if (m_pDocObjFrame)
			ShowWindow(m_pDocObjFrame->GetDocWindow(), SW_SHOW);

		OnAppActivation(TRUE, NULL);
	}
	else if ((!fActivate) && (m_fComponentActive))
	{

 		OnAppActivation(FALSE, NULL);

		if (m_pDocObjFrame)
		{
		    if (m_hbmDeactive) DeleteObject(m_hbmDeactive);
            m_hbmDeactive = DsoGetBitmapFromWindow(m_pDocObjFrame->GetDocWindow());
			ShowWindow(m_pDocObjFrame->GetDocWindow(), SW_HIDE);
		}

		m_fComponentActive = FALSE;
	}
}

////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::UpdateActivationState
//
//  Called when activation state for this control changes (if host app
//  loses focus to another application, or user switches between mulitple
//  DsoFramer controls in the same application). Lets us know of change in
//  activation after the fact (when we can also grab focus).
//
STDMETHODIMP_(void) CDsoFramerControl::UpdateActivationState(BOOL fActive)
{
 // We don't really need to do anything here except notify host of the change
 // made early by rasing a COM event so they can also take note of the change...
    if ((m_dispEvents) && !(m_fFreezeEvents) && !(m_fModalState))
    {
        VARIANT rgargs[1]; memset(rgargs, 0, sizeof(VARIANT) * 1);
        rgargs[0].vt = VT_BOOL; rgargs[0].boolVal = (fActive ? VARIANT_TRUE : VARIANT_FALSE);
	    DsoDispatchInvoke(m_dispEvents, NULL, DSOF_DISPID_ACTIVATE, 0, 1, rgargs, NULL);
        OnResize();
    }
    return;
}


////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::OnAppActivation
//
//  This method is called from the subclassed parent to notify us of
//  WM_ACTIVATEAPP messages which we pass on to ui active docobject. This
//  notification is required by docobject spec.
//
STDMETHODIMP_(void) CDsoFramerControl::OnAppActivation(BOOL fActive, DWORD dwThreadID)
{
	TRACE1("CDsoFramerControl::OnAppActivation(Active=%d)\n", fActive);
	if (m_pDocObjFrame) m_pDocObjFrame->OnNotifyAppActivate(fActive, dwThreadID);
    PostMessage(m_hwnd, DSO_WM_ASYNCH_STATECHANGE, DSO_STATE_ACTIVATION, (LPARAM)fActive);
}

////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::OnPaletteChanged
//
//  This method is also called from the subclassed parent. Per docobject
//  spec, a ui active object should get first chance of any palette updates.
//
STDMETHODIMP_(void) CDsoFramerControl::OnPaletteChanged(HWND hwndPalChg)
{
	ODS("CDsoFramerControl::OnPaletteChanged\n");
	if (m_pDocObjFrame)	m_pDocObjFrame->OnNotifyPaletteChanged(hwndPalChg);
}

////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::GetActivePopupMenu
//
//  Constructs our popup menu and returns the handle. The menu can be
//  either the File menu by itself (no docobj is open) or the merged
//  menu as a popup.
//
STDMETHODIMP_(HMENU) CDsoFramerControl::GetActivePopupMenu()
{
	HMENU hPopup, hMergedMenu, hServerMenu;

 // If we haven't made a File menu yet, make it. Here is where you might
 // want to add custom items if you have other file-level commands you would
 // the control to support. These are the basics...
	if (!m_hmenuFilePopup)
	{
		m_hmenuFilePopup = CreatePopupMenu(); m_cMenuItems = 0;
		if (!m_hmenuFilePopup) return NULL;

		AppendMenu(m_hmenuFilePopup, MF_STRING,    MNU_NEW,     "新建文档(&N)...\tCtrl+N");
		AppendMenu(m_hmenuFilePopup, MF_STRING,    MNU_OPEN,    "打开文档(&O)...\tCtrl+O");
		AppendMenu(m_hmenuFilePopup, MF_STRING,    MNU_CLOSE,   "关闭文档(&C)");
		AppendMenu(m_hmenuFilePopup, MF_SEPARATOR, 0,            NULL);
	//	AppendMenu(m_hmenuFilePopup, MF_STRING,    MNU_SAVE,    "保存(&S)\tCtrl+S");
	//	AppendMenu(m_hmenuFilePopup, MF_STRING,    MNU_SAVEAS,  "另存为(&A)...");
	//	AppendMenu(m_hmenuFilePopup, MF_SEPARATOR, 0,            NULL);
		AppendMenu(m_hmenuFilePopup, MF_STRING,    MNU_PGSETUP, "页面设置(&U)...");
//		AppendMenu(m_hmenuFilePopup, MF_STRING,    MNU_PRINTPV, "打印预览(&V)");
		AppendMenu(m_hmenuFilePopup, MF_STRING,    MNU_PRINT,   "打印(&P)...");
		AppendMenu(m_hmenuFilePopup, MF_SEPARATOR, 0,            NULL);
		AppendMenu(m_hmenuFilePopup, MF_STRING,    MNU_PROPS,   "属性(&I)");
	}

 // If we have a docobj and it has a merged menu, then lets return a 
 // merged menu between the docobj and our file menu...
	if ((m_pDocObjFrame) && (m_pDocObjFrame->GetMenuHWND()))
	{
	 // We only need to create the merged copy once.
		if (!(hMergedMenu = m_pDocObjFrame->GetMergedMenu()))
		{
			hMergedMenu = CreatePopupMenu(); m_cMenuItems = 0;
			if ((hMergedMenu) && (hServerMenu = (m_pDocObjFrame->GetActiveMenu())))
			{
				char szbuf[MAX_PATH];
				HMENU hT;

				int cbMenuCnt = GetMenuItemCount(hServerMenu);
				for (int i = 0; i < cbMenuCnt; i++)
				{
					hT = GetSubMenu(hServerMenu, i);
					if (hT)
					{
						szbuf[0] = '\0';
						GetMenuString(hServerMenu, i, szbuf, MAX_PATH, MF_BYPOSITION);
						InsertMenu(hMergedMenu, i, MF_BYPOSITION|MF_POPUP, (UINT)hT, szbuf);
					}
				}

				InsertMenu(hMergedMenu, 0, MF_BYPOSITION|MF_POPUP, (UINT)m_hmenuFilePopup, "&File");
				m_pDocObjFrame->SetMergedMenu(hMergedMenu);                
			}
		}

		hPopup = hMergedMenu;
	}
	else hPopup = m_hmenuFilePopup;

	return hPopup;
}


////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::FRunningInDesignMode
//
//  Determines if we are in design mode. Called when painting the control
//  and when deciding whether to subclass the parent.
//
STDMETHODIMP_(BOOL) CDsoFramerControl::FRunningInDesignMode()
{
	IDispatch *pdisp;

 // We must have a control site.
	CHECK_NULL_RETURN(m_pClientSite, FALSE);

 // If we have done this before, we don't need to keep doing it unless
 // the host has notified us of the state change (see our code in 
 // XOleControl::OnAmbientPropertyChange)...
	if ((!m_fModeFlagValid) && 
		SUCCEEDED(m_pClientSite->QueryInterface(IID_IDispatch, (void **)&pdisp)))
	{
		VARIANT vtUserMode;
		m_fDesignMode = FALSE; // assume run mode

		if (SUCCEEDED(DsoDispatchInvoke(pdisp, NULL, 
				DISPID_AMBIENT_USERMODE, DISPATCH_PROPERTYGET, 0, NULL, &vtUserMode)))
		{
		 // UserMode is True when control is in Run mode, False when in design.
		 // We assume run mode, so we only care to set the flag if in design.
			m_fDesignMode = !(BOOL_FROM_VARIANT(vtUserMode, TRUE));
			VariantClear(&vtUserMode);
		}

		m_fModeFlagValid = TRUE;
     // Release the IDispatch pointer...
        pdisp->Release();
	}

	return m_fDesignMode;
}

////////////////////////////////////////////////////////////////////////
// CDsoFramerControl::ControlWindowProc
//
//  The window proc for our control.
//
STDMETHODIMP_(LRESULT) CDsoFramerControl::ControlWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	CDsoFramerControl* pCtl = (CDsoFramerControl*)GetWindowLong(hwnd, GWL_USERDATA);
	if (pCtl)
	{
		switch (msg)
		{
			case WM_PAINT:
			{
				// call the OnDraw routine.
				PAINTSTRUCT ps;
				RECT        rc;
				HDC         hdc;
				hdc = BeginPaint(hwnd, &ps);
				GetClientRect(hwnd, &rc);
				pCtl->OnDraw(DVASPECT_CONTENT, hdc, (RECT*)&rc, NULL, NULL, TRUE);
				EndPaint(hwnd, &ps);
			}
			break;

			case WM_SIZE:
				pCtl->OnResize();
				break;

			case WM_DESTROY:
				pCtl->OnDestroyWindow();
				break;

			case WM_NCDESTROY:
				SetWindowLong(hwnd, GWL_USERDATA, 0);
				break;

			case WM_SETFOCUS:
			case WM_KILLFOCUS:
				pCtl->OnFocusChange((msg == WM_SETFOCUS), (HWND)wParam);
				break;

			case WM_MOUSEMOVE:
				pCtl->OnMouseMove(LOWORD(lParam), HIWORD(lParam));
				break;

			case WM_LBUTTONDOWN:
				pCtl->OnButtonDown(LOWORD(lParam), HIWORD(lParam));
				break;

			case DSO_WM_ASYNCH_OLECOMMAND:
                ODS(" -- Got DSO_WM_ASYNCH_OLECOMMAND\n");
				pCtl->OnToolbarAction((DWORD)wParam);
				break;

			case DSO_WM_ASYNCH_STATECHANGE:
                ODS(" -- Got DSO_WM_ASYNCH_STATECHANGE\n");
                {
                    BOOL fCondition = (lParam != 0);
                    switch (wParam)
                    {
                    case DSO_STATE_MODAL:
                        pCtl->UpdateModalState(fCondition, FALSE);
                        break;
                    case DSO_STATE_ACTIVATION:
                        pCtl->UpdateActivationState(fCondition);
                        break;
                    case DSO_STATE_INTERACTIVE:
                        pCtl->UpdateInteractiveState(fCondition);
                        break;
                    }
                }
                break;

            case WM_ENABLE:
                pCtl->OnWindowEnable((BOOL)wParam);
                break;

			case WM_MENUSELECT:
			case WM_DRAWITEM:
			case WM_MEASUREITEM:
			case WM_ENTERIDLE:
			case WM_INITMENU:
			case WM_INITMENUPOPUP:
			case WM_COMMAND:
				pCtl->OnMenuMessage(msg, wParam, lParam);
				break;
		}

	}

	return DefWindowProc(hwnd, msg, wParam, lParam);
}


////////////////////////////////////////////////////////////////////////
//
// OCX Interfaces for CDsoFramerControl
//
//  NOTE: The automation interfaces are implemented in dsofauto.cpp.
//  The interfaces that follow are largely the interfaces used by the
//  OCX host for normal control containment.
//

////////////////////////////////////////////////////////////////////////
//
// CDsoFramerControl::XInternalUnknown -- Internal IUnknown interface
//     !!! Controls lifetime of CDsoFramerControl !!!
//
//   STDMETHODIMP         QueryInterface(REFIID riid, void ** ppv);
//   STDMETHODIMP_(ULONG) AddRef(void);
//   STDMETHODIMP_(ULONG) Release(void);
//
STDMETHODIMP CDsoFramerControl::XInternalUnknown::QueryInterface(REFIID riid, void** ppv)
{
 // ODS("CDsoFramerControl::InternalQueryInterface\n");
	CHECK_NULL_RETURN(ppv, E_POINTER);
	
	HRESULT hr = S_OK;
	METHOD_PROLOGUE(CDsoFramerControl, InternalUnknown);

	if (IID_IUnknown == riid)
	{
		*ppv = (IUnknown*)this;
	}
	else if ((IID_IDispatch == riid) || (IID__FramerControl == riid))
	{
		*ppv = (_FramerControl*)pThis;
	}
	else if (IID_IOleObject == riid)
	{
		*ppv = (IOleObject*)&(pThis->m_xOleObject);
	}
	else if (IID_IOleControl == riid)
	{
		*ppv = (IOleControl*)&(pThis->m_xOleControl);
	}
	else if (IID_IPersistPropertyBag == riid)
	{
		*ppv = (IPersistPropertyBag*)&(pThis->m_xPersistPropertyBag);
	}
	else if ((IID_IPersistStreamInit == riid) || (IID_IPersistStream == riid) || (IID_IPersist == riid))
	{
		*ppv = (IPersistStreamInit*)&(pThis->m_xPersistStreamInit);
	}
	else if ((IID_IOleInPlaceObject == riid) || (IID_IOleWindow == riid))
	{
		*ppv = (IOleInPlaceObject*)&(pThis->m_xOleInplaceObject);
	}	
	else if (IID_IOleInPlaceActiveObject == riid)
	{
		*ppv = (IOleInPlaceActiveObject*)&(pThis->m_xOleInplaceActiveObject);
	}
	else if ((IID_IViewObjectEx == riid) || (IID_IViewObject == riid) || (IID_IViewObject2 == riid))
	{
		*ppv = (IViewObjectEx*)&(pThis->m_xViewObjectEx);
	}
    else if (IID_IDataObject == riid)
	{
		*ppv = (IDataObject*)&(pThis->m_xDataObject);
	}
	else if (IID_ISupportErrorInfo == riid)
	{
		*ppv = (ISupportErrorInfo*)&(pThis->m_xSupportErrorInfo);
	}
	else if (IID_IProvideClassInfo == riid)
	{
		*ppv = (IProvideClassInfo*)&(pThis->m_xProvideClassInfo);
	}
	else if (IID_IConnectionPointContainer == riid)
	{
		*ppv = (IConnectionPointContainer*)&(pThis->m_xConnectionPointContainer);
	}
	else if (IID_IConnectionPoint == riid)
	{
		*ppv = (IConnectionPoint*)&(pThis->m_xConnectionPoint);
	}
	else if (IID_IEnumConnectionPoints == riid)
	{
		*ppv = (IEnumConnectionPoints*)&(pThis->m_xEnumConnectionPoints);
	}
    else if (IID_IPersistStorage == riid)
	{
		*ppv = (IPersistStorage*)&(pThis->m_xPersistStorage);
	}
	else if (IID_IObjectSafety == riid)
	{

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -