Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


How To Activate The OLE Objects In Your Program

You can set the conditions under which an OLE object is activated using the AutoActivate property. Here are the possible values for that property (we’ll stick with vbOLEActivateDoubleclick, the default, in this chapter):

  vbOLEActivateManual—0; Manual. The object isn’t automatically activated. You can activate an object in code using the DoVerb method.
  vbOLEActivateGetFocus—1; Focus. If the OLE container control contains an object that supports single-click activation, the application that provides the object is activated when the OLE container control receives the focus.
  vbOLEActivateDoubleclick—2 (the default); Double-click. If the OLE container control contains an object, the application that provides the object is activated when the user double-clicks the OLE container control or presses Enter when the control has the focus.
  vbOLEActivateAuto—3; Automatic. If the OLE container control contains an object, the application that provides the object is activated based on the object’s normal method of activation either when the control receives the focus or when the user double-clicks the control.

For example, if you leave the OLE control’s AutoActivate property set to vbOLEActivateDoubleclick, the object is activated when the user double-clicks it. In fact, what really happens is that the OLE object primary verb is executed, and that verb is almost always a command to open the object for in-place editing. (For a list of the OLE verbs, see “Activating OLE Objects From Code” later in this chapter.) What that means in practice is that when you double-click an OLE object in a Visual Basic OLE control, the usual response is that the OLE object is opened for in-place editing.

What if you don’t want to edit the control in place? What if you prefer to launch the OLE server application in a separate window and work with the object there? In that case, you want to execute the object’s Open verb, not its Edit verb. To let the user use all the OLE verbs the object supports, you enable its OLE verb pop-up menu, and we’ll see how to do that in the next topic.

Activating OLE Objects With A Pop-Up Menu That Lists All OLE Verbs

To let the user select from among all the OLE verbs an object is capable of supporting, you set the AutoVerbMenu to True. When this property is True (the default), and the user right-clicks an inactive OLE object, a pop-up menu appears listing the OLE verbs the object supports.

For example, when you right-click an inactive Excel object in the OLE container example we’ve developed in the last few topics, a pop-up menu appears, displaying the possible OLE verbs you can us (see Figure 26.11). Selecting a verb in the pop-up menu executes that verb; here, the Edit verb opens the OLE object for in-place editing, and the Open verb launches Excel and opens the OLE object in Excel.


Figure 26.11  Pop-up menu listing the OLE verbs an Excel OLE object supports.


WARNING!  When the AutoVerbMenu property is True, Click events and MouseDown events don’t occur when the OLE container control is clicked with the right mouse button.

Activating OLE Objects From Code

In the previous few topics, we’ve seen how to add an OLE object to an OLE control and how to deactivate it. In fact, we’ve even seen how the object is activated when the user double-clicks it. But how can we activate an OLE object in code? To do that, you use the OLE control’s DoVerb method:

OLEControl.DoVerb ([ verb])

Here are the possible values for the verb argument—an OLE object’s primary verb is considered its default verb, and it usually opens the object for in-place editing:

  vbOLEPrimary—0; the default action for the object.
  vbOLEShow—1; activates the object for editing. If the application that created the object supports in-place activation, the object is activated within the OLE container control.
  vbOLEOpen—2; opens the object in a separate application window. If the application that created the object supports in-place activation, the object is activated in its own window.
  vbOLEHide—3; for embedded objects, hides the application that created the object.
  vbOLEUIActivate—4; if the object supports in-place activation, activates the object for in-place activation and shows any user interface tools. If the object doesn’t support in-place activation, the object doesn’t activate and an error occurs.
  vbOLEInPlaceActivate—5; if the user moves the focus to the OLE container control, creates a window for the object and prepares the object to be edited. An error occurs if the object doesn’t support activation on a single mouse click.
  vbOLEDiscardUndoState—6; used when the object is activated for editing to discard all record of changes that the object’s application can undo.

Let’s see an example. Here, we add a new item, Activate Object, to the File menu in the oleinsert example we’ve developed over the previous few topics. If the user clicks this item, we want to activate the OLE object in the OLE1 control, and we’ll do that by executing its primary verb:

Private Sub ActivateObject_Click()
    OLE1.DoVerb 0
End Sub

For example, if there’s an inactive Excel spreadsheet in the OLE control, selecting the Activate Object menu item will open it for in-place editing. The final code for this example is located in the oleinsert folder on this book’s accompanying CD-ROM.

Is An Object Linked Or Embedded?

You can use an OLE control’s OLEType property to determine how if an OLE object is linked or embedded. If the object is linked, OLEType will be set to Linked (0). If the object is embedded, OLEType will be set to Embedded (1).

Handling Multiple OLE Objects

So far, we’ve only dealt with a single OLE object in our example program, oleinsert. However, when you start working with multiple OLE controls in a program, there are some issues that you might not think of at first. For example, if you have two OLE controls in a form, and the user selects your program’s Insert Object menu item, which control do you insert the new OLE object into?


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.