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

📄 polyline.cpp

📁 英文版的 想要的话可以下载了 为大家服务
💻 CPP
📖 第 1 页 / 共 3 页
字号:
            //Call IOleAdviseHolder::SendOnRename (later)
            break;

        case OBJECTCODE_SAVEOBJECT:
            if (m_fDirty && NULL!=m_pIOleClientSite)
                m_pIOleClientSite->SaveObject();

            m_fDirty=FALSE;
            break;

        case OBJECTCODE_DATACHANGED:
            m_fDirty=TRUE;

            //No flags are necessary here.
            if (NULL!=m_pIDataAdviseHolder)
                {
                m_pIDataAdviseHolder->SendOnDataChange
                    (m_pImpIDataObject, 0, 0);
                }

            if (NULL!=m_pIAdviseSink
                & (dwAspect & m_dwAdviseAspects))
                {
                m_pIAdviseSink->OnViewChange(dwAspect
                    & m_dwAdviseAspects, 0);
                }

            break;

        case OBJECTCODE_SHOWWINDOW:
            if (NULL!=m_pIOleClientSite)
                m_pIOleClientSite->OnShowWindow(TRUE);

            break;

        case OBJECTCODE_HIDEWINDOW:
            if (NULL!=m_pIOleClientSite)
                m_pIOleClientSite->OnShowWindow(FALSE);

            break;

        case OBJECTCODE_SHOWOBJECT:
            if (NULL!=m_pIOleClientSite)
                m_pIOleClientSite->ShowObject();

            break;
        }

    return;
    }




/*
 * CPolyline::InPlaceActivate
 *
 * Purpose:
 *  Goes through all the steps of activating the Polyline as an
 *  in-place object.
 *
 * Parameters:
 *  pActiveSite     LPOLECLIENTSITE of the active site we show in.
 *  fIncludeUI      BOOL controls whether we call UIActivate too.
 *
 * Return Value:
 *  HRESULT         Whatever error code is appropriate.
 */

HRESULT CPolyline::InPlaceActivate(LPOLECLIENTSITE pActiveSite
    , BOOL fIncludeUI)
    {
    HRESULT                 hr;
    HWND                    hWnd;
    HWND                    hWndHW;
    RECT                    rcPos;
    RECT                    rcClip;
    OLEINPLACEFRAMEINFO     frameInfo;

    if (NULL==pActiveSite)
        return ResultFromScode(E_INVALIDARG);

    if (NULL!=m_pIOleIPSite)
        {
        if (fIncludeUI)
            UIActivate();

        return NOERROR;
        }


    //1.  Initialization, obtaining interfaces, OnInPlaceActivate.
    hr=pActiveSite->QueryInterface(IID_IOleInPlaceSite
        , (PPVOID)&m_pIOleIPSite);

    if (FAILED(hr))
        return hr;

    hr=m_pIOleIPSite->CanInPlaceActivate();

    if (NOERROR!=hr)
        {
        m_pIOleIPSite->Release();
        m_pIOleIPSite=NULL;
        return ResultFromScode(E_FAIL);
        }

    m_pIOleIPSite->OnInPlaceActivate();


    //2.  Get the window context and create a window.
    m_pIOleIPSite->GetWindow(&hWnd);
    frameInfo.cb=sizeof(OLEINPLACEFRAMEINFO);

    m_pIOleIPSite->GetWindowContext(&m_pIOleIPFrame
        , &m_pIOleIPUIWindow, &rcPos, &rcClip, &frameInfo);


    /*
     * Create the hatch window after we get a parent window.  We
     * could not create the hatch window sooner because had nothing
     * to use for the parent.
     */
    m_pHW=new CHatchWin(m_hInst);

    if (NULL==m_pHW)
        {
        InPlaceDeactivate();
        return ResultFromScode(E_OUTOFMEMORY);
        }

    if (!m_pHW->Init(hWnd, ID_HATCHWINDOW, NULL))
        {
        InPlaceDeactivate();
        return ResultFromScode(E_OUTOFMEMORY);
        }


    //Make sure dialog is hidden
    if (NULL!=m_hDlg)
        {
        ShowWindow(m_hDlg, SW_HIDE);
        SendAdvise(OBJECTCODE_HIDEWINDOW);
        }

    //Move the hatch window to the container window.
    hWndHW=m_pHW->Window();
    SetParent(hWndHW, hWnd);

    //Move the Polyline window from the hidden dialog to hatch window
    m_pHW->HwndAssociateSet(m_hWnd);
    m_pHW->ChildSet(m_hWnd);
    m_pHW->RectsSet(&rcPos, &rcClip);   //Positions polyline

    ///CHAPTER24MOD
    //This might be off when we get to here.
    if (!m_fHatch)
        m_pHW->ShowHatch(FALSE);
    //End CHAPTER24MOD

    ShowWindow(hWndHW, SW_SHOW);
    SendAdvise(OBJECTCODE_SHOWOBJECT);

    //Critical for accelerators to work initially.
    SetFocus(hWndHW);

    //3, 4, 5.  Do UI things: active object, shared menu, tools
    hr=NOERROR;

    if (fIncludeUI)
        hr=UIActivate();

    /*
     * Since we don't have an Undo while in-place, tell the continer
     * to free it's undo state immediately.
     */
    m_pIOleIPSite->DiscardUndoState();

    return hr;
    }




