473,386 Members | 1,790 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

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
IOleCommandTarget 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
IOleCommandTarget 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 MiscCommandTarget

{

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

}

internal int GetCommandInfo( MiscCommandTarget commandId )

{

OLECMD[] ole = new OLECMD[1];

ole[0] = new OLECMD();

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

OLECMDTEXT ret = new OLECMDTEXT();

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

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

}

internal bool IsEnabled( MiscCommandTarget commandId )

{

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

}

internal object Execute( MiscCommandTarget command )

{

return this.Execute( command, null );

}

internal object Execute( MiscCommandTarget command, object[] arguments )

{

object[] array = new object[1];

int n = ((IOleCommandTarget)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(MiscCommandTarget.Undo);

}

}

public void Undo()

{

if ( this.CanUndo ) this.Execute( MiscCommandTarget.Undo );

}

}

[StructLayout(LayoutKind.Sequential)]

public struct OLECMD

{

public int cmdID;

public int cmdf;

}

[StructLayout(LayoutKind.Sequential, CharSet=CharSet.Unicode)]

public struct OLECMDTEXT

{

public int cmdtextf;

public int cwActual;

private int cwBuf;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst=256)]

public string text;

}

[ComImport, Guid("b722bccb-4e68-101b-a2bc-00aa00404770"),
InterfaceType(ComInterfaceType.InterfaceIsIUnknown )]

public interface IOleCommandTarget

{

[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);

}

Nov 15 '05 #1
0 1249

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Lyn | last post by:
Hi, I have a text control on a form which is bound to table field StartDate which is in Date format. When updating the table record via the form, any data entered into the StartDate control is...
3
by: Tom | last post by:
Hi, I wrote the following code in a c# winform. InternetExplorer ie = new InternetExplorer(); ie.Navigate(url, ref o, ref o, ref o, ref o); The url can be passed to the IE. However, how...
0
by: Afigels | last post by:
I have an asp.net application that has references to MSHTML and SHDocVw to automate InternetExplorer from asp.net page. It works fine at the originating PC where the page was coded and compiled. ...
4
by: Lars-Erik Aabech | last post by:
Hi! I've been walking in extacy since reading the article about test automation with IE in the latest MSDN mag. (http://msdn.microsoft.com/msdnmag/issues/05/10/TestRun/default.aspx) After a...
0
by: mammucion | last post by:
Trying to automate processing 80,000 data sets through 15 web pages. Application URL creates a new IE instance in which runs first a login form and then runs the rest of the pages in the new...
4
by: Dick Sutton | last post by:
I am so close, yet oh so far! Here's the problem: I want to load a string variable that contains HTML into an instance of SHDocVw.InternetExplorer. Here's what I have so far: Function...
8
by: Ludwig Wittgenstein | last post by:
Hi, all. How can i hook up an InternetExplorer object to a WebBrowser control that I have in my windows form. Basically what I want to do is automate the WebBrowser control via the...
4
by: =?Utf-8?B?UmljaA==?= | last post by:
Hello, Does vb2005 have a built-in UnDo feature / object for applications so that I can undo actions like other windows apps? Or do I have to write my own UnDo routine? If vb2005 does have a...
1
by: Jeremy | last post by:
I'm working on an application that does some DOM manipulation. I want to add a mechanism for "Undo" so that the user can revert to the previous state after performing a mistaken action. Simple...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.