chr
7 天以前 43a0207d207390abdeeb3ab9155eebf03edd7b1a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
using log4net;
using PdmSwPlugin.Common.Setting;
using PdmSwPlugin.Common.Util;
using PdmSwPlugin.Main;
using PdmSwPlugin.Main.EventHandler;
using SolidWorks.Interop.sldworks;
using System.Runtime.InteropServices;
using System.Windows;
 
namespace WpfUI
{
    /// <summary>
    /// Window1.xaml 的交互逻辑
    /// </summary>
    public partial class Window1 : Window
    {
        private SldWorks SwApp;
        private PluginSetting GlobalConfig;
        private BaseAttacher attacher;
        private MainControl mainControl;
        public Window1()
        {
            InitializeComponent();
            GlobalConfig = PluginSetting.Instance;
        }
 
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            if (SwApp != null)
            {
                return;
            }
            else
            {
                try
                {
                    // SwApp = (SldWorks)Marshal.GetActiveObject("SldWorks.Application.28");
                    SwApp = (SldWorks)System.Runtime.InteropServices.Marshal.GetActiveObject("SldWorks.Application");
                    mainControl = new MainControl(SwApp);
                    mainControl.Loaded += MainControl_Loaded;
                    stack.Children.Add(mainControl);
 
                }
                catch (COMException ex)
                {
                    MessageBox.Show(ex.Message);
                }
            }
        }
 
        private void MainControl_Loaded(object sender, RoutedEventArgs e)
        {
            attacher = new AsyncAttacher(SwApp, mainControl);
            attacher.AttachEventHandlers();
        }
 
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            Button_Click(null, null);
        }
    }
}