Visual Basic 6 Black Book:OLE
function GetCookie (name)
{
var arg = name + "=";
var alen = arg.length;
var clen = document.cookie.length;
var i = 0;
while (i < clen)
{
var j = i + alen;
if (document.cookie.substring(i, j) == arg) {
var end = document.cookie.indexOf (";", j);
if (end == -1)
end = document.cookie.length;
return unescape(document.cookie.substring(j, end));
}
i = document.cookie.indexOf(" ", i) + 1;
if (i == 0) break;
}
return null;
}
var m1='';
var gifstr=GetCookie("UsrType");
if((gifstr!=0 ) && (gifstr!=null)) { m2=gifstr; }
document.write(m1+m2+m3);
Keyword
Title
Author
ISBN
Publisher
Imprint
Brief
Full
Advanced Search
Search Tips
Please Select
-----------
Components
Content Mgt
Certification
Databases
Enterprise Mgt
Fun/Games
Groupware
Hardware
IBM Redbooks
Intranet Dev
Middleware
Multimedia
Networks
OS
Prod Apps
Programming
Security
UI
Web Services
Webmaster
Y2K
-----------
New Titles
-----------
Free Archive
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
function isIE4()
{
return( navigator.appName.indexOf("Microsoft") != -1 && (navigator.appVersion.charAt(0)=='4') );
}
function bookMarkit()
{
var url="http://www.itknowledge.com/PSUser/EWBookMarks.html?url="+window.location+"&isbn=0";
parent.location.href=url;
//var win = window.open(url,"myitk");
//if(!isIE4())
// win.focus();
}
Search this book:
Previous
Table of Contents
Next
Copying And Pasting OLE Objects With The Clipboard
You can copy an OLE object to the Clipboard with an OLE controls Copy method, and you can paste an OLE object in the Clipboard to an OLE control with that controls Paste method. Neither of these methods takes any parameters. Lets see an example. Here, we can copy the OLE object in the OLE control OLE1 when the user clicks a command button, Command1, and paste that object into another OLE control, OLE2, when the user clicks a second command button, Command2.
When the user clicks Command1, then, we just copy the OLE object in OLE1 to the Clipboard (note that an OLE object should be running when you copy it to the Clipboard):
Private Sub Command1_Click()
OLE1.Copy
End Sub
When the user clicks Command2, we should paste the OLE object from the Clipboard to OLE2. First, we check to make sure there is an object in the Clipboard that the OLE2 control will accept, using that controls PasteOK method:
Private Sub Command2_Click()
If OLE2.PasteOK Then
...
End If
If its okay to paste into OLE2, we use that controls Paste method to paste the OLE object in the Clipboard into OLE2:
Private Sub Command2_Click()
If OLE2.PasteOK Then
OLE2.Paste
End If
...
Finally, we check to make sure the paste operation was completed successfully:
End SubPrivate Sub Command2_Click()
If OLE2.PasteOK Then
OLE2.Paste
End If
If OLE2.OLEType = None Then
MsgBox "OLE operation failed."
End If
End Sub
Zooming OLE Objects
The Testing Department is on the phone again. The OLE control youre using to show a picture of the companys glorious founder is great, but cant it be larger?
You can zoom (that is, enlarge or shrink) OLE objects using the SizeMode property of OLE controls. Here are the possible values for the SizeMode property:
vbOLESizeClip0 (the default); Clip. The object is displayed in actual size. If the object is larger than the OLE control, its image is clipped by the controls borders.
vbOLESizeStretch1; Stretch. The objects image is sized to fill the OLE control. (Note that the image may not maintain the original proportions of the object.)
vbOLESizeAutoSize2; Autosize. The OLE control is resized to display the entire object.
vbOLESizeZoom3; Zoom. The object is resized to fill the OLE container control as much as possible while still maintaining the original proportions of the object.
Lets see an example. Add a new OLE control to a form, setting its SizeMode property to VbOLESizeZoom. Next, we add a button, Command1, with the caption Zoom and add this code to enlarge OLE1 when the user clicks that button:
Private Sub Command1_Click()
OLE1.Width = 3 * OLE1.Width
OLE1.Height = 3 * OLE1.Height
End Sub
Thats all it takes. As an example, were zooming the Excel spreadsheet you see in Figure 26.15.
Figure 26.15 Zooming an OLE object.
Saving And Retrieving Embedded Objects Data
Because an embedded OLE objects data is stored in your program, you are responsible for storing and retrieving that data if its changed. Otherwise, when a form containing an OLE container control is closed, any changes to the data associated with that control are lost.
To save updated data from an object to a file, you use the OLE container controls SaveToFile method. Once the data has been saved to a file, you can open the file and restore the object with the ReadFromFile method. Lets see an example. When the user clicks a button, Command1, we can open a new file, data.ole, for binary output:
Private Sub Command1_Click ()
Dim intFileNumber as Integer
intFileNumber = FreeFile
Open "data.ole" For Binary As #intFileNumber
...
Now we can save the OLE object in an OLE control, OLE1, to that file this way using SaveToFile:
Private Sub Command1_Click ()
Dim intFileNumber as Integer
intFileNumber = FreeFile
Open "data.ole" For Binary As #intFileNumber
OLE1.SaveToFile intFileNumber
Close #intFileNumber
End Sub
WARNING! If you save multiple OLE objects to a file, you should read them from the file in the same order you wrote them.
Later, we can read the stored OLE object back to OLE1 with the ReadFromFile method when the user clicks another button, Command2. First, we open the data.ole file:
Private Sub Command2_Click ()
Dim intFileNumber as Integer
intFileNumber = FreeFile
Open "data.ole" For Binary As #intFileNumber
...
Then we read the OLE object back into OLE1 with the ReadFromFile method:
Private Sub Command2_Click ()
Dim intFileNumber as Integer
intFileNumber = FreeFile
Open "data.ole" For Binary As #intFileNumber
OLE1.ReadFromFile intFileNumber
Close #intFileNumber
End Sub
And thats itnow weve stored and retrieved an OLE file to and from disk (which is called persisting the object).
Handling OLE Object Updated Events
You can determine when an OLE object has been updated with the OLE controls Updated event. Your program is passed a variable named code in the Updated event handler to indicate what operation updated the OLE objects data:
Sub OLEobject_Updated (code As Integer)
Here are the possible settings for code:
vbOLEChanged0; the objects data was changed.
vbOLESaved1; the objects data was saved by the application that created the object.
vbOLEClosed2; the file containing the linked objects data was closed by the server application that created the object.
vbOLERenamed3; the file containing the linked objects data was renamed by the server application that created the object.
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.
Wyszukiwarka
Podobne podstrony:
Brother Fax 910, 920, 921, 930, 931, 940, 945, MFC2SB 927 2SD1247922 927927 929931 (2)929 931931 932Zero Bania u Cygana (931)ReadMe (927)931 935więcej podobnych podstron