/*
 * CPolyline::InPlaceDeactivate
 *
 * Purpose:
 *  Reverses all the activation steps from InPlaceActivate.
 *
 * Parameters:
 *  None
 *
 * Return Value:
 *  None
 */

void CPolyline::InPlaceDeactivate(void)
    {
    UIDeactivate();

    if (NULL!=m_pHW)
        {
        RECT        rc;

        ShowWindow(m_pHW->Window(), SW_HIDE);

        //Reposition the polyline window in the dialog box.
        SetParent(m_hWnd, m_hDlg);
        CalcPolyRectInDialog(m_hDlg, &rc);

        SetWindowPos(m_hWnd, NULL, rc.left, rc.top
            , rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER);

        m_pHW->ChildSet(NULL);

        delete m_pHW;
        m_pHW=NULL;
        }

    ReleaseInterface(m_pIOleIPFrame);
    ReleaseInterface(m_pIOleIPUIWindow)

    if (NULL!=m_pIOleIPSite)
        {
        m_pIOleIPSite->OnInPlaceDeactivate();
        ReleaseInterface(m_pIOleIPSite);
        }

    return;
    }



/*
 * CPolyline::UIActivate
 *
 * Purpose:
 *  Goes through all the steps of activating the user interface of
 *  Polyline as an in-place object.
 *
 * Parameters:
 *  None
 *
 * Return Value:
 *  HRESULT         NOERROR or error code.
 */

HRESULT CPolyline::UIActivate(void)
    {
    //1.  Call IOleInPlaceSite::UIActivate
    if (NULL!=m_pIOleIPSite)
        m_pIOleIPSite->OnUIActivate();

    //2.  Set the active object
   #ifdef WIN32ANSI
    OLECHAR     szTemp[40];

    MultiByteToWideChar(CP_ACP, 0, PSZ(IDS_USERTYPE)
        , -1, szTemp, 40);
   #endif

    if (NULL!=m_pIOleIPFrame)
        {
        m_pIOleIPFrame->SetActiveObject(m_pImpIOleIPActiveObject
           #ifdef WIN32ANSI
            , szTemp);
           #else
            , PSZ(IDS_USERTYPE));
           #endif
        }

    if (NULL!=m_pIOleIPUIWindow)
        {
        m_pIOleIPUIWindow->SetActiveObject(m_pImpIOleIPActiveObject
           #ifdef WIN32ANSI
            , szTemp);
           #else
            , PSZ(IDS_USERTYPE));
           #endif
        }

    //3.  Critical for accelerators to work initially.
    SetFocus(m_pHW->Window());

    //4.  Negotiate border space.  Polyline doesn't need any.
    if (NULL!=m_pIOleIPFrame)
        m_pIOleIPFrame->SetBorderSpace(NULL);

    if (NULL!=m_pIOleIPUIWindow)
        m_pIOleIPUIWindow->SetBorderSpace(NULL);


    /*
     * 5.  Create the shared menu.  We don't have any, so tell
     *     the container to use its own menu.
     */

    if (NULL!=m_pIOleIPFrame)
        m_pIOleIPFrame->SetMenu(NULL, NULL, m_hWnd);

    m_fUIActive=TRUE;
    return NOERROR;
    }





