| View previous topic :: View next topic |
| Author |
Message |
LarsB OOo Advocate


Joined: 31 Aug 2005 Posts: 445 Location: Hamburg, Germany
|
Posted: Mon Nov 28, 2005 1:12 pm Post subject: Hiding the main menu using OO 2.o and C# resp. net |
|
|
Hi,
after there are so many postings about hiding
menus and toolbars using OO Basic here is
some code that hide the main menu using
C# resp. any other .net language. The code
based on the OO 2.0 api!
| Code: |
using System;
using System.Reflection;
namespace TestApp
{
/// <summary>
/// Start a new OpenOffice instance, load a blank writer, and hide the main menu.
/// </summary>
class Class1
{
[STAThread]
static void Main()
{
//Get the service manager
object _serviceManager = System.Activator.CreateInstance(
Type.GetTypeFromProgID("com.sun.star.ServiceManager", true));
//Get the desktop
object _starDesktop = ComObject.Invoke(_serviceManager,
"createinstance",
BindingFlags.InvokeMethod,
"com.sun.star.frame.Desktop");
//Params to create a new writer instance
Object[] args = new Object[4];
args[0] = "private:factory/swriter";
args[1] = "_blank";
args[2] = 0;
args[3] = new Object[] { };
//Create the document
object _xDocument = ComObject.Invoke(_starDesktop,
"loadComponentFromUrl",
BindingFlags.InvokeMethod,
args
);
// Get the current frame
object _oframe = ComObject.Invoke(_starDesktop,
"getCurrentFrame", BindingFlags.InvokeMethod, new object[] {});
//Get the LayoutManager
object _olayout = ComObject.Invoke(_oframe,
"LayoutManager", BindingFlags.GetProperty, new object[] {});
//Hide the main menu
ComObject.Invoke(_olayout, "hideElement", BindingFlags.InvokeMethod,
new object[] { "private:resource/menubar/menubar" });
Console.WriteLine("Stop");
Console.ReadLine();
}
}
public class ComObject
{
public ComObject()
{
}
/// <summary>
/// Create a new Com object.
/// </summary>
/// <param name="obj">The object to call invoke on.</param>
/// <param name="method">The methodname to call</param>
/// <param name="binding">One of the BiningFlags Enumertion</param>
/// <param name="par">The params for the invoke method call</param>
/// <returns></returns>
public static object Invoke(object obj,string method, BindingFlags binding,params object[] par)
{
return obj.GetType().InvokeMember(method,binding,null,obj,par);
}
}
}
|
Cheers
Lars B _________________ AODC - A free OpenDocument Converter
AODL - An independent OpenDocument Library C#
EmbeddedOpenOffice .net UserControl C#
EmbeddedOpenOffice Visual Studio .net Add In
http://www.OpenDocument4all.com/ |
|
| Back to top |
|
 |
James Miles General User

Joined: 28 Nov 2005 Posts: 22 Location: Perth - Australia
|
Posted: Tue Nov 29, 2005 12:51 am Post subject: LayoutManager missing |
|
|
Hi Lars,
I'm trying to do the same thing, but i have not been using reflection.
| Code: | // Get the current frame.
XFrame currentFrame = OpenOfficeConnectionManager.Desktop.getCurrentFrame(); |
This is where i run into problems. The XFrame doesn't have a LayoutManager so i tried to use reflection.
| Code: | // Get the layout manager from the current frame.
XLayoutManager layoutManager = currentFrame.GetType().InvokeMember("LayoutManager", BindingFlags.GetProperty, null, currentFrame, new object[] {}) as XLayoutManager; |
When it tries to access this property i get the following exception.
"An unhandled exception of type 'System.MissingMethodException' occurred in mscorlib.dll
Additional information: Attempted to access a missing member."
Why does your XFrame have a layout manager... and mine doesn't. Is it because you created your frame object differently?
Cheers,
James Miles. |
|
| Back to top |
|
 |
LarsB OOo Advocate


Joined: 31 Aug 2005 Posts: 445 Location: Hamburg, Germany
|
Posted: Tue Nov 29, 2005 2:55 am Post subject: Not supported by the cli assmblies |
|
|
Hi,
the XLayoutManager interface is part of the cli assemblies,
but the developer forgot to add resp. implement the LayoutManager
property on the Frame object
Maybe anyone has a idea if there is another way to get a
LayoutManager instance.
I already tried to create the service with the servicemanager
and then use addFrame which result in no errors, but the
following method calls doesn't do anything.
Cheers
Lars B _________________ AODC - A free OpenDocument Converter
AODL - An independent OpenDocument Library C#
EmbeddedOpenOffice .net UserControl C#
EmbeddedOpenOffice Visual Studio .net Add In
http://www.OpenDocument4all.com/ |
|
| Back to top |
|
 |
James Miles General User

Joined: 28 Nov 2005 Posts: 22 Location: Perth - Australia
|
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|