Tutorials to .com

Tutorials to .com » Dotnet » Winform » insert r in richtextbox Animation / control

insert r in richtextbox Animation / control

Print View , by: iSee ,Total views: 10 ,Word Count: 553 ,Date: Fri, 21 Aug 2009 Time: 4:08 PM

Richtextbox insert picture in many ways too, but generally can not be changed, it is necessary to achieve the animation should at least achieve a activex control, however. Net to support poor activex, I tried to use c # to write a activex, but the effect of poor basicdynamic.

(Note) is almost here, someone else's C++ + + code (Chiang Sheng), and come in msdn (So, I am not a master)

This is my part in gowk code (with deletion) used a common study

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Runtime.InteropServices;

using gowk.common;

namespace gowk.controls
(
public class GRichTextBox_: RichTextBox
(
public GRichTextBox_ ()
(
)
# region insert ole
public void Insersert (IOleObject oleObj)
(
RichEidtOle ole = new RichEidtOle (this);
ole.InsertOle (oleObj);
)
public void Insersert (Control control)
(
RichEidtOle ole = new RichEidtOle (this);
ole.InsertControl (control);
)
public void InsertImage (string imageFile)
(
Image img = Image.FromFile (imageFile);
Type t = Type.GetTypeFromProgID ( "ImageOle.GifAnimator.1");
object o = System.Activator.CreateInstance (t);
bool b = o is IOleObject;
if (! b) throw (new System.Exception ( "Unable to create Ole Object"));
t.InvokeMember ( "LoadFromFile",
System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.InvokeMethod,
null,
o,
new object [] (imageFile));
if (b)
this.Insersert ((IOleObject) o);
)
class RichEidtOle
(
private RichTextBox _richEdit;
private IRichEditOle _RichEditOle;
public RichEidtOle (RichTextBox richEdit)
(
this._richEdit = richEdit;
)
private IRichEditOle IRichEditOle
(
get
(
if (this._RichEditOle == null)
(
this._RichEditOle = SendMessage (this._richEdit.Handle, API.EM_GETOLEINTERFACE, 0);
)
return this._RichEditOle;
)
)
public void InsertControl (Control control)
(
if (control == null) return;
IntPtr pLockBytes = API.CreateILockBytesOnHGlobal (IntPtr.Zero, true);
IntPtr pStorage = API.StgCreateDocfileOnILockBytes (pLockBytes, STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE, 0);
IntPtr pOleClientSite = this.IRichEditOle.GetClientSite ();
REOBJECT roeObject = new REOBJECT ();
roeObject.clsid = Marshal.GenerateGuidForType (control.GetType ());
roeObject.pstg = pStorage;
roeObject.poleobj = Marshal.GetIUnknownForObject (control);
roeObject.polesite = pOleClientSite;
roeObject.dvaspect = DVASPECT.DVASPECT_CONTENT;
roeObject.dwFlags = ReoObjectFlag.REO_BELOWBASELINE;
this.IRichEditOle.InsertObject (roeObject);
control.Select ();
control.Focus ();
)
public void InsertOle (IOleObject oleObject)
(
if (oleObject == null) return;
Guid guid = oleObject.GetUserClassID ();
IntPtr pLockBytes = API.CreateILockBytesOnHGlobal (IntPtr.Zero, true);
IntPtr pStorage = API.StgCreateDocfileOnILockBytes (pLockBytes, STGM.STGM_SHARE_EXCLUSIVE | STGM.STGM_CREATE | STGM.STGM_READWRITE, 0);
IntPtr pOleClientSite = this.IRichEditOle.GetClientSite ();
REOBJECT roeObject = new REOBJECT ();
roeObject.clsid = guid;
roeObject.pstg = pStorage;
roeObject.poleobj = Marshal.GetIUnknownForObject (oleObject);
roeObject.polesite = pOleClientSite;
roeObject.dvaspect = DVASPECT.DVASPECT_CONTENT;
roeObject.dwFlags = ReoObjectFlag.REO_BELOWBASELINE;
this.IRichEditOle.InsertObject (roeObject);
)
[DllImport ( "User32.dll", CharSet = CharSet.Auto, PreserveSig = false)]
public static extern IRichEditOle SendMessage (IntPtr hWnd, int message, int wParam);
)
# endregion
)
)



.Net Windows development Articles


Can't Find What You're Looking For?


Rating: Not yet rated

Comments

No comments posted.