RichTextBox插入.gif图片

原创 2007年10月07日 09:35:00

'转载
'实际上还可以嵌入其他组件,比如Windows Media Player等,下面以比较成熟的QQ的ImageOle为例。
'
'需要组件:
'ImageOle.dll   在QQ的目录下找,如果非XP系统则还需要GdiPlus.dll。
'OleLib.tlb         下载地址:http://www.mvps.org/emorcillo/download/vb6/tl_ole.zip(此压缩包我gmail邮箱里也有)
'
'引用两个组件后,在窗体添加一个RichTextBox1,然后将下面代码放在.bas中

Option Explicit
Private Declare Sub ZeroMemory Lib "KERNEL32" Alias "RtlZeroMemory" (dest As Any, ByVal numBytes As Long)
Private Declare Function InvalidateRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT, ByVal bErase As Long) As Long
Private Declare Function GetWindowRect Lib "user32.dll" (ByVal hwnd As Long, ByRef lpRect As RECT) As Long
Public Declare Function UpdateWindow Lib "user32.dll" (ByVal hwnd As Long) As Long

Public Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, lParam As Any) As Long
Private Const WM_USER = &H400
Private Const EM_GETOLEINTERFACE = (WM_USER + 60)
Private Const EM_POSFROMCHAR = (WM_USER + 38)

Public Enum reCharPos
    reSelection = -1
End Enum

Public Enum reObjectAspect
    reObjectAspectContent = DVASPECT_CONTENT
    reObjectAspectIcon = DVASPECT_ICON
End Enum

Public Function AddClass(hwnd As Long, ObjIUnknown As stdole.IUnknown, _
      Optional ByVal CharPos As Long = reSelection, _
      Optional ByVal InitialAspect As reObjectAspect = reObjectAspectContent) As IRichEditOle
   
    Dim OleObject As olelib.IOleObject
    Dim Storage As olelib.IStorage
    Dim ClientSite As olelib.IOleClientSite
    Dim tOUIIO As olelib.OLEUIINSERTOBJECT
    Dim REOBJ As olelib.REOBJECT
    Dim CLSID As olelib.UUID
    Dim hMFPict As Long
   
    Dim mILockBytes As ILockBytes
    '创建Global Heap,实例化mILockBytes
    Set mILockBytes = CreateILockBytesOnHGlobal(0&, True)
    '创建storage,实例化mIStorage
    Set Storage = StgCreateDocfileOnILockBytes(mILockBytes, STGM_SHARE_EXCLUSIVE _
                    Or STGM_CREATE Or STGM_READWRITE, 0)
   

    Dim RichEditOle As IRichEditOle
    SendMessage hwnd, EM_GETOLEINTERFACE, 0&, RichEditOle


    Set ClientSite = RichEditOle.GetClientSite
'    Set Storage = StgCreateDocfile(vbNullString, STGM_CREATE Or STGM_READWRITE Or STGM_DELETEONRELEASE Or STGM_SHARE_EXCLUSIVE)

    Set OleObject = ObjIUnknown
    OleObject.GetUserClassID CLSID

    On Error Resume Next

    If hMFPict = 0 Then hMFPict = OleGetIconOfClass(CLSID, vbNullString, 1)


    If Err.Number <> 0 Then InitialAspect = reObjectAspectContent

    On Error GoTo 0

    OleSetContainedObject ObjIUnknown, 1

    With REOBJ
        .cbStruct = Len(REOBJ)
        LSet .CLSID = CLSID
        .DVASPECT = DVASPECT_CONTENT
        .cp = REO_CP_SELECTION
        .dwFlags = REO_DYNAMICSIZE
        .sizel.cx = 0
        .sizel.cy = 0
        .dwUser = 0
        Set .pStg = Storage
        Set .polesite = ClientSite
        Set .poleobj = ObjIUnknown
    End With

    RichEditOle.InsertObject REOBJ
   
    ZeroMemory REOBJ, LenB(REOBJ)
    ZeroMemory CLSID, LenB(CLSID)
     
    Set AddClass = RichEditOle
    Set OleObject = Nothing
    Set ClientSite = Nothing
    Set Storage = Nothing

    SendMessage hwnd, &HF, 0, 0

End Function

private Sub CommandButton_Click()
    Dim g As New GifAnimator
    g.LoadFromFile App.Path & "/" & sPictureFilePath & ".gif"
    Call AddClass(RTxtCIN.hwnd, g)
end sun 

MS SQLSERVER中如何快速获取表的记录总数

 在数据库应用的设计中,我们往往会需要获取某些表的记录总数,用于判断表的记录总数是否过大,是否需要备份数据等。我们通常的做法是:select count(*) as c from tableA 。然而...
  • eaglet
  • eaglet
  • 2003-05-27 11:13:00
  • 1453

RichTextBox插入.gif图片

转载 实际上还可以嵌入其他组件,比如Windows Media Player等,下面以比较成熟的QQ的ImageOle为例。 需要组件: ImageOle.dll   在QQ的目录下找,如果非XP系...
  • shaxunyeman
  • shaxunyeman
  • 2007-10-07 09:35:00
  • 1317

c# <em>richtextbox</em> 实现动态<em>gif</em>显示

c# <em>richtextbox</em> 实现动态<em>gif</em>显示 综合评分:3 收藏(3)评论(11)举报 所需: 3积分/C币 下载个数: 40 开通VIP 立即下载 评论共有11条 asd8215881 2015-07-20 ...
  • 2018年04月18日 00:00

c#自带的richtextbox实现动态的gif

1)想用c#自带的richtextbox实现动态的gif效果不是一件简单的事情, 在这里本人通过上网查询做了一个简单的demo,下载地址如下(下载分数有点高请谅解): http://downloa...
  • czh4869623
  • czh4869623
  • 2012-03-27 15:25:07
  • 1257

RichtextBox 插入图片

Bitmap bmp = new Bitmap(@"D:/System/My Documents/My Pictures/Misc/4_213071.gif");Clipboard.SetDataOb...
  • songkexin
  • songkexin
  • 2007-12-04 07:57:00
  • 1084

RichTextbox保存为图片

FileStream pngfs = new FileStream("C:\\1.png", FileMode.OpenOrCreate); RenderTargetBitmap rtb = ...
  • ima_zhan
  • ima_zhan
  • 2014-09-05 23:28:22
  • 1109

如何在C#下利用RichTextBox打开一个有文字格式和图片的Word文档

小知识点:.Net Framework 4.0 和.Net Framework 4.0 Client Profile区别:       .NET Framework Client Profile是....
  • xiaohuizi2009
  • xiaohuizi2009
  • 2012-06-22 11:44:11
  • 4586

VB中实现GIF嵌入到RichTextBox

原帖:http://blog.csdn.net/Modest/archive/2006/04/12/660890.aspx 实际上还可以嵌入其他组件,比如Windows Media Player等,下...
  • fengrx
  • fengrx
  • 2009-05-21 19:56:00
  • 977

C# 让RichTextBox支持GIF

我只是做了一些简单的测试...有疑问给我发消息把.  使用方法 //获取选择的图形 并且保存出来 private void button2_Click(object sender, EventArgs...
  • zgke
  • zgke
  • 2009-07-24 16:07:00
  • 5113

在RichTextBox控件加入图片

// 作者Blog:http://blog.csdn.net/huhong81312/using System;using System.Collections.Specialized;using S...
  • mliu
  • mliu
  • 2007-01-17 15:51:00
  • 917
收藏助手
不良信息举报
您举报文章:RichTextBox插入.gif图片
举报原因:
原因补充:

(最多只允许输入30个字)