Beispiel #1
0
        /// <summary>
        /// 获得richtextBox中现有的图片集合
        /// </summary>
        /// <returns></returns>
        public IMLibrary.gifCollections GetExistGifs()
        {
            IMLibrary.gifCollections tempGifs = new gifCollections();

            IMLibrary.ExtRichTextBox.REOBJECT reObject = new  REOBJECT ();
            IMLibrary.MyPicture pic;
            for (int i = 0; i < this.GetRichEditOleInterface().GetObjectCount(); i++)//循环访问richbox中所有图片或对像
            {
                this.GetRichEditOleInterface().GetObject(i, reObject, IMLibrary.ExtRichTextBox.GETOBJECTOPTIONS.REO_GETOBJ_ALL_INTERFACES);
                pic = this.findPic(reObject.dwUser);//在图片集合中查找此图片
                if (pic != null && pic.ImageMD5.Length==32)//如果此图片名在集合中
                {
                    pic.Pos  = reObject.cp;//获得图片的位置
                    pic.IsSent = true;//标识发送当前图片
                    tempGifs.add(pic);//将图片添加进发送集合
                }
            }
            return tempGifs;
        }
Beispiel #2
0
			public void UpdateObjects()
			{
				int k = this.IRichEditOle.GetObjectCount();

				for (int i = 0; i < k; i++)
				{
					REOBJECT reoObject = new REOBJECT();

					this.IRichEditOle.GetObject(i, reoObject, GETOBJECTOPTIONS.REO_GETOBJ_ALL_INTERFACES);

					if (reoObject.dwUser == 1)
					{
						Point pt = this._richEdit.GetPositionFromCharIndex(reoObject.cp);
//						MessageBox.Show(reoObject.fileName );
						Rectangle rect = new Rectangle(pt, reoObject.sizel);

						this._richEdit.Invalidate(rect, false); // repaint
					}
				}
			}
Beispiel #3
0
			public void InsertOleObject(IOleObject oleObject)
			{
				if (oleObject == null)
					return;

				//-----------------------
				ILockBytes pLockBytes;
				CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes);

				IStorage pStorage;
				StgCreateDocfileOnILockBytes(pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE|STGM.STGM_CREATE|STGM.STGM_READWRITE), 0, out pStorage);

				IOleClientSite pOleClientSite;
				this.IRichEditOle.GetClientSite(out pOleClientSite);
				//-----------------------

				//-----------------------
				Guid guid = new Guid();

				oleObject.GetUserClassID(ref guid);
				//-----------------------

				//-----------------------
				OleSetContainedObject(oleObject, true);

				REOBJECT reoObject = new REOBJECT();
				
				reoObject.cp = this._richEdit.TextLength;

				reoObject.clsid = guid;
				reoObject.pstg = pStorage;
				reoObject.poleobj = Marshal.GetIUnknownForObject(oleObject);
				reoObject.polesite = pOleClientSite;
				reoObject.dvAspect = (uint)DVASPECT.DVASPECT_CONTENT;
				reoObject.dwFlags = (uint)REOOBJECTFLAGS.REO_BELOWBASELINE;

				this.IRichEditOle.InsertObject(reoObject);
				//-----------------------

				//-----------------------
				Marshal.ReleaseComObject(pLockBytes);
				Marshal.ReleaseComObject(pOleClientSite);
				Marshal.ReleaseComObject(pStorage);
				//-----------------------
			}
Beispiel #4
0
			public void InsertMyDataObject(myDataObject mdo)
			{
				if (mdo == null)
					return;

				//-----------------------
				ILockBytes pLockBytes;
				int sc = CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes);

				IStorage pStorage;
				sc = StgCreateDocfileOnILockBytes(pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE|STGM.STGM_CREATE|STGM.STGM_READWRITE), 0, out pStorage);
				
				IOleClientSite pOleClientSite;
				this.IRichEditOle.GetClientSite(out pOleClientSite);
				//-----------------------

				Guid guid = Marshal.GenerateGuidForType(mdo.GetType());

				Guid IID_IOleObject = new Guid("{00000112-0000-0000-C000-000000000046}");
				Guid IID_IDataObject = new Guid("{0000010e-0000-0000-C000-000000000046}");
				Guid IID_IUnknown = new Guid("{00000000-0000-0000-C000-000000000046}");

				object pOleObject;

				int hr = OleCreateStaticFromData(mdo, ref IID_IOleObject, (uint)OLERENDER.OLERENDER_FORMAT, ref mdo.mpFormatetc, pOleClientSite, pStorage, out pOleObject);

				if (pOleObject == null)
					return;
				//-----------------------

				
				//-----------------------
				OleSetContainedObject(pOleObject, true);

				REOBJECT reoObject = new REOBJECT();

				reoObject.cp = this._richEdit.TextLength;

				reoObject.clsid = guid;
				reoObject.pstg = pStorage;
				reoObject.poleobj = Marshal.GetIUnknownForObject(pOleObject);
				reoObject.polesite = pOleClientSite;
				reoObject.dvAspect = (uint)(DVASPECT.DVASPECT_CONTENT);
				reoObject.dwFlags = (uint)(REOOBJECTFLAGS.REO_BELOWBASELINE);
				reoObject.dwUser = 0;

				this.IRichEditOle.InsertObject(reoObject);
				//-----------------------

				//-----------------------
				Marshal.ReleaseComObject(pLockBytes);
				Marshal.ReleaseComObject(pOleClientSite);
				Marshal.ReleaseComObject(pStorage);
				Marshal.ReleaseComObject(pOleObject);
				//-----------------------
			}
