home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Programmer'…arterly (Limited Edition) / Visual_Basic_Programmers_Journal_VB-CD_Quarterly_Limited_Edition_1995.iso / code / ch15code / viewer.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1994-10-10  |  4.5 KB  |  145 lines

  1. VERSION 4.00
  2. Begin VB.Form Form1 
  3.    Caption         =   "OLE Object Viewer"
  4.    ClientHeight    =   4230
  5.    ClientLeft      =   2295
  6.    ClientTop       =   2280
  7.    ClientWidth     =   6720
  8.    BeginProperty Font 
  9.       name            =   "MS Sans Serif"
  10.       charset         =   0
  11.       weight          =   400
  12.       size            =   8.25
  13.       underline       =   0   'False
  14.       italic          =   0   'False
  15.       strikethrough   =   0   'False
  16.    EndProperty
  17.    Height          =   4920
  18.    Left            =   2235
  19.    LinkTopic       =   "Form1"
  20.    MDIChild        =   -1  'True
  21.    ScaleHeight     =   540
  22.    ScaleWidth      =   540
  23.    Top             =   1650
  24.    Width           =   6840
  25.    Begin VB.TextBox txtObj 
  26.       Height          =   4215
  27.       Left            =   0
  28.       MultiLine       =   -1  'True
  29.       ScrollBars      =   3  'Both
  30.       TabIndex        =   1
  31.       Text            =   "Text1"
  32.       Top             =   0
  33.       Width           =   6735
  34.    End
  35.    Begin VB.Image imgObj 
  36.       Height          =   4215
  37.       Left            =   0
  38.       Top             =   0
  39.       Width           =   6735
  40.    End
  41.    Begin MSComDlg.CommonDialog cmnDlg 
  42.       Left            =   1200
  43.       Top             =   3960
  44.       _version        =   65536
  45.       _extentx        =   847
  46.       _extenty        =   847
  47.       _stockprops     =   0
  48.       dialogtitle     =   "View OLE File"
  49.       filter          =   "*.xls; *.doc; *.vsd"
  50.       filterindex     =   1
  51.    End
  52.    Begin VB.OLE oleObject 
  53.       AutoActivate    =   3  'Automatic
  54.       Class           =   "Word.Document.6"
  55.       Height          =   4215
  56.       Left            =   0
  57.       SizeMode        =   2  'AutoSize
  58.       TabIndex        =   0
  59.       Top             =   0
  60.       Width           =   6750
  61.    End
  62.    Begin VB.Menu mnuFile 
  63.       Caption         =   "&File"
  64.       Begin VB.Menu mnuView 
  65.          Caption         =   "&View..."
  66.       End
  67.       Begin VB.Menu mnuitExit 
  68.          Caption         =   "E&xit"
  69.       End
  70.    End
  71. Attribute VB_Name = "Form1"
  72. Attribute VB_Creatable = False
  73. Attribute VB_Exposed = False
  74. Option Explicit
  75. Private Sub mnuView_Click()
  76.     ' New: Set up error handling.
  77.     On Error Resume Next
  78.     ' Show all filenames.
  79.     cmnDlg.FileName = "*.*"
  80.     ' Display the Open common dialog.
  81.     cmnDlg.ShowOpen
  82.     ' Make sure a filename was entered and that the file exists.
  83.     If (cmnDlg.FileName <> "") And Len(Dir(cmnDlg.FileName)) Then
  84.         ' Display the file in the OLE object.
  85.         oleObject.CreateEmbed cmnDlg.FileName
  86.         ' New: If the file was not an OLE object,
  87.         ' load the file as a non-OLE object.
  88.         If Err Then DisplayNonOLEObject (cmnDlg.FileName)
  89.         ' New: Hide other objects
  90.         imgObj.Visible = False
  91.         txtObj.Visible = False
  92.         oleObject.Visible = True
  93.     End If
  94. End Sub
  95. Private Sub mnuitExit_Click()
  96.     End
  97. End Sub
  98. ' Resize the form to fit the object.
  99. Private Sub oleObject_Resize(HeightNew As Single, WidthNew As Single)
  100.     Me.Height = HeightNew
  101.     Me.Width = WidthNew
  102. End Sub
  103. ' Handles displaying other types of files.
  104. Sub DisplayNonOLEObject(strFile As String)
  105.     ' Check for errors.
  106.     On Error Resume Next
  107.     Dim strBuffer As String, iFile As Integer
  108.     ' If the file is a graphic, display it in
  109.     ' an Image control.
  110.     imgObj.Picture = LoadPicture(strFile)
  111.     ' If the file was a valid picture, then
  112.     ' display the image control and hide others.
  113.     If Err = 0 Then
  114.         ' Hide other objects
  115.         imgObj.Visible = True
  116.         txtObj.Visible = False
  117.         oleObject.Visible = False
  118.         ' Reset form's Height and Width to match
  119.         ' Image control.
  120.         Me.Height = imgObj.Height
  121.         Me.Width = imgObj.Width
  122.     ' If the file wasn't a valid picture, then
  123.     ' load the data into a text box and hide other
  124.     ' controls.
  125.     Else
  126.         iFile = FreeFile
  127.         Open strFile For Binary As iFile
  128.         strBuffer = Space(LOF(iFile))
  129.         Get iFile, 1, strBuffer
  130.         Close iFile
  131.         txtObj.Text = strBuffer
  132.         ' Hide other objects
  133.         imgObj.Visible = False
  134.         txtObj.Visible = False
  135.         oleObject.Visible = False
  136.         ' Reset form's Height and Width to match
  137.         ' Text Box control.
  138.         Me.Height = txtObj.Height
  139.         Me.Width = txtObj.Width
  140.     End If
  141. End Sub
  142. Private Sub oleObject_Updated(Code As Integer)
  143.     Me.Caption = oleObject.HostName
  144. End Sub
  145.