这是我从网上搜索的一段代码,用于在RichTextBox中插入gif图片,原贴地址为:http://blog.csdn.net/modest/archive/2006/04/12/660890.aspx下面代码是放在模块中,红色部分为出现问题的地方。
麻烦高手帮我高度一下。
Option ExplicitPrivate 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 LongPublic 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 EnumPublic Enum reObjectAspect
    reObjectAspectContent = DVASPECT_CONTENT'在这个地方会出现要求常数声明的提示
    reObjectAspectIcon = DVASPECT_ICON
End EnumPublic 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, 0End Function

解决方案 »

  1.   

     DVASPECT_ICON 和DVASPECT_CONTENT都是常数 没有定义
      

  2.   

    仅能提供MSDN的解释:
    COleClientItem::SetDrawAspect
    void SetDrawAspect( DVASPECT nDrawAspect );ParametersnDrawAspectA value from the DVASPECT enumeration. This parameter can have one of the following values: DVASPECT_CONTENT   Item is represented in such a way that it can be displayed as an embedded object inside its container.
    DVASPECT_THUMBNAIL   Item is rendered in a “thumbnail” representation so that it can be displayed in a browsing tool.
    DVASPECT_ICON   Item is represented by an icon.
    DVASPECT_DOCPRINT   Item is represented as if it were printed using the Print command from the File menu. 
    ResCall the SetDrawAspect member function to set the “aspect,” or view, of the item. The aspect specifies how the item is to be rendered by Draw when the default value for that function’s nDrawAspect argument is used.This function is called automatically by the Change Icon (and other dialogs that call the Change Icon dialog directly) to enable the iconic display aspect when requested by the user.COleClientItem Overview |  Class Members |  Hierarchy ChartSee Also   COleClientItem::GetDrawAspect, COleClientItem::Draw
      

  3.   

    DVASPECT_CONTENT是常数,一般都是到C++头文件中去找。