Beispiel #5
0
			public bool InsertImageFromFile(string strFilename)
			{
				//-----------------------
				ILockBytes pLockBytes;
				CreateILockBytesOnHGlobal(IntPtr.Zero, true, out pLockBytes);

				IStorage pStorage;
				StgCreateDocfileOnILockBytes(pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE|STGM.STGM_CREATE|STGM.STGM_READWRITE), 0, out pStorage);
				
				IOleClientSite pOleClientSite;
				this.IRichEditOle.GetClientSite(out pOleClientSite);
				//-----------------------

				
				//-----------------------
				FORMATETC formatEtc = new FORMATETC();

				formatEtc.cfFormat = 0;
				formatEtc.ptd = IntPtr.Zero;
				formatEtc.dwAspect = DVASPECT.DVASPECT_CONTENT;
				formatEtc.lindex = -1;
				formatEtc.tymed = TYMED.TYMED_NULL;
				
				Guid IID_IOleObject = new Guid("{00000112-0000-0000-C000-000000000046}");
				Guid CLSID_NULL = new Guid("{00000000-0000-0000-0000-000000000000}");
				
				object pOleObjectOut;

				// I don't sure, but it appears that this function only loads from bitmap
				// You can also try OleCreateFromData, OleLoadPictureIndirect, etc.
				int hr = OleCreateFromFile(ref CLSID_NULL, strFilename, ref IID_IOleObject, (uint)OLERENDER.OLERENDER_DRAW, ref formatEtc, pOleClientSite, pStorage, out pOleObjectOut);

				if (pOleObjectOut == null)
				{
					Marshal.ReleaseComObject(pLockBytes);
					Marshal.ReleaseComObject(pOleClientSite);
					Marshal.ReleaseComObject(pStorage);

					return false;
				}

				IOleObject pOleObject = (IOleObject)pOleObjectOut;
				//-----------------------


				//-----------------------
				Guid guid = new Guid();

				//guid = Marshal.GenerateGuidForType(pOleObject.GetType());
				pOleObject.GetUserClassID(ref guid);
				//-----------------------

				//-----------------------
				OleSetContainedObject(pOleObject, true);

				REOBJECT reoObject = new REOBJECT();

				reoObject.cp = this._richEdit.TextLength;

				reoObject.clsid = guid;
				reoObject.pstg = pStorage;
				reoObject.poleobj = Marshal.GetIUnknownForObject(pOleObject);
				reoObject.polesite = pOleClientSite;
				reoObject.dvAspect = (uint)(DVASPECT.DVASPECT_CONTENT);
				reoObject.dwFlags = (uint)(REOOBJECTFLAGS.REO_BELOWBASELINE);
				reoObject.dwUser = 0;

				this.IRichEditOle.InsertObject(reoObject);
				//-----------------------

				//-----------------------
				Marshal.ReleaseComObject(pLockBytes);
				Marshal.ReleaseComObject(pOleClientSite);
				Marshal.ReleaseComObject(pStorage);
				Marshal.ReleaseComObject(pOleObject);
				//-----------------------

				return true;
			}
Beispiel #6
0
			public void InsertControl(Control control)
			{
				if (control == null)
					return;

				Guid guid = Marshal.GenerateGuidForType(control.GetType());

				//-----------------------
                ILockBytes pLockBytes;
				CreateILockBytesOnHGlobal(IntPtr.Zero, true  ,out pLockBytes);

				IStorage pStorage;
				StgCreateDocfileOnILockBytes (pLockBytes, (uint)(STGM.STGM_SHARE_EXCLUSIVE|STGM.STGM_CREATE|STGM.STGM_READWRITE), 0, out pStorage);
				
				IOleClientSite pOleClientSite;
				this.IRichEditOle.GetClientSite(out pOleClientSite);
				//-----------------------

				//-----------------------
			    REOBJECT reoObject=new REOBJECT();
                    
				
				reoObject.cp = this._richEdit.SelectionStart;//this._richEdit.TextLength;
				reoObject.clsid = guid;
				reoObject.pstg = pStorage;
				reoObject.poleobj = Marshal.GetIUnknownForObject(control);
				reoObject.polesite = pOleClientSite;
				reoObject.dvAspect = (uint)(DVASPECT.DVASPECT_CONTENT);
				reoObject.dwFlags = (uint)(REOOBJECTFLAGS.REO_BELOWBASELINE);
				try
				{
					reoObject.dwUser =(control as MyPicture).Index ;
				}
				catch{}
				this.IRichEditOle.InsertObject(reoObject);

				//-----------------------
				//-----------------------

				Marshal.ReleaseComObject(pLockBytes);
				Marshal.ReleaseComObject(pOleClientSite);
				Marshal.ReleaseComObject(pStorage);
				//-----------------------
			}