| | |
| | | |
| | | private BaseAttacher attacher; |
| | | private ISldWorks swApp; |
| | | private TaskpaneView panel; |
| | | private Form mainForm; |
| | | // Public Properties |
| | | public ISldWorks SwApp |
| | | { |
| | |
| | | Path.Combine(imageFolder, @"MatChooser_128X128.png") |
| | | }; |
| | | // 创建Panel |
| | | TaskpaneView panel = SwApp.CreateTaskpaneView3(bitmaps, "PdmSwPlugin" + PluginConst.Version); |
| | | panel = SwApp.CreateTaskpaneView3(bitmaps, "PdmSwPlugin" + PluginConst.Version); |
| | | |
| | | mainControl = new MainControl((SldWorks)SwApp); |
| | | // 只能用winform,代理wpf |
| | |
| | | AutoSize = true, |
| | | Dock = DockStyle.Fill |
| | | }; |
| | | Form form = new Form |
| | | mainForm = new Form |
| | | { |
| | | Text = "PdmSwPlugin", |
| | | ControlBox = false, |
| | |
| | | KeyPreview = true, |
| | | Dock = DockStyle.Fill |
| | | }; |
| | | form.Controls.Add(host); |
| | | IntPtr ptr = form.Handle; |
| | | mainForm.Controls.Add(host); |
| | | IntPtr ptr = mainForm.Handle; |
| | | // IntPtr ptr = WindowIntPtrUtil.FindWindow(null, "Window1"); |
| | | panel.DisplayWindowFromHandlex64(ptr.ToInt64()); |
| | | mainForm.WindowState = FormWindowState.Maximized; |
| | | } |
| | | |
| | | private void LoadPlugins() |
| | |
| | | /// <returns></returns> |
| | | public bool DisconnectFromSW() |
| | | { |
| | | RemoveCommandMgr(); |
| | | RemovePMP(); |
| | | mainControl.StopTcpServer(); |
| | | attacher.DetachEventHandlers(); |
| | | attacher = null; |
| | | try |
| | | { |
| | | RemoveCommandMgr(); |
| | | RemovePMP(); |
| | | mainControl.StopTcpServer(); |
| | | mainControl.DeActiveHandler(); |
| | | attacher.DetachEventHandlers(); |
| | | attacher = null; |
| | | |
| | | System.Runtime.InteropServices.Marshal.ReleaseComObject(iCmdMgr); |
| | | iCmdMgr = null; |
| | | System.Runtime.InteropServices.Marshal.ReleaseComObject(SwApp); |
| | | swApp = null; |
| | | //The addin _must_ call GC.Collect() here in order to retrieve all managed code pointers |
| | | GC.Collect(); |
| | | GC.WaitForPendingFinalizers(); |
| | | mainForm.Close(); |
| | | mainForm = null; |
| | | mainControl = null; |
| | | panel.DeleteView(); |
| | | panel = null; |
| | | |
| | | GC.Collect(); |
| | | GC.WaitForPendingFinalizers(); |
| | | Marshal.ReleaseComObject(iCmdMgr); |
| | | iCmdMgr = null; |
| | | Marshal.ReleaseComObject(SwApp); |
| | | swApp = null; |
| | | //The addin _must_ call GC.Collect() here in order to retrieve all managed code pointers |
| | | GC.Collect(); |
| | | GC.WaitForPendingFinalizers(); |
| | | |
| | | //GC.Collect(); |
| | | //GC.WaitForPendingFinalizers(); |
| | | } |
| | | catch (Exception ex) |
| | | { |
| | | Logger.Error("DisconnectFromSW Failed!", ex); |
| | | } |
| | | return true; |
| | | } |
| | | #endregion |