Builtinmenus

S

Saritha

Hi,
am trying get a UIObject object that represents Microsoft Office Visio
built-in menus.But am not able to get Builtinmenu.(C#)
Visio.Application is not showing Builtinmenus.
Can anybody plz tell how to get it?
Thanks
 
C

Chris Roth [ Visio MVP ]

Visio has built-in menus, custom menus, and a document has custom menus as
well. The custom menus may or may not be in use. I use the subroutine below
to get the UI for a document.

The theory is that you should modify the "highest level of customization" so
that you don't stomp on other solutions' customization (if there is any)

See if this code makes any sense?
Private Function _getUI( ByVal visDoc As Visio.Document ) As Visio.UIObject

' Note: we need to get a COPY of the custom UIs
Dim ui As Visio.UIObject

If visDoc.CustomMenus Is Nothing Then
Dim app As Visio.Application = visDoc.Application
If app.CustomMenus Is Nothing Then
ui = app.BuiltInMenus ' This is Visio's built-in
menus.
Else
ui = app.CustomMenus.Clone ' This is a fine point, but it's
important!
End If
Else
ui = visDoc.CustomMenus ' This is the document's custom menu
set.
End If

Return ui

End Function


--

Hope this helps,

Chris Roth
Visio MVP
 
R

R

But How to show this VisioBuiltin menu in windows Form using C# ( using
Visio ActiveX Control)
Thanks
 
C

Chris Roth [ Visio MVP ]

Ah, you're using the Vis control!

Make your own menus on the form. It's easier than trying to show the Visio
menus (as far as I know) I've never used the built-in Visio menus when using
the control (other than the right-click menu)

More info in this article, with an excerpt below:

http://msdn.microsoft.com/library/d.../odc_vsProgrammingWithVisioActiveXControl.asp

--

Hope this helps,

Chris Roth
Visio MVP

--------------------------------------------------------
Integrating Menus and Toolbars
The best practice when building an application using the Visio drawing
control is to implement a custom UI. If you want to display Visio menus and
toolbars in your container application, set the drawing control's
NegotatiateToolbars and NegotiateMenus properties. The following C# code
enables both menu and toolbar merging:

drawingControl.NegotiateMenus = True;
drawingControl.NegotiateToolbars = True;
The best practice is to set both of these properties to the same value. The
control will not support independent negotiation of toolbars and menus.

Menu and Toolbar Integration for Non-OLE Menu Merging Hosts
If your container does not support OLE menu merging (for example, a Windows
Form), you can use the IOleCommandTarget interface to run Visio commands.
You can implement your own menu item or toolbar button as demonstrated by
the following C# example:

using System.Runtime.InteropServices;
using System;

namespace OleCommandTarget
{
[StructLayout(LayoutKind.Sequential)]
public struct OLECMDTEXT
{
public UInt32 cmdtextf;
public UInt32 cwActual;
public UInt32 cwBuf;
public char rgwz;
}

[StructLayout(LayoutKind.Sequential)]
public struct OLECMD
{
public UInt32 cmdID;
public UInt64 cmdf;
}

[ComImport(), Guid("B722BCCB-4E68-101B-A2BC-00AA00404770"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface IOleCommandTarget
{
[PreserveSig()]
int QueryStatus( [In, MarshalAs(UnmanagedType.Struct)] ref Guid
pguidCmdGroup, [MarshalAs(UnmanagedType.U4)] int cCmds,
[In, Out] IntPtr prgCmds, [In, Out] IntPtr pCmdText);

[PreserveSig()]
int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdExecOpt,
object[] pvaIn, [In, Out, MarshalAs(UnmanagedType.LPArray)]
object[] pvaOut);
}
}
After you have created your menu item, use your IOleCommandTarget interface
to apply the appropriate Visio user interface command for that target. The
following example enables the Connector tool when a menu item is clicked:

using OleCommandTarget;

private void menuItem_Click(object sender, System.EventArgs eventData)
{
SendCommand();
}

private void SendCommand()
{
const UInt32 VISCMD_DRCONNECTORTOOL =
(UInt32)Visio.VisUICmds.visCmdDRConnectorTool;
IOleCommandTarget commandTarget =
(IOleCommandTarget)axDrawingControl1.GetOcx();

try
{
Guid CLSID_Application = new Guid("{0x00021A20, 0x0000, 0x0000,
{0xC0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46}}");
commandTarget.Exec(ref CLSID_Application, VISCMD_DRCONNECTORTOOL,
0, null, null);
}
catch(System.Runtime.InteropServices.COMException ex)
{
MessageBox.Show(ex.ToString());
}
}
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top