How to complete other toolbar Icon function in Drawing control by code.

C

Chen Jian

I got some code in msdn:"Programming with the Microsoft Office Visio 2003
ActiveX Control"
(http://msdn.microsoft.com/library/default.asp?url=/library/en-us/odc_vis200
3_ta/html/odc_vsProgrammingWithVisioActiveXControl.asp)
Like this:

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());
}
}




notice this line:
const UInt32 VISCMD_DRCONNECTORTOOL =
(UInt32)Visio.VisUICmds.visCmdDRConnectorTool;

this means complete Connector Tool of visio toolbar.
but I need other toolbar icons, like:visCmdDrawRect,visCmdSaveFile.
When I replace "visCmdDRConnectorTool" as "visCmdDrawRect" or
"visCmdSaveFile",it does not work.
How Can I do?
thanks for tips!
 

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