/*
 * CPolyline::UIDeactivate
 *
 * Purpose:
 *  Reverses all the user interface activation steps from
 *  UIActivate.
 *
 * Parameters:
 *  None
 *
 * Return Value:
 *  None
 */

void CPolyline::UIDeactivate(void)
    {
    m_fUIActive=FALSE;

    //We don't have any shared menu or tools to clean up.

    //Clear out the active objects
    if (NULL!=m_pIOleIPFrame)
        m_pIOleIPFrame->SetActiveObject(NULL, NULL);

    if (NULL!=m_pIOleIPUIWindow)
        m_pIOleIPUIWindow->SetActiveObject(NULL, NULL);

    if (NULL!=m_pIOleIPSite)
        m_pIOleIPSite->OnUIDeactivate(FALSE);

    return;
    }


//CHAPTER24MOD

/*
 * AmbientGet
 *
 * Purpose:
 *  Retrieves a specific ambient property into a VARIANT.
 *
 * Parameters:
 *  dispID          DISPID of the property to retrieve.
 *  pva             VARIANT * to fill with the new value.
 *
 * Return value
 *  BOOL            TRUE if the ambient was retrieved, FALSE
 *                  otherwise.
 */

BOOL CPolyline::AmbientGet(DISPID dispID, VARIANT *pva)
    {
    HRESULT         hr;
    DISPPARAMS      dp;

    if (NULL==pva)
        return FALSE;

    if (NULL==m_pIDispatchAmbients)
        return FALSE;

    SETNOPARAMS(dp);
    hr=m_pIDispatchAmbients->Invoke(dispID, IID_NULL
        , LOCALE_USER_DEFAULT, DISPATCH_PROPERTYGET
        , &dp, pva, NULL, NULL);

    return SUCCEEDED(hr);
    }


/*
 * AmbientsInitialize
 *
 * Purpose:
 *  Attempts to retrieve the container's ambient properties
 *  and initialize (or reinitialize) Polyline accordingly.
 *
 * Parameters:
 *  dwWhich         DWORD containing INITAMBIENT_... flags
 *                  describing which ambients to initialize.
 *                  This can be any combination.
 *
 * Return Value:
 *  None
 */

void CPolyline::AmbientsInitialize(DWORD dwWhich)
    {
    VARIANT     va;
    COLORREF    cr;

    if (NULL==m_pIDispatchAmbients)
        return;

    /*
     * We need to retrieve these ambients into these variables:
     *
     *  Ambient Property:               Variable:
     *  -----------------------------------------------
     *  DISPID_AMBIENT_SHOWHATCHING     m_fHatch
     *  DISPID_AMBIENT_UIDEAD           m_fUIDead
     *  DISPID_AMBIENT_BACKCOLOR        m_pl.rgbBackground
     *  DISPID_AMBIENT_FORECOLOR        m_pl.rgbLine
     */

    if ((INITAMBIENT_SHOWHATCHING & dwWhich)
        &&AmbientGet(DISPID_AMBIENT_SHOWHATCHING, &va))
        {
        m_fHatch=V_BOOL(&va);

        if (NULL!=m_pHW)
            m_pHW->ShowHatch(m_fHatch);
        }

    if ((INITAMBIENT_UIDEAD & dwWhich)
        && AmbientGet(DISPID_AMBIENT_UIDEAD, &va))
        {
        //This affects our detection of mouse clicks
        m_fUIDead=V_BOOL(&va);
        }

    if ((INITAMBIENT_BACKCOLOR & dwWhich)
        && AmbientGet(DISPID_AMBIENT_BACKCOLOR, &va))
        {
        cr=V_I4(&va);

        if (0x80000000 & cr)
            cr=GetSysColor(cr & 0x7FFFFFFF);

        m_pl.rgbBackground=cr;
        InvalidateRect(m_hWnd, NULL, TRUE);
        UpdateWindow(m_hWnd);
        }

    if ((INITAMBIENT_FORECOLOR & dwWhich)
        && AmbientGet(DISPID_AMBIENT_FORECOLOR, &va))
        {
        cr=V_I4(&va);

        if (0x80000000 & cr)
            cr=GetSysColor(cr & 0x7FFFFFFF);

        m_pl.rgbLine=cr;
        InvalidateRect(m_hWnd, NULL, TRUE);
        UpdateWindow(m_hWnd);
        }

    return;
    }

//End CHAPTER24MOD

⌨️ 快捷键说明

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