1
0

ToolsBox.cpp 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. #include <stdio.h>
  2. #include <windows.h>
  3. #include "resource.h"
  4. #include "cdrapp.h"
  5. static HINSTANCE g_hResource = NULL;
  6. BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  7. {
  8. if (fdwReason == DLL_PROCESS_ATTACH) {
  9. g_hResource = (HINSTANCE)hinstDLL;
  10. }
  11. return TRUE;
  12. }
  13. class ToolsBoxPlugin : public VGCore::IVGAppPlugin
  14. {
  15. private:
  16. volatile ULONG m_ulRefCount;
  17. long m_lCookie;
  18. static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  19. void OpenToolsBox();
  20. public:
  21. ToolsBoxPlugin();
  22. VGCore::IVGApplication* m_pApp;
  23. // IUnknown
  24. public:
  25. STDMETHOD(QueryInterface)(REFIID riid, void** ppvObject);
  26. STDMETHOD_(ULONG, AddRef)(void) { return ++m_ulRefCount; }
  27. STDMETHOD_(ULONG, Release)(void)
  28. {
  29. ULONG ulCount = --m_ulRefCount;
  30. if (ulCount == 0) {
  31. delete this;
  32. }
  33. return ulCount;
  34. }
  35. // IDispatch
  36. public:
  37. STDMETHOD(GetTypeInfoCount)(UINT* pctinfo) { return E_NOTIMPL; }
  38. STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo** ppTInfo) { return E_NOTIMPL; }
  39. STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR* rgszNames, UINT cNames, LCID lcid, DISPID* rgDispId) { return E_NOTIMPL; }
  40. STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr);
  41. // IVGAppPlugin
  42. public:
  43. STDMETHOD(raw_OnLoad)(VGCore::IVGApplication* Application);
  44. STDMETHOD(raw_StartSession)();
  45. STDMETHOD(raw_StopSession)();
  46. STDMETHOD(raw_OnUnload)();
  47. };
  48. ToolsBoxPlugin::ToolsBoxPlugin()
  49. {
  50. m_pApp = NULL;
  51. m_lCookie = 0;
  52. m_ulRefCount = 1;
  53. }
  54. STDMETHODIMP ToolsBoxPlugin::QueryInterface(REFIID riid, void** ppvObject)
  55. {
  56. HRESULT hr = S_OK;
  57. m_ulRefCount++;
  58. if (riid == IID_IUnknown) {
  59. *ppvObject = (IUnknown*)this;
  60. } else if (riid == IID_IDispatch) {
  61. *ppvObject = (IDispatch*)this;
  62. } else if (riid == __uuidof(VGCore::IVGAppPlugin)) {
  63. *ppvObject = (VGCore::IVGAppPlugin*)this;
  64. } else {
  65. m_ulRefCount--;
  66. hr = E_NOINTERFACE;
  67. }
  68. return hr;
  69. }
  70. STDMETHODIMP ToolsBoxPlugin::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS* pDispParams, VARIANT* pVarResult, EXCEPINFO* pExcepInfo, UINT* puArgErr)
  71. {
  72. switch (dispIdMember) {
  73. case 0x0014: // DISPID_APP_ONPLUGINCMD
  74. if (pDispParams != NULL && pDispParams->cArgs == 1) {
  75. _bstr_t strCmd(pDispParams->rgvarg[0].bstrVal);
  76. if (strCmd == _bstr_t("OpenToolsBox")) {
  77. // MessageBox(NULL, _bstr_t("OpenToolsBox"), _bstr_t("OpenToolsBox"), MB_ICONSTOP);
  78. OpenToolsBox();
  79. }
  80. }
  81. break;
  82. case 0x0015: // DISPID_APP_ONPLUGINCMDSTATE
  83. if (pDispParams != NULL && pDispParams->cArgs == 3) {
  84. _bstr_t strCmd(pDispParams->rgvarg[2].bstrVal);
  85. if (strCmd == _bstr_t("OpenToolsBox")) {
  86. *pDispParams->rgvarg[1].pboolVal = VARIANT_TRUE;
  87. }
  88. }
  89. break;
  90. }
  91. return S_OK;
  92. }
  93. STDMETHODIMP ToolsBoxPlugin::raw_OnLoad(VGCore::IVGApplication* Application)
  94. {
  95. m_pApp = Application;
  96. if (m_pApp) {
  97. m_pApp->AddRef();
  98. }
  99. return S_OK;
  100. }
  101. STDMETHODIMP ToolsBoxPlugin::raw_StartSession()
  102. {
  103. try {
  104. m_pApp->AddPluginCommand(_bstr_t("OpenToolsBox"), _bstr_t("Tools Box"), _bstr_t("打开工具窗口"));
  105. VGCore::ICUIControlPtr ctl = m_pApp->CommandBars->Item[_bstr_t("Standard")]->Controls->AddCustomButton(VGCore::cdrCmdCategoryPlugins, _bstr_t("OpenToolsBox"), 10, VARIANT_FALSE);
  106. ctl->SetIcon2(_bstr_t("guid://d2fdc0d9-09f8-4948-944c-4297395c05b7"));
  107. m_lCookie = m_pApp->AdviseEvents(this);
  108. } catch (_com_error &e) {
  109. MessageBox(NULL, e.Description(), _bstr_t("Error"), MB_ICONSTOP);
  110. }
  111. return S_OK;
  112. }
  113. STDMETHODIMP ToolsBoxPlugin::raw_StopSession()
  114. {
  115. try {
  116. m_pApp->UnadviseEvents(m_lCookie);
  117. m_pApp->RemovePluginCommand(_bstr_t("OpenToolsBox"));
  118. } catch (_com_error &e) {
  119. MessageBox(NULL, e.Description(), _bstr_t("Error"), MB_ICONSTOP);
  120. }
  121. return S_OK;
  122. }
  123. STDMETHODIMP ToolsBoxPlugin::raw_OnUnload()
  124. {
  125. if (m_pApp) {
  126. m_pApp->Release();
  127. m_pApp = NULL;
  128. }
  129. return S_OK;
  130. }
  131. void ToolsBoxPlugin::OpenToolsBox()
  132. {
  133. m_pApp->StartupMode = VGCore::cdrStartupDoNothing;
  134. INT_PTR nHandle = m_pApp->AppWindow->Handle;
  135. HWND hAppWnd = reinterpret_cast<HWND>(nHandle);
  136. // 创建非模态对话框
  137. HWND hDlgWnd = CreateDialogParam(g_hResource, MAKEINTRESOURCE(IDD_TOOLS_BOX), hAppWnd, DlgProc, (LPARAM)m_pApp);
  138. // 在创建对话框之前存储 m_pApp 指针
  139. SetWindowLongPtr(hDlgWnd, DWLP_USER, (LONG_PTR)m_pApp);
  140. // 获取屏幕的宽度和高度
  141. RECT rect;
  142. GetWindowRect(GetDesktopWindow(), &rect);
  143. int screenWidth = rect.right - rect.left;
  144. int screenHeight = rect.bottom - rect.top;
  145. // 计算对话框窗口的宽度和高度
  146. RECT dlgRect;
  147. GetWindowRect(hDlgWnd, &dlgRect);
  148. int dlgWidth = dlgRect.right - dlgRect.left;
  149. int dlgHeight = dlgRect.bottom - dlgRect.top;
  150. // 计算对话框窗口的左上角坐标,使其居中显示
  151. int x = (screenWidth - dlgWidth) / 2;
  152. int y = (screenHeight - dlgHeight) / 2;
  153. // 设置对话框窗口的位置
  154. SetWindowPos(hDlgWnd, NULL, x, y, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  155. // 设置对话框窗口的父窗口 // #define GWL_HWNDPARENT (-8)
  156. SetWindowLong(hDlgWnd, -8, (LONG)hAppWnd);
  157. // 显示对话框窗口
  158. ShowWindow(hDlgWnd, SW_SHOW);
  159. }
  160. INT_PTR CALLBACK ToolsBoxPlugin::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  161. {
  162. // 从附加数据中获取 m_pApp 指针
  163. VGCore::IVGApplication* cdr = reinterpret_cast<VGCore::IVGApplication*>(GetWindowLongPtr(hDlg, DWLP_USER));
  164. if (uMsg == WM_COMMAND) {
  165. try {
  166. switch (LOWORD(wParam)) {
  167. case IDC_RED :
  168. AdobeAI_Copy_ImportCdr(cdr);
  169. // fill_red(cdr);
  170. MessageBox(NULL, "AdobeAI_Copy_ImportCdr", "CPG代码测试", MB_ICONSTOP);
  171. break;
  172. case IDC_CQL_OUTLINE:
  173. cql_OutlineColor(cdr);
  174. Active_CorelWindows(hDlg);
  175. break;
  176. case IDC_CQL_FILL:
  177. cql_FillColor(cdr);
  178. Active_CorelWindows(hDlg);
  179. break;
  180. case IDC_CQL_SIZE:
  181. cql_SameSize(cdr);
  182. Active_CorelWindows(hDlg);
  183. break;
  184. case IDC_CLEAR_FILL:
  185. Clear_Fill(cdr);
  186. break;
  187. case IDC_SR_FLIP:
  188. Shapes_Filp(cdr);
  189. break;
  190. case IDC_CDR2AI:
  191. CdrCopy_to_AdobeAI(cdr);
  192. break;
  193. case IDC_AI2CDR:
  194. AdobeAI_Copy_ImportCdr(cdr);
  195. break;
  196. case IDOK:
  197. case IDCANCEL:
  198. EndDialog(hDlg, 0);
  199. break;
  200. }
  201. } catch (_com_error &e) {
  202. MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
  203. }
  204. } else if (uMsg == WM_INITDIALOG) {
  205. return 1;
  206. }
  207. return 0;
  208. }
  209. extern "C" __declspec(dllexport) DWORD APIENTRY AttachPlugin(VGCore::IVGAppPlugin** ppIPlugin)
  210. {
  211. *ppIPlugin = new ToolsBoxPlugin;
  212. return 0x100;
  213. }