1
0

WelcomeScreen.cpp 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. #include <windows.h>
  2. #include "resource.h"
  3. #import "VGCoreAuto.tlb" \
  4. rename("GetCommandLine", "VGGetCommandLine") \
  5. rename("CopyFile", "VGCore") \
  6. rename("FindWindow", "VGFindWindow")
  7. static HINSTANCE g_hResource = NULL;
  8. BOOL APIENTRY DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
  9. {
  10. if(fdwReason == DLL_PROCESS_ATTACH)
  11. {
  12. g_hResource = (HINSTANCE)hinstDLL;
  13. }
  14. return TRUE;
  15. }
  16. class CWelcomeScreenPlugin : public VGCore::IVGAppPlugin
  17. {
  18. private:
  19. VGCore::IVGApplication *m_pApp;
  20. volatile ULONG m_ulRefCount;
  21. long m_lCookie;
  22. static INT_PTR CALLBACK DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  23. void OnAppStart();
  24. public:
  25. CWelcomeScreenPlugin();
  26. // IUnknown
  27. public:
  28. STDMETHOD(QueryInterface)(REFIID riid, void **ppvObject);
  29. STDMETHOD_(ULONG, AddRef)(void) { return ++m_ulRefCount; }
  30. STDMETHOD_(ULONG, Release)(void)
  31. {
  32. ULONG ulCount = --m_ulRefCount;
  33. if(ulCount == 0)
  34. {
  35. delete this;
  36. }
  37. return ulCount;
  38. }
  39. // IDispatch
  40. public:
  41. STDMETHOD(GetTypeInfoCount)(UINT *pctinfo) { return E_NOTIMPL; }
  42. STDMETHOD(GetTypeInfo)(UINT iTInfo, LCID lcid, ITypeInfo **ppTInfo) { return E_NOTIMPL; }
  43. STDMETHOD(GetIDsOfNames)(REFIID riid, LPOLESTR *rgszNames, UINT cNames, LCID lcid, DISPID *rgDispId) { return E_NOTIMPL; }
  44. STDMETHOD(Invoke)(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr);
  45. // IVGAppPlugin
  46. public:
  47. STDMETHOD(raw_OnLoad)(VGCore::IVGApplication *Application);
  48. STDMETHOD(raw_StartSession)();
  49. STDMETHOD(raw_StopSession)();
  50. STDMETHOD(raw_OnUnload)();
  51. };
  52. CWelcomeScreenPlugin::CWelcomeScreenPlugin()
  53. {
  54. m_pApp = NULL;
  55. m_lCookie = 0;
  56. m_ulRefCount = 1;
  57. }
  58. STDMETHODIMP CWelcomeScreenPlugin::QueryInterface(REFIID riid, void **ppvObject)
  59. {
  60. HRESULT hr = S_OK;
  61. m_ulRefCount++;
  62. if(riid == IID_IUnknown)
  63. {
  64. *ppvObject = (IUnknown *)this;
  65. }
  66. else if(riid == IID_IDispatch)
  67. {
  68. *ppvObject = (IDispatch *)this;
  69. }
  70. else if(riid == __uuidof(VGCore::IVGAppPlugin))
  71. {
  72. *ppvObject = (VGCore::IVGAppPlugin *)this;
  73. }
  74. else
  75. {
  76. m_ulRefCount--;
  77. hr = E_NOINTERFACE;
  78. }
  79. return hr;
  80. }
  81. STDMETHODIMP CWelcomeScreenPlugin::Invoke(DISPID dispIdMember, REFIID riid, LCID lcid, WORD wFlags, DISPPARAMS *pDispParams, VARIANT *pVarResult, EXCEPINFO *pExcepInfo, UINT *puArgErr)
  82. {
  83. switch(dispIdMember)
  84. {
  85. case 0x0012: //DISPID_APP_START
  86. OnAppStart();
  87. break;
  88. }
  89. return S_OK;
  90. }
  91. STDMETHODIMP CWelcomeScreenPlugin::raw_OnLoad(VGCore::IVGApplication *Application)
  92. {
  93. m_pApp = Application;
  94. if(m_pApp)
  95. {
  96. m_pApp->AddRef();
  97. }
  98. return S_OK;
  99. }
  100. STDMETHODIMP CWelcomeScreenPlugin::raw_StartSession()
  101. {
  102. try
  103. {
  104. m_lCookie = m_pApp->AdviseEvents(this);
  105. }
  106. catch(_com_error &e)
  107. {
  108. MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
  109. }
  110. return S_OK;
  111. }
  112. STDMETHODIMP CWelcomeScreenPlugin::raw_StopSession()
  113. {
  114. try
  115. {
  116. m_pApp->UnadviseEvents(m_lCookie);
  117. }
  118. catch(_com_error &e)
  119. {
  120. MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
  121. }
  122. return S_OK;
  123. }
  124. STDMETHODIMP CWelcomeScreenPlugin::raw_OnUnload()
  125. {
  126. if(m_pApp)
  127. {
  128. m_pApp->Release();
  129. m_pApp = NULL;
  130. }
  131. return S_OK;
  132. }
  133. void CWelcomeScreenPlugin::OnAppStart()
  134. {
  135. try
  136. {
  137. m_pApp->StartupMode = VGCore::cdrStartupDoNothing;
  138. // To avoid 64 bit portability warning, store the long handle value into an INT_PTR
  139. // before casting it to HWND:
  140. INT_PTR nHandle = m_pApp->AppWindow->Handle;
  141. HWND hAppWnd = reinterpret_cast<HWND>(nHandle);
  142. INT_PTR nRet = DialogBoxParam(g_hResource, MAKEINTRESOURCE(IDD_WELCOME), hAppWnd, DlgProc, (LPARAM)this);
  143. switch(nRet)
  144. {
  145. case IDC_NEWDOC:
  146. m_pApp->CreateDocument();
  147. break;
  148. case IDC_LASTDOC:
  149. if(m_pApp->RecentFiles->Count > 0)
  150. {
  151. m_pApp->OpenDocument(m_pApp->RecentFiles->Item[1]->FullName, 0);
  152. }
  153. else
  154. {
  155. MessageBox(NULL, "No documents were editied yet.", "Error", MB_ICONSTOP);
  156. }
  157. break;
  158. }
  159. }
  160. catch(_com_error &e)
  161. {
  162. MessageBox(NULL, e.Description(), "Error", MB_ICONSTOP);
  163. }
  164. }
  165. INT_PTR CALLBACK CWelcomeScreenPlugin::DlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  166. {
  167. if(uMsg == WM_COMMAND)
  168. {
  169. switch(LOWORD(wParam))
  170. {
  171. case IDC_NEWDOC:
  172. EndDialog(hDlg, IDC_NEWDOC);
  173. break;
  174. case IDC_LASTDOC:
  175. EndDialog(hDlg, IDC_LASTDOC);
  176. break;
  177. case IDOK:
  178. case IDCANCEL:
  179. EndDialog(hDlg, 0);
  180. break;
  181. }
  182. }
  183. else if(uMsg == WM_INITDIALOG)
  184. {
  185. return 1;
  186. }
  187. return 0;
  188. }
  189. extern "C" __declspec(dllexport) DWORD APIENTRY AttachPlugin(VGCore::IVGAppPlugin **ppIPlugin)
  190. {
  191. *ppIPlugin = new CWelcomeScreenPlugin;
  192. return 0x100;
  193. }