Jelajahi Sumber

02_WelcomeScreen 03_ClearFill

蘭雅sRGB 9 bulan lalu
induk
melakukan
61927062db

+ 217 - 0
02_WelcomeScreen/WelcomeScreen.cpp

@@ -0,0 +1,217 @@
+#include <windows.h>
+#include "resource.h"
+
+#import "VGCoreAuto.tlb" \
+			rename("GetCommandLine", "VGGetCommandLine") \
+			rename("CopyFile", "VGCore") \
+			rename("FindWindow", "VGFindWindow")
+
+
+static HINSTANCE g_hResource = NULL;
+
+BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
+{
+  if(fdwReason == DLL_PROCESS_ATTACH)
+  {
+    g_hResource = (HINSTANCE)hinstDLL;
+  }
+  return TRUE;
+}
+
+class CWelcomeScreenPlugin : public VGCore::IVGAppPlugin
+{
+private:
+  VGCore::IVGApplication *m_pApp;
+  volatile ULONG m_ulRefCount;
+  long m_lCookie;
+
+  static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
+  void OnAppStart();
+
+public:
+  CWelcomeScreenPlugin();
+
+// IUnknown
+public:
+  STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
+  STDMETHOD_(ULONG, AddRef)(void) { return ++m_ulRefCount; }
+  STDMETHOD_(ULONG, Release)(void)
+  {
+    ULONG ulCount = --m_ulRefCount;
+    if(ulCount == 0)
+    {
+      delete this;
+    }
+    return ulCount;
+  }
+
+// IDispatch
+public:
+  STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { return E_NOTIMPL; }
+  STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) { return E_NOTIMPL; }
+  STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) { return E_NOTIMPL; }
+  STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
+
+// IVGAppPlugin
+public:
+  STDMETHOD(raw_OnLoad)(VGCore::IVGApplication *Application);
+  STDMETHOD(raw_StartSession)();
+  STDMETHOD(raw_StopSession)();
+  STDMETHOD(raw_OnUnload)();
+};
+
+CWelcomeScreenPlugin::CWelcomeScreenPlugin()
+{
+  m_pApp = NULL;
+  m_lCookie = 0;
+  m_ulRefCount = 1;
+}
+
+STDMETHODIMP CWelcomeScreenPlugin::QueryInterface(REFIID riid, void **ppvObject)
+{
+  HRESULT hr = S_OK;
+  m_ulRefCount++;
+  if(riid == IID_IUnknown)
+  {
+    *ppvObject = (IUnknown *)this;
+  }
+  else if(riid == IID_IDispatch)
+  {
+    *ppvObject = (IDispatch *)this;
+  }
+  else if(riid == __uuidof(VGCore::IVGAppPlugin))
+  {
+    *ppvObject = (VGCore::IVGAppPlugin *)this;
+  }
+  else
+  {
+    m_ulRefCount--;
+    hr = E_NOINTERFACE;
+  }
+  return hr;
+}
+
+STDMETHODIMP CWelcomeScreenPlugin::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
+{
+  switch(dispIdMember)
+  {
+    case 0x0012: //DISPID_APP_START
+      OnAppStart();
+      break;
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CWelcomeScreenPlugin::raw_OnLoad(VGCore::IVGApplication *Application)
+{
+  m_pApp = Application;
+  if(m_pApp)
+  {
+    m_pApp->AddRef();
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CWelcomeScreenPlugin::raw_StartSession()
+{
+  try
+  {
+    m_lCookie = m_pApp->AdviseEvents(this);
+  }
+  catch(_com_error &e)
+  {
+    MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CWelcomeScreenPlugin::raw_StopSession()
+{
+  try
+  {
+    m_pApp->UnadviseEvents(m_lCookie);
+  }
+  catch(_com_error &e)
+  {
+    MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CWelcomeScreenPlugin::raw_OnUnload()
+{
+  if(m_pApp)
+  {
+    m_pApp->Release();
+    m_pApp = NULL;
+  }
+  return S_OK;
+}
+
+void CWelcomeScreenPlugin::OnAppStart()
+{
+  try
+  {
+    m_pApp->StartupMode = VGCore::cdrStartupDoNothing;
+	// To avoid 64 bit portability warning, store the long handle value into an INT_PTR
+	// before casting it to HWND:
+
+	INT_PTR nHandle = m_pApp->AppWindow->Handle;
+	HWND hAppWnd = reinterpret_cast<HWND>(nHandle);
+    INT_PTR nRet = DialogBoxParam(g_hResource, MAKEINTRESOURCE(IDD_WELCOME), hAppWnd, DlgProc, (LPARAM)this);
+    switch(nRet)
+    {
+    case IDC_NEWDOC:
+      m_pApp->CreateDocument();
+      break;
+
+    case IDC_LASTDOC:
+      if(m_pApp->RecentFiles->Count > 0)
+      {
+        m_pApp->OpenDocument(m_pApp->RecentFiles->Item[1]->FullName, 0);
+      }
+      else
+      {
+        MessageBox(NULL, "No documents were editied yet.", "Error", MB_ICONSTOP);
+      }
+      break;
+    }
+  }
+  catch(_com_error &e)
+  {
+    MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
+  }
+}
+
+INT_PTR CALLBACK CWelcomeScreenPlugin::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
+{
+  if(uMsg == WM_COMMAND)
+  {
+    switch(LOWORD(wParam))
+    {
+      case IDC_NEWDOC:
+        EndDialog(hDlg, IDC_NEWDOC);
+        break;
+
+      case IDC_LASTDOC:
+        EndDialog(hDlg, IDC_LASTDOC);
+        break;
+
+      case IDOK:
+      case IDCANCEL:
+        EndDialog(hDlg, 0);
+        break;
+    }
+  }
+  else if(uMsg == WM_INITDIALOG)
+  {
+    return 1;
+  }
+  return 0;
+}
+
+extern "C" __declspec(dllexport) DWORD APIENTRY AttachPlugin(VGCore::IVGAppPlugin **ppIPlugin)
+{
+  *ppIPlugin = new CWelcomeScreenPlugin;
+  return 0x100;
+}

+ 24 - 0
02_WelcomeScreen/WelcomeScreen.rc

@@ -0,0 +1,24 @@
+// Generated by ResEdit 1.6.6
+// Copyright (C) 2006-2015
+// http://www.resedit.net
+
+#include <windows.h>
+#include <commctrl.h>
+#include <richedit.h>
+#include "resource.h"
+
+
+
+
+//
+// Dialog resources
+//
+LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
+IDD_WELCOME DIALOGEX 0, 0, 172, 57
+STYLE DS_MODALFRAME | DS_SHELLFONT | WS_CAPTION | WS_POPUP | WS_SYSMENU
+CAPTION "Welcome"
+FONT 8, "MS Shell Dlg", 400, 0, 1
+{
+    PUSHBUTTON      "New Document", IDC_NEWDOC, 7, 7, 77, 42, 0, WS_EX_LEFT
+    PUSHBUTTON      "Last Document", IDC_LASTDOC, 88, 7, 77, 42, 0, WS_EX_LEFT
+}

+ 51 - 0
02_WelcomeScreen/lycpg64.cbp

@@ -0,0 +1,51 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+	<FileVersion major="1" minor="6" />
+	<Project>
+		<Option title="lycpg64" />
+		<Option pch_mode="2" />
+		<Option compiler="microsoft_visual_c_2022" />
+		<Build>
+			<Target title="Debug">
+				<Option output="bin/Debug/lycpg64" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Debug/" />
+				<Option type="3" />
+				<Option compiler="microsoft_visual_c_2022" />
+				<Option createDefFile="1" />
+				<Option createStaticLib="1" />
+				<Compiler>
+					<Add option="/Zi" />
+					<Add option="/D_DEBUG" />
+				</Compiler>
+				<Linker>
+					<Add option="/debug" />
+					<Add option="/DEBUG" />
+				</Linker>
+			</Target>
+			<Target title="Release">
+				<Option output="bin/Release/lycpg64" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Release/" />
+				<Option type="3" />
+				<Option compiler="microsoft_visual_c_2022" />
+				<Option createDefFile="1" />
+				<Option createStaticLib="1" />
+				<Compiler>
+					<Add option="/Ox" />
+					<Add option="/DNDEBUG" />
+					<Add directory="../TypeLibs" />
+				</Compiler>
+			</Target>
+		</Build>
+		<Compiler>
+			<Add option="/W3" />
+			<Add option="/EHsc" />
+		</Compiler>
+		<Unit filename="WelcomeScreen.cpp" />
+		<Unit filename="WelcomeScreen.rc">
+			<Option compilerVar="WINDRES" />
+		</Unit>
+		<Extensions>
+			<lib_finder disable_auto="1" />
+		</Extensions>
+	</Project>
+</CodeBlocks_project_file>

+ 7 - 0
02_WelcomeScreen/resource.h

@@ -0,0 +1,7 @@
+#ifndef IDC_STATIC
+#define IDC_STATIC (-1)
+#endif
+
+#define IDD_WELCOME                             9
+#define IDC_NEWDOC                              1001
+#define IDC_LASTDOC                             1002

+ 214 - 0
03_ClearFill/ClearFill.cpp

@@ -0,0 +1,214 @@
+#include <windows.h>
+#include <tchar.h>
+
+#import "VGCoreAuto.tlb" \
+      rename("GetCommandLine", "VGGetCommandLine") \
+      rename("CopyFile", "VGCore") \
+      rename("FindWindow", "VGFindWindow")
+
+#ifdef _MANAGED
+#pragma managed(push, off)
+#endif
+
+BOOL APIENTRY DllMain( HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved )
+{
+  switch (fdwReason)
+  {
+    case DLL_PROCESS_ATTACH:
+    case DLL_THREAD_ATTACH:
+    case DLL_THREAD_DETACH:
+    case DLL_PROCESS_DETACH:
+      break;
+  }
+  return TRUE;
+}
+
+#ifdef _MANAGED
+#pragma managed(pop)
+#endif
+
+class CVGAppPlugin : public VGCore::IVGAppPlugin
+{
+private:
+  VGCore::IVGApplication *m_pApp;
+  ULONG m_ulRefCount;
+  long m_lCookie;
+  bool m_bEnabled;
+
+  bool CheckSelection();
+  void OnClearFill();
+
+public:
+  CVGAppPlugin();
+
+// IUnknown
+public:
+  STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
+  STDMETHOD_(ULONG, AddRef)(void) { return ++m_ulRefCount; }
+  STDMETHOD_(ULONG, Release)(void)
+  {
+    ULONG ulCount = --m_ulRefCount;
+    if(ulCount == 0)
+    {
+      delete this;
+    }
+    return ulCount;
+  }
+
+// IDispatch
+public:
+  STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { return E_NOTIMPL; }
+  STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) { return E_NOTIMPL; }
+  STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) { return E_NOTIMPL; }
+  STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
+
+// IVGAppPlugin
+public:
+  STDMETHOD(raw_OnLoad)(VGCore::IVGApplication *Application);
+  STDMETHOD(raw_StartSession)();
+  STDMETHOD(raw_StopSession)();
+  STDMETHOD(raw_OnUnload)();
+};
+
+bool CVGAppPlugin::CheckSelection()
+{
+  bool bRet = false;
+  if(m_pApp->Documents->Count > 0)
+  {
+    bRet = (m_pApp->ActiveSelection->Shapes->Count > 0);
+  }
+  return bRet;
+}
+
+void CVGAppPlugin::OnClearFill()
+{
+  if(CheckSelection())
+  {
+    m_pApp->ActiveSelection->Fill->ApplyNoFill();
+  }
+}
+
+CVGAppPlugin::CVGAppPlugin() :
+  m_pApp(NULL),
+  m_lCookie(0),
+  m_ulRefCount(1),
+  m_bEnabled(false)
+{
+}
+
+STDMETHODIMP CVGAppPlugin::QueryInterface(REFIID riid, void **ppvObject)
+{
+  HRESULT hr = S_OK;
+  m_ulRefCount++;
+  if(riid == IID_IUnknown)
+  {
+    *ppvObject = (IUnknown *)this;
+  }
+  else if(riid == IID_IDispatch)
+  {
+    *ppvObject = (IDispatch *)this;
+  }
+  else if(riid == __uuidof(VGCore::IVGAppPlugin))
+  {
+    *ppvObject = (VGCore::IVGAppPlugin *)this;
+  }
+  else
+  {
+    m_ulRefCount--;
+    hr = E_NOINTERFACE;
+  }
+  return hr;
+}
+
+STDMETHODIMP CVGAppPlugin::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
+{
+  switch(dispIdMember)
+  {
+    case 0x0011: //DISPID_APP_SELCHANGE
+      m_bEnabled = CheckSelection();
+      break;
+
+    case 0x0014: // DISPID_APP_ONPLUGINCMD
+      if(pDispParams != NULL && pDispParams->cArgs == 1)
+      {
+        _bstr_t strCmd(pDispParams->rgvarg[0].bstrVal);
+        if(strCmd == _bstr_t("ClearFill"))
+        {
+          OnClearFill();
+        }
+      }
+      break;
+
+    case 0x0015: // DISPID_APP_ONPLUGINCMDSTATE
+      if(pDispParams != NULL && pDispParams->cArgs == 3)
+      {
+        _bstr_t strCmd(pDispParams->rgvarg[2].bstrVal);
+        if(strCmd == _bstr_t("ClearFill"))
+        {
+          *pDispParams->rgvarg[1].pboolVal = m_bEnabled ? VARIANT_TRUE : VARIANT_FALSE;
+        }
+      }
+      break;
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CVGAppPlugin::raw_OnLoad(VGCore::IVGApplication *Application)
+{
+  m_pApp = Application;
+  if(m_pApp)
+  {
+    m_pApp->AddRef();
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CVGAppPlugin::raw_StartSession()
+{
+  try
+  {
+    m_pApp->AddPluginCommand(_bstr_t("ClearFill"), _bstr_t("Clear Fill"), _bstr_t("Clears fill from selected objects"));
+
+    // CorelDRAW X6 使用 VGCore::CommandBarControlPtr ctl
+    // CorelDRAW 2020 使用  VGCore::ICUIControlPtr ctl,能通过编译,不过运行目前有错误
+    VGCore::ICUIControlPtr ctl = m_pApp->CommandBars->Item[_bstr_t("CorelVBA")]->Controls->AddCustomButton(VGCore::cdrCmdCategoryPlugins, _bstr_t("ClearFill"), 0, VARIANT_TRUE);
+//    _bstr_t bstrPath(m_pApp->Path + _bstr_t("Plugins64\\ClearFill.bmp"));
+    ctl->SetIcon2(_bstr_t("guid://d2fdc0d9-09f8-4948-944c-4297395c05b7"));
+    m_lCookie = m_pApp->AdviseEvents(this);
+  }
+  catch(_com_error &e)
+  {
+    MessageBox(NULL, e.Description(), _T("Error"), MB_ICONSTOP);
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CVGAppPlugin::raw_StopSession()
+{
+  try
+  {
+    m_pApp->UnadviseEvents(m_lCookie);
+    m_pApp->RemovePluginCommand(_bstr_t("ClearFill"));
+  }
+  catch(_com_error &e)
+  {
+    MessageBox(NULL, e.Description(), _T("Error"), MB_ICONSTOP);
+  }
+  return S_OK;
+}
+
+STDMETHODIMP CVGAppPlugin::raw_OnUnload()
+{
+  if(m_pApp)
+  {
+    m_pApp->Release();
+    m_pApp = NULL;
+  }
+  return S_OK;
+}
+
+extern "C" __declspec(dllexport) DWORD APIENTRY AttachPlugin(VGCore::IVGAppPlugin **ppIPlugin)
+{
+  *ppIPlugin = new CVGAppPlugin;
+  return 0x100;
+}

+ 47 - 0
03_ClearFill/lycpg64.cbp

@@ -0,0 +1,47 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocks_project_file>
+	<FileVersion major="1" minor="6" />
+	<Project>
+		<Option title="lycpg64" />
+		<Option pch_mode="2" />
+		<Option compiler="microsoft_visual_c_2022" />
+		<Build>
+			<Target title="Debug">
+				<Option output="bin/Debug/lycpg64" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Debug/" />
+				<Option type="3" />
+				<Option compiler="microsoft_visual_c_2022" />
+				<Option createDefFile="1" />
+				<Option createStaticLib="1" />
+				<Compiler>
+					<Add option="/Zi" />
+					<Add option="/D_DEBUG" />
+				</Compiler>
+				<Linker>
+					<Add option="/debug" />
+				</Linker>
+			</Target>
+			<Target title="Release">
+				<Option output="bin/Release/lycpg64" prefix_auto="1" extension_auto="1" />
+				<Option object_output="obj/Release/" />
+				<Option type="3" />
+				<Option compiler="microsoft_visual_c_2022" />
+				<Option createDefFile="1" />
+				<Option createStaticLib="1" />
+				<Compiler>
+					<Add option="/Ox" />
+					<Add option="/DNDEBUG" />
+					<Add directory="../TypeLibs" />
+				</Compiler>
+			</Target>
+		</Build>
+		<Compiler>
+			<Add option="/W3" />
+			<Add option="/EHsc" />
+		</Compiler>
+		<Unit filename="ClearFill.cpp" />
+		<Extensions>
+			<lib_finder disable_auto="1" />
+		</Extensions>
+	</Project>
+</CodeBlocks_project_file>

+ 3 - 0
img/CPG插件目录.txt

@@ -0,0 +1,3 @@
+C:\Program Files\Corel\CorelDRAW Graphics Suite 2020\Draw\Plugins64
+
+lycpg64.cpg

+ 54 - 0
img/MSVC_2022_For_CodeBlocks.conf

@@ -0,0 +1,54 @@
+<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
+<CodeBlocksConfig version="1">
+	<compiler>
+		<user_sets>
+			<microsoft_visual_c_2022>
+				<NAME>
+					<str>
+						<![CDATA[Microsoft Visual C++ 2022]]>
+					</str>
+				</NAME>
+				<PARENT>
+					<str>
+						<![CDATA[msvc10]]>
+					</str>
+				</PARENT>
+				<INCLUDE_DIRS>
+					<str>
+						<![CDATA[C:\MSVC2022\include;]]>
+					</str>
+				</INCLUDE_DIRS>
+				<RES_INCLUDE_DIRS>
+					<str>
+						<![CDATA[C:\MSVC2022\include;]]>
+					</str>
+				</RES_INCLUDE_DIRS>
+				<LIBRARY_DIRS>
+					<str>
+						<![CDATA[C:\MSVC2022\lib;]]>
+					</str>
+				</LIBRARY_DIRS>
+				<LIBRARIES>
+					<str>
+						<![CDATA[Gdi32;user32;Kernel32;]]>
+					</str>
+				</LIBRARIES>
+				<MASTER_PATH>
+					<str>
+						<![CDATA[C:\MSVC2022\]]>
+					</str>
+				</MASTER_PATH>
+				<EXTRA_PATHS>
+					<str>
+						<![CDATA[$(CODEBLOCKS)\tool;$(CODEBLOCKS)\tool\svn;$(CODEBLOCKS)\tool\windbg;$(CODEBLOCKS)\tool\vctool;]]>
+					</str>
+				</EXTRA_PATHS>
+				<DEBUGGER_CONFIG>
+					<str>
+						<![CDATA[gdb_debugger:cdb]]>
+					</str>
+				</DEBUGGER_CONFIG>
+			</microsoft_visual_c_2022>
+		</user_sets>
+	</compiler>
+</CodeBlocksConfig>