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 < prev    next >
Text File  |  1994-10-10  |  5KB  |  154 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. End
  72. Attribute VB_Name = "Form1"
  73. Attribute VB_Creatable = False
  74. Attribute VB_Exposed = False
  75. Option Explicit
  76.  
  77. Private Sub mnuView_Click()
  78.     ' New: Set up error handling.
  79.     On Error Resume Next
  80.     ' Show all filenames.
  81.     cmnDlg.FileName = "*.*"
  82.     ' Display the Open common dialog.
  83.     cmnDlg.ShowOpen
  84.     ' Make sure a filename was entered and that the file exists.
  85.     If (cmnDlg.FileName <> "") And Len(Dir(cmnDlg.FileName)) Then
  86.         ' Display the file in the OLE object.
  87.         oleObject.CreateEmbed cmnDlg.FileName
  88.         ' New: If the file was not an OLE object,
  89.         ' load the file as a non-OLE object.
  90.         If Err Then DisplayNonOLEObject (cmnDlg.FileName)
  91.         ' New: Hide other objects
  92.         imgObj.Visible = False
  93.         txtObj.Visible = False
  94.         oleObject.Visible = True
  95.     End If
  96. End Sub
  97.  
  98. Private Sub mnuitExit_Click()
  99.     End
  100. End Sub
  101.  
  102. ' Resize the form to fit the object.
  103. Private Sub oleObject_Resize(HeightNew As Single, WidthNew As Single)
  104.     Me.Height = HeightNew
  105.     Me.Width = WidthNew
  106. End Sub
  107.  
  108. ' Handles displaying other types of files.
  109. Sub DisplayNonOLEObject(strFile As String)
  110.     ' Check for errors.
  111.     On Error Resume Next
  112.     Dim strBuffer As String, iFile As Integer
  113.     ' If the file is a graphic, display it in
  114.     ' an Image control.
  115.     imgObj.Picture = LoadPicture(strFile)
  116.     ' If the file was a valid picture, then
  117.     ' display the image control and hide others.
  118.     If Err = 0 Then
  119.         ' Hide other objects
  120.         imgObj.Visible = True
  121.         txtObj.Visible = False
  122.         oleObject.Visible = False
  123.         ' Reset form's Height and Width to match
  124.         ' Image control.
  125.         Me.Height = imgObj.Height
  126.         Me.Width = imgObj.Width
  127.     ' If the file wasn't a valid picture, then
  128.     ' load the data into a text box and hide other
  129.     ' controls.
  130.     Else
  131.         iFile = FreeFile
  132.         Open strFile For Binary As iFile
  133.         strBuffer = Space(LOF(iFile))
  134.         Get iFile, 1, strBuffer
  135.         Close iFile
  136.         txtObj.Text = strBuffer
  137.         ' Hide other objects
  138.         imgObj.Visible = False
  139.         txtObj.Visible = False
  140.         oleObject.Visible = False
  141.         ' Reset form's Height and Width to match
  142.         ' Text Box control.
  143.         Me.Height = txtObj.Height
  144.         Me.Width = txtObj.Width
  145.     End If
  146. End Sub
  147.  
  148. Private Sub oleObject_Updated(Code As Integer)
  149.     Me.Caption = oleObject.HostName
  150. End Sub
  151.  
  152.  
  153.  
  154.