| Home | Previous Lesson: OLE Control Attributes Next Lesson: Opening a Sub-Storage |
This function comes in lot of flavors. Only the first format is discussed here and other topics are explained in the "OLE Storages and Streams" session. Open opens the specified file in the OLE control. The following example opens an OLE file, however you can open any OLE server file such as a word document, excel spread sheet, etc. and save as a OLE file. All the examples shown in this section are available in the w_ole_20 window in the ole2.pbl library.
All the code in the library uses a directory called "c:\workdir". Make sure you have the directory on your computer and unzip the zip file you download into the "c:\workdir" directory. You can run the window and test the functionality, since all the support files are also available with this.
Open the application "object_embedding_n_linking-2_0" from "ole2.pbl" library. Run the application. Select 'Module > OLE Control Examples' menu option. Click on the Open Doc CommandButton.
String lFileNameWithFullPath, lFileName
Integer lResult
lResult = GetFileOpenName( "Select Document File " + &
"to Open in OLE Control", lFileNameWithFullPath, &
lFileName, "DOC", "DOC Files (*.doc), *.doc" )
If lResult <> 1 Then Return
lResult = ole_1.Open( lFileNameWithFullPath )
If lResult <> 0 Then
MessageBox( "Error while opening the " + &
specified File", "Error No: " + String( lResult ))
Return -1000
End If
We are asking the user to select the file to open by calling GetFileOpenName() function. We are then opening that document in the OLE control using Open() function.
| Home | Previous Lesson: OLE Control Attributes Next Lesson: Opening a Sub-Storage |