using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Collections.ObjectModel; using System.Windows.Forms; using Microsoft.Win32; using OOLib; using System.Diagnostics; using System.Runtime.InteropServices; using unoidl.com.sun.star.uno; using unoidl.com.sun.star.lang; using unoidl.com.sun.star.frame; namespace Sample { public partial class Form1 : Form { private const int SW_SHOWNORMAL = 1; [DllImport("user32.dll")] public static extern bool ShowWindowAsync(IntPtr hWnd, int cmdShow); [DllImport("user32.dll")] static extern int SetParent(int hWndChild, int hWndNewParent); public ObservableCollection<oolib.officedocument> Docs { get; private set; } private OOLib.ServiceManager _ServiceManager = null; public OOLib.Desktop Desktop { get; private set; } public Form1() { Docs = new ObservableCollection<oolib.officedocument>(); InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { } private void Init() { if(_ServiceManager == null) { _ServiceManager = new OOLib.ServiceManager(); Desktop = _ServiceManager.CreateDesktop(); } if(Desktop != null) { var doc = Desktop.CreateTextDocument(hidden = true); Docs.Add(doc); } } private static void FindOpenOffice() { try { //Process currentProcess = Process.GetCurrentProcess(); //in this line getting MainWindowHandle. Process[] ps = Process.GetProcessesByName("soffice"); if(ps != null) { if(ps.Length > 0) foreach(Process p in ps) { // get mainwindow handle . IntPtr pFoundWindow = p.MainWindowHandle; // Use Handle to view in normal window. if(!pFoundWindow.Equals(IntPtr.Zero)) { ShowWindowAsync(pFoundWindow, SW_SHOWNORMAL); } } } else { MessageBox.Show("OpenOffice not found. Is OpenOffice installed?"); } } catch(System.Exception Exp) { MessageBox.Show(Exp.Message); } } public bool hidden { get; set; } private void btnOpen_Click(object sender, EventArgs e) { Init(); FindOpenOffice(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)