none
关于IExecuteCommand的应用 RRS feed

  • 问题

  • 我编写了一个扩展组件实现了 IExecuteCommand 其接口,该接口主要是操作文件夹的操作,当用户双击会调用接口的函数

    代码如下:

     

    class ATL_NO_VTABLE CTxtIconShlExt : 
        public CComObjectRootEx<CComSingleThreadModel>
        ,public CComCoClass<CTxtIconShlExt, &CLSID_TxtIconShlExt>
        ,public IDispatchImpl<ITxtIconShlExt, &IID_ITxtIconShlExt, &LIBID_TXTFILEICONSLib>
    ,public IExecuteCommand
    ,public IObjectWithSite
    ,public IObjectWithSelection
    {
    public:
        CTxtIconShlExt()
        {
    GUID CLSID_ExecuteFolder;
    CLSID_ExecuteFolder.Data1=0x11dbb47c;
    CLSID_ExecuteFolder.Data2=0xa525;
    CLSID_ExecuteFolder.Data3=0x400b;
    CLSID_ExecuteFolder.Data4[0]=0x9e;
    CLSID_ExecuteFolder.Data4[1]=0x80;
    CLSID_ExecuteFolder.Data4[2]=0xa5;
    CLSID_ExecuteFolder.Data4[3]=0x46;
    CLSID_ExecuteFolder.Data4[4]=0x15;
    CLSID_ExecuteFolder.Data4[5]=0xa0;
    CLSID_ExecuteFolder.Data4[6]=0x90;
    CLSID_ExecuteFolder.Data4[7]=0xc0;


    IUnknown* pUnk;
    HRESULT hr = CoCreateInstance(
    CLSID_ExecuteFolder,
    NULL,
    CLSCTX_SERVER,
    IID_IUnknown,
    (void**)&pUnk);
    if (FAILED(hr))
    {
    return;
    }

    //IExecuteCommand* pExecuteCmd;
    hr=pUnk->QueryInterface(IID_IExecuteCommand,(void**)&m_pExecuteCommand);
    if (FAILED(hr))
    {
    return;
    }
    hr=pUnk->QueryInterface(IID_IObjectWithSelection,(void**)&m_pObjectWithSelection);
    if (FAILED(hr))
    {
    return;
    }
    hr=pUnk->QueryInterface(IID_IObjectWithSite,(void**)&m_pIObjectWithSite);
    if (FAILED(hr))
    {
    return;
    }

        }

    DECLARE_REGISTRY_RESOURCEID(IDR_TXTICONSHLEXT)

    DECLARE_PROTECT_FINAL_CONSTRUCT()



    BEGIN_COM_MAP(CTxtIconShlExt)
        COM_INTERFACE_ENTRY(ITxtIconShlExt)
        COM_INTERFACE_ENTRY(IDispatch)
    COM_INTERFACE_ENTRY(IExecuteCommand)
    COM_INTERFACE_ENTRY(IObjectWithSelection)
    COM_INTERFACE_ENTRY(IObjectWithSite)
    END_COM_MAP()

    public:

    //IExecuteCommand
    STDMETHODIMP SetKeyState(DWORD grfKeyState) 
    {
    return m_pExecuteCommand->SetKeyState(grfKeyState) ;
    //MessageBoxA(NULL,__FUNCTION__,"",MB_OK); return S_OK; 
    }
    STDMETHODIMP SetParameters(LPCWSTR pszParameters) 

    return m_pExecuteCommand->SetParameters(pszParameters) ;
    //MessageBoxA(NULL,__FUNCTION__,"",MB_OK);return S_OK; 
    }
    STDMETHODIMP SetPosition(POINT pt) 

    return m_pExecuteCommand->SetPosition(pt) ;
    //MessageBoxA(NULL,__FUNCTION__,"",MB_OK);return S_OK; 
    }
    STDMETHODIMP SetShowWindow(int nShow) 

    return m_pExecuteCommand->SetShowWindow(nShow) ;
    // MessageBoxA(NULL,__FUNCTION__,"",MB_OK);return S_OK; 
    }
    STDMETHODIMP SetNoShowUI(BOOL fNoShowUI) 

    return m_pExecuteCommand->SetNoShowUI(fNoShowUI) ;
    // MessageBoxA(NULL,__FUNCTION__,"",MB_OK);return S_OK; 
    }
    STDMETHODIMP SetDirectory(LPCWSTR pszDirectory) 

    return m_pExecuteCommand->SetDirectory(pszDirectory) ;
    //MessageBoxA(NULL,__FUNCTION__,"",MB_OK);return S_OK; 
    }
    STDMETHODIMP Execute()

    return m_pExecuteCommand->Execute() ;
    //MessageBoxA(NULL,__FUNCTION__,"",MB_OK);return S_OK;
    };

    // *** IObjectWithSelection ***
    STDMETHODIMP SetSelection(IShellItemArray *psia) 
    {
    //MessageBoxA(NULL,__FUNCTION__,"",MB_OK); return S_OK; 
    return m_pObjectWithSelection->SetSelection(psia);
    }
    STDMETHODIMP GetSelection(REFIID riid, void **ppv) 

    //MessageBoxA(NULL,__FUNCTION__,"",MB_OK);return S_OK; 
    return m_pObjectWithSelection->GetSelection(riid,ppv);
    }

    //
    STDMETHODIMP GetSite (
    REFIID riid,
    void ** ppvSite
    )
    {
    return m_pIObjectWithSite->GetSite(riid,ppvSite);
    }

    STDMETHODIMP SetSite (  IUnknown * pUnkSite)
    {
    return m_pIObjectWithSite->SetSite(pUnkSite);
    }


    protected:
    IExecuteCommand* m_pExecuteCommand;
    IObjectWithSelection* m_pObjectWithSelection;
    IObjectWithSite* m_pIObjectWithSite;
    };

    #endif //__TXTICONSHLEXT_H_

    我想知道如何让其正常调用会系统的接口 IExecuteCommand,IObjectWithSelection以及IObjectWithSite

    2019年8月16日 1:57

全部回复