Undo on InternetExplorer

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Wiktor Zychla

    Undo on InternetExplorer

    I am still trying to get the Undo function work on Internet Explorer editor
    hosted as activex in my c# application.

    Some time ago I've found a note at msdn that says "undo is not supported". I
    gave up.

    But lately I've downloaded LutzRoeder Writer that makes use of undo
    function. I've looked at the code and it turns out that it uses
    IOleCommandTarg et interface to invoke this command.

    Because I cannot get it to work, I have questions:

    1. is it a good way to follow? the undo does not work when invoked by
    execCommand on IHtmlDocument. is there a chance that it will work with
    IOleCommandTarg et then?

    2. after few days of fighting, digging through msdn and the groups archive,
    I've came up with following code but it still does not work. when asking for
    CanUndo I always get 0.

    could anyone share his/her experiences with me and tell me where the problem
    could be? I can send the full source code of my webbrowser control if
    needed.
    thanks in advance,

    Wiktor Zychla

    ----------------------------------------------------------------------------
    ---

    public class MyWebBrowser
    {
    // the rest of the code is not here
    public enum MiscCommandTarg et

    {

    Find = 1, ViewSource = 2, Options = 3, Undo = 43

    }

    internal int GetCommandInfo( MiscCommandTarg et commandId )

    {

    OLECMD[] ole = new OLECMD[1];

    ole[0] = new OLECMD();

    ole[0].cmdID = (int)commandId;

    OLECMDTEXT ret = new OLECMDTEXT();



    ((IOleCommandTa rget)Document). QueryStatus( ref cmdGuid, 1, ole, ret );

    return ( (int)ole[0].cmdf >> 1 );

    }

    internal bool IsEnabled( MiscCommandTarg et commandId )

    {

    return ( (this.GetComman dInfo( commandId ) & 1) != 0);

    }

    internal object Execute( MiscCommandTarg et command )

    {

    return this.Execute( command, null );

    }

    internal object Execute( MiscCommandTarg et command, object[] arguments )

    {

    object[] array = new object[1];

    int n = ((IOleCommandTa rget)Document). Exec( ref cmdGuid, (int)command,
    2, ref arguments, ref array );

    if ( n != 0 )

    {

    MessageBox.Show ( string.Concat( "Execution of MSHTML command ID '",
    command, "' failed.") );

    }

    return array[0];

    }

    public bool CanUndo

    {

    get

    {

    return this.IsEnabled( MiscCommandTarg et.Undo);

    }

    }

    public void Undo()

    {

    if ( this.CanUndo ) this.Execute( MiscCommandTarg et.Undo );

    }

    }

    [StructLayout(La youtKind.Sequen tial)]

    public struct OLECMD

    {

    public int cmdID;

    public int cmdf;

    }

    [StructLayout(La youtKind.Sequen tial, CharSet=CharSet .Unicode)]

    public struct OLECMDTEXT

    {

    public int cmdtextf;

    public int cwActual;

    private int cwBuf;

    [MarshalAs(Unman agedType.ByValT Str, SizeConst=256)]

    public string text;

    }

    [ComImport, Guid("b722bccb-4e68-101b-a2bc-00aa00404770"),
    InterfaceType(C omInterfaceType .InterfaceIsIUn known)]

    public interface IOleCommandTarg et

    {

    [PreserveSig()]

    int QueryStatus(ref Guid pguidCmdGroup,

    int cCmds,

    [In(), Out()]

    OLECMD[] prgCmds,

    [In(), Out()]

    OLECMDTEXT cmdText );

    [PreserveSig()]

    int Exec(ref Guid pguidCmdGroup, int nCmdId, int nCmdExecOpt, ref object[]
    pvaIn, ref object[] pvaOut);

    }



Working...