|
|
![]() | |
|
|
|
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
How To Activate The OLE Objects In Your ProgramYou can set the conditions under which an OLE object is activated using the AutoActivate property. Here are the possible values for that property (well stick with vbOLEActivateDoubleclick, the default, in this chapter):
For example, if you leave the OLE controls 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 dont 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 objects 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 well see how to do that in the next topic. Activating OLE Objects With A Pop-Up Menu That Lists All OLE VerbsTo 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 weve 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.
Activating OLE Objects From CodeIn the previous few topics, weve seen how to add an OLE object to an OLE control and how to deactivate it. In fact, weve 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 controls DoVerb method: OLEControl.DoVerb ([ verb]) Here are the possible values for the verb argumentan OLE objects primary verb is considered its default verb, and it usually opens the object for in-place editing:
Lets see an example. Here, we add a new item, Activate Object, to the File menu in the oleinsert example weve developed over the previous few topics. If the user clicks this item, we want to activate the OLE object in the OLE1 control, and well do that by executing its primary verb:
Private Sub ActivateObject_Click()
OLE1.DoVerb 0
End Sub
For example, if theres 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 books accompanying CD-ROM. Is An Object Linked Or Embedded?You can use an OLE controls 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 ObjectsSo far, weve 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 programs Insert Object menu item, which control do you insert the new OLE object into?
|
|
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. |