[SIZE=2][COLOR=#0000ff]
' This is the main API used to display the Insert Obj DlgBox
Private Declare Ansi Function OleUIInsertObject Lib "oledlg.dll" _
Alias "OleUIInsertObjectA" (ByRef inParam As OleUIInsertObjectType) As Integer
' This is used to get the ProgID from Class ID.
' Note that this API need us to pass LPOLESTR * from Visual Basic.
Private Declare Unicode Function ProgIDFromCLSID Lib "ole32.dll" _
(ByRef clsid As Guid, <MarshalAs(UnmanagedType.LPWStr)> ByRef strAddess As String) As Integer
' Constants used in the dwFlags of OleUIInsertObjectType.
Const IOF_SHOWHELP As Integer = &H1
Const IOF_SELECTCREATENEW As Integer = &H2
Const IOF_SELECTCREATEFROMFILE As Integer = &H4
Const IOF_CHECKLINK As Integer = &H8
Const IOF_CHECKDISPLAYASICON As Integer = &H10
Const IOF_CREATENEWOBJECT As Integer = &H20
Const IOF_CREATEFILEOBJECT As Integer = &H40
Const IOF_CREATELINKOBJECT As Integer = &H80
Const IOF_DISABLELINK As Integer = &H100
Const IOF_VERIFYSERVERSEXIST As Integer = &H200
Const IOF_DISABLEDISPLAYASICON As Integer = &H400
Const IOF_HIDECHANGEICON As Integer = &H800
Const IOF_SHOWINSERTCONTROL As Integer = &H1000
Const IOF_SELECTCREATECONTROL As Integer = &H2000
' Return codes from OleUIInsertObject
Const OLEUI_FALSE As Integer = 0
Const OLEUI_SUCCESS As Integer = 1 ' No error, same as OLEUI_OK.
Const OLEUI_OK As Integer = 1 ' OK button pressed.
Const OLEUI_CANCEL As Integer = 2
<StructLayout(LayoutKind.Sequential, pack:=1)> _
Private Structure OleUIInsertObjectType
' These IN fields are standard across all OLEUI dialog box functions.
Public cbStruct As Integer
Public dwFlags As Integer
Public hWndOwner As Integer
<MarshalAs(UnmanagedType.LPStr)> Public lpszCaption As String ' LPCSTR
Public lpfnHook As Integer ' LPFNOLEUIHOOK
Public lCustData As Integer ' LPARAM
Public hInstance As Integer
<MarshalAs(UnmanagedType.LPStr)> Public lpszTemplate As String ' LPCSTR
Public hResource As Integer ' HRSRC
Public clsid As Guid
' Specifics for OLEUIINSERTOBJECT.
<MarshalAs(UnmanagedType.LPTStr)> Public lpszFile As String ' LPTSTR
Public cchFile As Integer
Public cClsidExclude As Integer
Public lpClsidExclude As Integer ' LPCLSID
Public IID As Guid
' Specifics to create objects if flags say so.
Public oleRender As Integer
Public lpFormatEtc As Integer ' LPFORMATETC
Public lpIOleClientSite As Integer ' LPOLECLIENTSITE
Public lpIStorage As Integer ' LPSTORAGE
Public ppvObj As Integer ' LPVOID FAR *
Public sc As Integer ' SCODE
Public hMetaPict As Integer ' HGLOBAL
End Structure
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim UIInsertObj As OleUIInsertObjectType
Dim retValue As Integer
Dim lpolestr, ProgId As String
Try
' Prepare the OleUIInsertObjectType.
UIInsertObj.cbStruct = Marshal.SizeOf(GetType(OleUIInsertObjectType))
UIInsertObj.dwFlags = IOF_SELECTCREATENEW
UIInsertObj.hWndOwner = Me.Handle.ToInt32
UIInsertObj.lpszFile = New String(ControlChars.NullChar, 256)
UIInsertObj.cchFile = Len(UIInsertObj.lpszFile)
' Call the API to display the dialog box.
retValue = OleUIInsertObject(UIInsertObj)
If retValue = OLEUI_OK Then
' If we select to insert from a new object
If (UIInsertObj.dwFlags And IOF_SELECTCREATENEW) = IOF_SELECTCREATENEW Then
ProgIDFromCLSID(UIInsertObj.clsid, lpolestr)
MsgBox(lpolestr)
'RichTextBox1.OLEObjects.add(, , "", ProgId)
Else ' If we select to insert from file
'RichTextBox1.OLEObjects.add(, , UIInsertObj.lpszFile)
End If
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
[/COLOR][COLOR=black]