using OfficeAppHelp.Help;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OfficeAppHelp
{
    /// <summary>
    /// office应用
    /// </summary>
    public class OfficeApp
    {
        /// <summary>
        /// WPS 2019+窗体模式 是否为整合模式
        /// </summary>
        private bool? IsWpsFormMergeModel
        {
            get
            {
                return null;
            }
        }

        /// <summary>
        /// 得到进程中的word应用
        /// </summary>
        /// <param name="appType">0没有找到 1 office 2 wps</param>
        /// <returns>word应用</returns>
        public static object GetProcessesWordApp(out OfficeType officeType)
        {
            officeType = OfficeType.Null;

            if (Process.GetProcessesByName("wps").Count() > 0)
            {
                //WPS Office V9
                if (Type.GetTypeFromProgID("KWPS.Application") != null)
                {
                    officeType = OfficeType.WPS;
                    return DllImportHelp.GetActiveObject("KWPS.Application");
                }
                //WPS Office V8
                else if (Type.GetTypeFromProgID("WPS.Application") != null)
                {
                    officeType = OfficeType.WPS;
                    return DllImportHelp.GetActiveObject("WPS.Application");
                }
                else
                    return null;
            }
            //MS Office
            else if (Process.GetProcessesByName("WINWORD").Count() > 0)
            {
                officeType = OfficeType.Microsoft;
                return DllImportHelp.GetActiveObject("Word.Application");
            }
            else
            {
                return null;
            }
        }
    }
}
