Richtextbox [ OleObjects (Ole Dialog Box) ] and a licence question

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
Hello.
I have a two questions:
1) There are a richtextbox and a button in my form. I want to add an oleobject (MS Word like) in rrichtextbox. I use this code:
This is the main API used to display the Insert Obj DlgBox
<br/>
Private Declare Ansi Function OleUIInsertObject Lib "oledlg.dll" Alias "OleUIInsertObjectA" (ByRef inParam As OleUIInsertObjectType) As Integer<br/>
This is used to get the ProgID from Class ID. <br/>
Note that this API need us to pass LPOLESTR * from Visual Basic.
<br/>
Private Declare Unicode Function ProgIDFromCLSID Lib "ole32.dll" (ByRef clsid As Guid, <Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPWStr)> ByRef strAddess As String) As Integer<br/>
Constants used in the dwFlags of OleUIInsertObjectType. <br/>
<br/>
Private Declare Sub OleCreate Lib "ole32.dll" (ByRef rclsid As Int32, ByVal riid As Int32, ByVal renderopt As Int32, ByRef pFormatEtc As Integer, ByVal pClientSite As Int32, ByVal pStg As Int32, ByVal ppvObj As Int32)<br/>
<br/>
Private Declare Sub OleRun Lib "ole32.dll" (ByRef pUnknown As Int32)<br/>
<br/>
Const IOF_SHOWHELP As Integer = &H1<br/>
Const IOF_SELECTCREATENEW As Integer = &H2<br/>
Const IOF_SELECTCREATEFROMFILE As Integer = &H4<br/>
Const IOF_CHECKLINK As Integer = &H8<br/>
Const IOF_CHECKDISPLAYASICON As Integer = &H10<br/>
Const IOF_CREATENEWOBJECT As Integer = &H20<br/>
Const IOF_CREATEFILEOBJECT As Integer = &H40<br/>
Const IOF_CREATELINKOBJECT As Integer = &H80<br/>
Const IOF_DISABLELINK As Integer = &H100<br/>
Const IOF_VERIFYSERVERSEXIST As Integer = &H200<br/>
Const IOF_DISABLEDISPLAYASICON As Integer = &H400<br/>
Const IOF_HIDECHANGEICON As Integer = &H800<br/>
Const IOF_SHOWINSERTCONTROL As Integer = &H1000<br/>
Const IOF_SELECTCREATECONTROL As Integer = &H2000<br/>
<br/>
<br/>
Return codes from OleUIInsertObject <br/>
Const OLEUI_FALSE As Integer = 0<br/>
Const OLEUI_SUCCESS As Integer = 1 No error, same as OLEUI_OK.
<br/>
Const OLEUI_OK As Integer = 1 OK button pressed. <br/>
Const OLEUI_CANCEL As Integer = 2<br/>
<br/>
<Runtime.InteropServices.StructLayout(Runtime.InteropServices.LayoutKind.Sequential, pack:=1)><br/>
<br/>
Private Structure OleUIInsertObjectType<br/>
These IN fields are standard across all OLEUI dialog box functions.
<br/>
Public cbStruct As Integer<br/>
Public dwFlags As Integer<br/>
Public hWndOwner As Integer<br/>
<Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPStr)> Public lpszCaption As String LPCSTR
<br/>
Public lpfnHook As Integer LPFNOLEUIHOOK
<br/>
Public lCustData As Integer LPARAM <br/>
Public hInstance As Integer<br/>
<Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPStr)> Public lpszTemplate As String LPCSTR
<br/>
Public hResource As Integer HRSRC <br/>
Public clsid As Guid<br/>
Specifics for OLEUIINSERTOBJECT. <br/>
<Runtime.InteropServices.MarshalAs(Runtime.InteropServices.UnmanagedType.LPTStr)> Public lpszFile As String LPTSTR
<br/>
Public cchFile As Integer<br/>
Public cClsidExclude As Integer<br/>
Public lpClsidExclude As Integer LPCLSID
<br/>
Public IID As Guid<br/>
Specifics to create objects if flags say so.
<br/>
Public oleRender As Integer<br/>
Public lpFormatEtc As Integer LPFORMATETC
<br/>
Public lpIOleClientSite As Integer LPOLECLIENTSITE
<br/>
Public lpIStorage As Integer LPSTORAGE
<br/>
Public ppvObj As Integer LPVOID FAR *
<br/>
Public sc As Integer SCODE <br/>
Public hMetaPict As Integer HGLOBAL <br/>
End Structure<br/>
<br/>
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click<br/>
Dim UIInsertObj As OleUIInsertObjectType<br/>
Dim retValue As Integer<br/>
Dim lpolestr, ProgId As String<br/>
Try<br/>
Prepare the OleUIInsertObjectType.
<br/>
UIInsertObj.cbStruct = Runtime.InteropServices.Marshal.SizeOf(GetType(OleUIInsertObjectType))<br/>
UIInsertObj.dwFlags = IOF_SELECTCREATENEW<br/>
UIInsertObj.hWndOwner = Me.Handle.ToInt32<br/>
UIInsertObj.lpszFile = New String(ControlChars.NullChar, 256)<br/>
UIInsertObj.cchFile = Len(UIInsertObj.lpszFile)<br/>
<br/>
Call the API to display the dialog box.
<br/>
retValue = OleUIInsertObject(UIInsertObj)<br/>
If retValue = OLEUI_OK Then<br/>
If we select to insert from a new object
<br/>
If (UIInsertObj.dwFlags And IOF_SELECTCREATENEW) = IOF_SELECTCREATENEW Then<br/>
ProgIDFromCLSID(UIInsertObj.clsid, lpolestr)<br/>
<br/>
MsgBox(lpolestr)<br/>
<br/>
OleCreate(UIInsertObj.clsid, UIInsertObj.IID, UIInsertObj.oleRender, UIInsertObj.lpFormatEtc, UIInsertObj.lpIOleClientSite, UIInsertObj.lpIStorage,
UIInsertObj.ppvObj)<br/>
OleRun(Val(UIInsertObj.clsid.ToString))<br/>
<br/>
RichTextBox1.OLEObjects.add(, , "", ProgId)<br/>
Else If we select to insert from file
<br/>
RichTextBox1.OLEObjects.add(, , UIInsertObj.lpszFile)
<br/>
End If<br/>
End If<br/>
Catch ex As Exception<br/>
MsgBox(ex.Message)<br/>
End Try<br/>
End Sub

But, this code shows ole dialog box. When i select an ole objects in dialog box, messagebox shows a program id.
I want when clicking OK Button Run this application..then create a new object of this type..and then close this application and have this new created object pasted into my Richtextbox.
I used OleCreate Api and OleRun Api, but i couldnt. I had some errors.
2) If i use Richtextbox ocx with in VB6 (Richtx32.ocx), i can use:
<div style="color:Black; background-color:White
<pre> <span style="color:Green RichTextBox1.OLEObjects.add(, , "", ProgId)

<br/>

[/code]

But, i dont have a Visual Basic 6 licence. Is there a problem to use "Richtx32.ocx" file, in VB.Net about licence?
Thank you very much.

View the full article
 
Back
Top