void init()
 {
     if (!initialised)
     {
         // only initialise once
         app = new Visio.Application();
         // app.BeforeDocumentClose += app_BeforeDocumentClose;
         app.EventList.AddAdvise(DocCloseEventCode, this, null, null);
         initialised = true;
         Application.DoEvents();
     }
 }
Exemple #2
0
        /// <summary>
        /// Visioの既存のファイルを開く。存在しない場合はエラー
        /// </summary>
        /// <param name="_App"></param>
        /// <param name="_Docs"></param>
        /// <param name="_FilePath"></param>
        /// <returns></returns>
        public virtual Visio.Document Open(ref Visio.Application _App, ref Visio.Documents _Docs, string _FilePath)
        {
            Visio.Document _Doc = null;
            try
            {
                TheOpenAppCapture <Visio.Document> _Capture = new TheOpenAppCapture <Visio.Document>(_FilePath);
                if (_Capture.IsFileOpened())
                {
                    _Doc = _Capture.GetRunningApp();
                    SecureApp(ref _App, ref _Docs, _Doc.Application);

                    return(_Doc);
                }
            }
            catch (Exception e)
            {
                if (_Doc != null)
                {
                    while (Marshal.ReleaseComObject(_Doc) > 0)
                    {
                        ;
                    }
                }
                if (e.Message.IndexOf(_FilePath) < 0)
                {
                    throw e;
                }
            }

            try
            {
                SecureApp(ref _App, ref _Docs);
                return(_OpenSaveArgs == 0 ? _Docs.Open(_FilePath) : _Docs.OpenEx(_FilePath, _OpenSaveArgs));
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #3
0
        /// <summary>
        /// Visioのファイルを新規作成して開く。既にファイルがある場合も新規作成される。
        /// </summary>
        /// <param name="_App"></param>
        /// <param name="_Docs"></param>
        /// <param name="_FilePath"></param>
        /// <returns></returns>
        public virtual Visio.Document Add(ref Visio.Application _App, ref Visio.Documents _Docs, string _FilePath)
        {
            Visio.Document _Doc = null;
            try
            {
                SecureApp(ref _App, ref _Docs);

                _Doc = _OpenSaveArgs == 0 ? _Docs.Add("") : _Docs.AddEx("", Visio.VisMeasurementSystem.visMSMetric, _OpenSaveArgs);
                _Doc.SaveAs(_FilePath);

                return(_Doc);
            }
            catch (Exception e)
            {
                if (_Doc != null)
                {
                    while (Marshal.ReleaseComObject(_Doc) > 0)
                    {
                        ;
                    }
                }
                throw e;
            }
        }
Exemple #4
0
 private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
 {
     e_application.DocumentOpened -= new Visio.EApplication_DocumentOpenedEventHandler(e_Application_DocumentOpened);
     e_application = null;
 }
Exemple #5
0
 private void ThisAddIn_Startup(object sender, System.EventArgs e)
 {
     e_application = this.Application;
     e_application.DocumentOpened += new Visio.EApplication_DocumentOpenedEventHandler(e_Application_DocumentOpened);
 }