标签:
这是另一个例子;
贴上主要代码:
1 #include "stdafx.h" 2 #include <tchar.h> 3 4 #import "libid:95E23C91-BC5A-49F3-8CD1-1FC515597048" version("d.0") 5 rename("GetCommandLine", "VGGetCommandLine") 6 rename("CopyFile", "VGCore") 7 rename("FindWindow", "VGFindWindow") 8 9 #ifdef _MANAGED 10 #pragma managed(push, off) 11 #endif 12 13 BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved ) 14 { 15 switch (fdwReason) 16 { 17 case DLL_PROCESS_ATTACH: 18 case DLL_THREAD_ATTACH: 19 case DLL_THREAD_DETACH: 20 case DLL_PROCESS_DETACH: 21 break; 22 } 23 return TRUE; 24 } 25 26 #ifdef _MANAGED 27 #pragma managed(pop) 28 #endif 29 30 class CVGAppPlugin : public VGCore::IVGAppPlugin 31 { 32 private: 33 VGCore::IVGApplication *m_pApp; 34 ULONG m_ulRefCount; 35 long m_lCookie; 36 bool m_bEnabled; 37 38 bool CheckSelection(); 39 void OnClearFill(); 40 41 public: 42 CVGAppPlugin(); 43 44 // IUnknown 45 public: 46 STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject); 47 STDMETHOD_(ULONG, AddRef)(void) { return ++m_ulRefCount; } 48 STDMETHOD_(ULONG, Release)(void) 49 { 50 ULONG ulCount = --m_ulRefCount; 51 if(ulCount == 0) 52 { 53 delete this; 54 } 55 return ulCount; 56 } 57 58 // IDispatch 59 public: 60 STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { return E_NOTIMPL; } 61 STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) { return E_NOTIMPL; } 62 STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) { return E_NOTIMPL; } 63 STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr); 64 65 // IVGAppPlugin 66 public: 67 STDMETHOD(raw_OnLoad)(VGCore::IVGApplication *Application); 68 STDMETHOD(raw_StartSession)(); 69 STDMETHOD(raw_StopSession)(); 70 STDMETHOD(raw_OnUnload)(); 71 }; 72 73 bool CVGAppPlugin::CheckSelection() 74 { 75 bool bRet = false; 76 if(m_pApp->Documents->Count > 0) 77 { 78 bRet = (m_pApp->ActiveSelection->Shapes->Count > 0); 79 } 80 return bRet; 81 } 82 83 void CVGAppPlugin::OnClearFill() 84 { 85 if(CheckSelection()) 86 { 87 m_pApp->ActiveSelection->Fill->ApplyNoFill(); 88 } 89 } 90 91 CVGAppPlugin::CVGAppPlugin() : 92 m_pApp(NULL), 93 m_lCookie(0), 94 m_ulRefCount(1), 95 m_bEnabled(false) 96 { 97 } 98 99 STDMETHODIMP CVGAppPlugin::QueryInterface(REFIID riid, void **ppvObject) 100 { 101 HRESULT hr = S_OK; 102 m_ulRefCount++; 103 if(riid == IID_IUnknown) 104 { 105 *ppvObject = (IUnknown *)this; 106 } 107 else if(riid == IID_IDispatch) 108 { 109 *ppvObject = (IDispatch *)this; 110 } 111 else if(riid == __uuidof(VGCore::IVGAppPlugin)) 112 { 113 *ppvObject = (VGCore::IVGAppPlugin *)this; 114 } 115 else 116 { 117 m_ulRefCount--; 118 hr = E_NOINTERFACE; 119 } 120 return hr; 121 } 122 123 STDMETHODIMP CVGAppPlugin::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr) 124 { 125 switch(dispIdMember) 126 { 127 case 0x0011: //DISPID_APP_SELCHANGE 128 m_bEnabled = CheckSelection(); 129 break; 130 131 case 0x0014: // DISPID_APP_ONPLUGINCMD 132 if(pDispParams != NULL && pDispParams->cArgs == 1) 133 { 134 _bstr_t strCmd(pDispParams->rgvarg[0].bstrVal); 135 if(strCmd == _bstr_t("ClearFill")) 136 { 137 OnClearFill(); 138 } 139 } 140 break; 141 142 case 0x0015: // DISPID_APP_ONPLUGINCMDSTATE 143 if(pDispParams != NULL && pDispParams->cArgs == 3) 144 { 145 _bstr_t strCmd(pDispParams->rgvarg[2].bstrVal); 146 if(strCmd == _bstr_t("ClearFill")) 147 { 148 *pDispParams->rgvarg[1].pboolVal = m_bEnabled ? VARIANT_TRUE : VARIANT_FALSE; 149 } 150 } 151 break; 152 } 153 return S_OK; 154 } 155 156 STDMETHODIMP CVGAppPlugin::raw_OnLoad(VGCore::IVGApplication *Application) 157 { 158 m_pApp = Application; 159 if(m_pApp) 160 { 161 m_pApp->AddRef(); 162 } 163 return S_OK; 164 } 165 166 STDMETHODIMP CVGAppPlugin::raw_StartSession() 167 { 168 try 169 { 170 m_pApp->AddPluginCommand(_bstr_t("ClearFill"), _bstr_t("Clear Fill"), _bstr_t("Clears fill from selected objects")); 171 VGCore::CommandBarControlPtr ctl = m_pApp->CommandBars->Item[_bstr_t("Standard")]->Controls->AddCustomButton(VGCore::cdrCmdCategoryPlugins, _bstr_t("ClearFill"), 0, VARIANT_TRUE); 172 _bstr_t bstrPath(m_pApp->Path + _bstr_t("Plugins\\ClearFill.bmp")); 173 ctl->SetCustomIcon(bstrPath); 174 m_lCookie = m_pApp->AdviseEvents(this); 175 } 176 catch(_com_error &e) 177 { 178 MessageBox(NULL, e.Description(), _T("Error"), MB_ICONSTOP); 179 } 180 return S_OK; 181 } 182 183 STDMETHODIMP CVGAppPlugin::raw_StopSession() 184 { 185 try 186 { 187 m_pApp->UnadviseEvents(m_lCookie); 188 m_pApp->RemovePluginCommand(_bstr_t("ClearFill")); 189 } 190 catch(_com_error &e) 191 { 192 MessageBox(NULL, e.Description(), _T("Error"), MB_ICONSTOP); 193 } 194 return S_OK; 195 } 196 197 STDMETHODIMP CVGAppPlugin::raw_OnUnload() 198 { 199 if(m_pApp) 200 { 201 m_pApp->Release(); 202 m_pApp = NULL; 203 } 204 return S_OK; 205 } 206 207 extern "C" __declspec(dllexport) DWORD APIENTRY AttachPlugin(VGCore::IVGAppPlugin **ppIPlugin) 208 { 209 *ppIPlugin = new CVGAppPlugin; 210 return 0x100; 211 }
下载:
ClearFill_src.zip
ClearFill_cpg.zip
C++ 编写 CorelDRAW CPG 插件例子(2)—ClearFill
标签:
原文地址:http://www.cnblogs.com/o594cql/p/4480951.html