home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 10 / 10.iso / l / l406 / 3.ddi / OLEMAIN.FR_ / OLEMAIN.bin (.txt)
Encoding:
Visual Basic Form  |  1992-10-21  |  8.9 KB  |  330 lines

  1. VERSION 2.00
  2. Begin Form frmMain 
  3.    Caption         =   "OLE Client Demo"
  4.    Height          =   4725
  5.    Left            =   615
  6.    LinkMode        =   1  'Source
  7.    LinkTopic       =   "Form1"
  8.    ScaleHeight     =   71.173
  9.    ScaleMode       =   6  'Millimeter
  10.    ScaleWidth      =   139.7
  11.    Top             =   1740
  12.    Width           =   8040
  13.    Begin OleClient OleClient1 
  14.       Class           =   ""
  15.       Focus           =   -1  'True
  16.       Height          =   30
  17.       HostName        =   ""
  18.       Left            =   0
  19.       Protocol        =   "StdFileEditing"
  20.       ServerShow      =   -1  'True
  21.       ServerType      =   0  'Linked
  22.       SourceDoc       =   ""
  23.       SourceItem      =   ""
  24.       Timeout         =   32767
  25.       Top             =   0
  26.       Verb            =   0
  27.       Width           =   30
  28.    End
  29.    Begin Menu mnuFile 
  30.       Caption         =   "&File"
  31.       Begin Menu mnuOpenObject 
  32.          Caption         =   "&Open..."
  33.       End
  34.       Begin Menu mnuSaveObject 
  35.          Caption         =   "Save &As..."
  36.       End
  37.       Begin Menu sep4 
  38.          Caption         =   "-"
  39.       End
  40.       Begin Menu mnuFileExit 
  41.          Caption         =   "E&xit Demo"
  42.       End
  43.       Begin Menu mnuAbout 
  44.          Caption         =   "A&bout..."
  45.       End
  46.    End
  47.    Begin Menu mnuEdit 
  48.       Caption         =   "&Edit"
  49.       Begin Menu mnuCut 
  50.          Caption         =   "Cu&t"
  51.       End
  52.       Begin Menu mnuCopyObject 
  53.          Caption         =   "&Copy"
  54.       End
  55.       Begin Menu mnuPasteObject 
  56.          Caption         =   "&Paste"
  57.       End
  58.       Begin Menu mnuPasteLink 
  59.          Caption         =   "Paste &Link"
  60.       End
  61.       Begin Menu sep3 
  62.          Caption         =   "-"
  63.          Index           =   3
  64.       End
  65.       Begin Menu mnuDeleteObject 
  66.          Caption         =   "&Delete"
  67.       End
  68.       Begin Menu separator2 
  69.          Caption         =   "-"
  70.          Index           =   1
  71.       End
  72.       Begin Menu mnuLinks 
  73.          Caption         =   "&Links..."
  74.       End
  75.       Begin Menu mnuEditObject 
  76.          Caption         =   "EditObject"
  77.          Index           =   0
  78.          Visible         =   0   'False
  79.          Begin Menu mnuEditObjVerb 
  80.             Caption         =   "Edit"
  81.             Index           =   0
  82.          End
  83.       End
  84.       Begin Menu mnuEditObject 
  85.          Caption         =   "&Object"
  86.          Enabled         =   0   'False
  87.          Index           =   1
  88.       End
  89.       Begin Menu mnuUpdate 
  90.          Caption         =   "&Update"
  91.       End
  92.    End
  93.    Begin Menu mnuInsert 
  94.       Caption         =   "&Insert"
  95.       Begin Menu mnuInsertObject 
  96.          Caption         =   "&Object"
  97.       End
  98.    End
  99. Sub Form_Resize ()
  100.     OleClient1.Move 0, 0, frmMain.ScaleWidth, frmMain.ScaleHeight
  101. End Sub
  102. Sub Form_Unload (Cancel As Integer)
  103.     End
  104. End Sub
  105. Sub mnuAbout_Click ()
  106.   CenterForm Me, AboutBox
  107.   AboutBox.Show 1
  108. End Sub
  109. Sub mnuCopyObject_Click ()
  110.   'copy object to Clipboard
  111.   OleClient1.Action = OLE_COPY
  112. End Sub
  113. Sub mnuCut_Click ()
  114.   Call mnuCopyObject_Click
  115.   Call mnuDeleteObject_Click
  116. End Sub
  117. Sub mnuDeleteObject_Click ()
  118.   On Error Resume Next
  119.   ' if object needs to be saved
  120.   If Save = True Then
  121.     response% = MsgBox("Save Object?", 19)
  122.     Select Case response%
  123.     ' user pressed Yes
  124.     Case 6
  125.       Call mnuSaveObject_Click
  126.     ' user pressed Cancel
  127.     Case 2
  128.       Exit Sub
  129.     End Select
  130.   End If
  131.   ' delete the object
  132.   OleClient1.Action = OLE_DELETE
  133.   If Err Then
  134.     MsgBox Error$
  135.     Exit Sub
  136.   End If
  137.     'reset flags, object no longer contains an object
  138.     ContainsObject = False
  139.     LinkFlag = False
  140.     'reset edit object menu
  141.     mnuEditObject(0).Visible = False
  142.     mnuEditObject(1).Caption = "&Object"
  143.     mnuEditObject(1).Enabled = False
  144.     mnuEditObject(1).Visible = True
  145. End Sub
  146. Sub mnuEdit_Click ()
  147. 'enable/disable menu items
  148.   'if OleClient contains an object
  149.   If ContainsObject Then
  150.     mnuDeleteObject.Enabled = True
  151.     mnuCopyObject.Enabled = True
  152.     mnuCut.Enabled = True
  153.     mnuEditObject(0).Enabled = True
  154.     mnuEditObject(1).Enabled = True
  155.   Else
  156.     mnuDeleteObject.Enabled = False
  157.     mnuCopyObject.Enabled = False
  158.     mnuCut.Enabled = False
  159.     mnuEditObject(0).Enabled = False
  160.     mnuEditObject(1).Enabled = False
  161.   End If
  162.   'check if it's ok to paste embedded object
  163.   OleClient1.ServerType = OLE_EMBEDDED
  164.   OleClient1.Protocol = "StdFileEditing"
  165.   If OleClient1.PasteOK Then
  166.     mnuPasteObject.Enabled = True
  167.   Else
  168.     mnuPasteObject.Enabled = False
  169.   End If
  170.   'check if it's ok to paste linked object
  171.   OleClient1.ServerType = OLE_LINKED
  172.   If OleClient1.PasteOK Then
  173.     mnuPasteLink.Enabled = True
  174.   Else
  175.     mnuPasteLink.Enabled = False
  176.   End If
  177.   mnuUpdate.Enabled = False
  178.   'check if object is linked
  179.   If LinkFlag Then
  180.     mnuLinks.Enabled = True
  181.    'check if current object is a manual (frozen) link
  182.    'if so, allow user to update
  183.    If OleClient1.UpdateOptions = OLE_FROZEN Then mnuUpdate.Enabled = True
  184.   Else
  185.     mnuLinks.Enabled = False
  186.   End If
  187. End Sub
  188. Sub mnuEditObject_Click (Index As Integer)
  189.   'If single verb menu is selected
  190.   If Index = 1 Then
  191.     Call OleClient1_DblClick
  192.   End If
  193. End Sub
  194. Sub mnuEditObjVerb_Click (Index As Integer)
  195.     On Error Resume Next
  196.     ' Set the verb to perform when activated
  197.     frmMain.OleClient1.Verb = Index
  198.     ' Activate the object
  199.     frmMain.OleClient1.Action = OLE_ACTIVATE
  200.     If (Err) Then
  201.         MsgBox Error$
  202.    End If
  203. End Sub
  204. Sub mnuFile_Click ()
  205.   If Save And ContainsObject Then
  206.     mnuSaveObject.Enabled = True
  207.   Else
  208.     mnuSaveObject.Enabled = False
  209.   End If
  210. End Sub
  211. Sub mnuFileExit_Click ()
  212.   End
  213. End Sub
  214. Sub mnuInsert_Click ()
  215.   If ContainsObject Then
  216.     mnuInsertObject.Enabled = False
  217.   Else
  218.     mnuInsertObject.Enabled = True
  219.   End If
  220. End Sub
  221. Sub mnuInsertObject_Click ()
  222.   On Error Resume Next
  223.   'display insert dialog
  224.   Call CenterForm(frmMain, dlgInsert)
  225.   dlgInsert.Show 1
  226.   If CancelFlag Then 'user cancelled insert operation
  227.     CancelFlag = False   'reset flag
  228.   Else
  229.     'create new object
  230.     frmMain.OleClient1.Action = OLE_CREATE_NEW
  231.     If Err Then
  232.       MsgBox Error$
  233.     Else
  234.       'set object flag
  235.       ContainsObject = True
  236.     End If
  237.   End If
  238.   'initialize edit menu
  239.   Call InitEditObjectMenu
  240.   'restore cursor
  241.   Screen.MousePointer = 0
  242. End Sub
  243. Sub mnuLinks_Click ()
  244.   ' display Links dialog
  245.   Call CenterForm(frmMain, Links)
  246.   Links.Show 1
  247. End Sub
  248. Sub mnuOpenObject_Click ()
  249.     Dim FileNum As Integer
  250.     Fileform.Caption = "File Open"
  251.     Call CenterForm(frmMain, Fileform)
  252.     Fileform.Show 1
  253.         
  254. End Sub
  255. Sub mnuPasteLink_Click ()
  256.   On Error Resume Next
  257.   'linked object
  258.   OleClient1.ServerType = OLE_LINKED
  259.   'paste object
  260.   Screen.MousePointer = 11
  261.   OleClient1.Action = OLE_PASTE
  262.   If (Err) Then
  263.     MsgBox Error$
  264.   Else
  265.     ContainsObject = True
  266.     'call FindDisplayName to set RegIndex for the new object
  267.     DisplayName$ = FindDisplayName(OleClient1.Class)
  268.     'initialize edit menu
  269.     Call InitEditObjectMenu
  270.   End If
  271.   Screen.MousePointer = 0
  272.   'set flag, OleClient contains a linked object
  273.   LinkFlag = True
  274. End Sub
  275. Sub mnuPasteObject_Click ()
  276.   On Error Resume Next
  277.   ' set to embedded object
  278.   OleClient1.ServerType = OLE_EMBEDDED
  279.   ' paste object
  280.   Screen.MousePointer = 11
  281.   OleClient1.Action = OLE_PASTE
  282.   If (Err) Then
  283.     MsgBox Error$
  284.   Else
  285.     ContainsObject = True
  286.     ' call FindDisplayName to set RegIndex for the new object
  287.     DisplayName$ = FindDisplayName(OleClient1.Class)
  288.     ' initialize edit menu
  289.     Call InitEditObjectMenu
  290.   End If
  291.   ' since link wasn't pasted, disable links menu item
  292.   LinkFlag = False
  293.   Screen.MousePointer = 0
  294. End Sub
  295. Sub mnuSaveObject_Click ()
  296.     Dim FileNum As Integer
  297.     Fileform.Caption = "Save File As"
  298.     Fileform.filFiles.Refresh
  299.     Call CenterForm(frmMain, Fileform)
  300.     Fileform.Show 1
  301. End Sub
  302. Sub mnuUpdate_Click ()
  303.     OleClient1.Action = OLE_UPDATE
  304. End Sub
  305. Sub OleClient1_DblClick ()
  306.   On Error Resume Next
  307.   '0 is primary verb for each object in reg database
  308.   OleClient1.Verb = 0
  309.   OleClient1.Action = OLE_ACTIVATE
  310.   If (Err) Then
  311.     MsgBox Error$
  312.   End If
  313. End Sub
  314. Sub OleClient1_Updated (Code As Integer)
  315.   Dim RetVal As Integer
  316.   'set flag to enable save object menu
  317.   Save = True
  318.   RetVal = OleQueryBounds(OleClient1.LpOleObject, OleRect)
  319.   ' If the query function is successful
  320.   If RetVal = 0 Then
  321.     ' Set the ole client control's height and width to the
  322.     ' optimal size as specified by the server application
  323.     ' Remember to set the form's scalemode to millimeters
  324.     ' since the OleQueryBounds API returns the Rect structure
  325.     ' elements in 1/100 millimeters.
  326.     OleClient1.Width = OleRect.right / 100
  327.     OleClient1.Height = Abs(OleRect.bottom / 100)
  328.   End If
  329. End Sub
  330.