• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ 编写 CorelDRAW CPG 插件例子(2)—ClearFill

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

这是另一个例子;

贴上主要代码:

  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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
c++性能分析工具发布时间:2022-07-13
下一篇:
Hypertable 简介 (一个 C++ 的Bigtable开源实现)(转载)发布时间:2022-07-13
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap