安装MSDN全部
看看其Sample\VB98\OLECONT
就知道了
看看其Sample\VB98\OLECONT
就知道了
解决方案 »
- VB調用SHOCKWAVEFLASH時出錯
- vbscript把數據插入數據庫問題
- 一个datagrid与数据库连接查询的怪问题 急求帮助
- sql语句分组问题?
- VB&SQL2000SERVER
- 第一次用data控件,小问题,关于seek
- sleilei(雷磊) 请进。感谢你的代码
- to raeck:请问怎样往文件后面写数据?
- 在Outlook编辑新邮件的窗口,中间有一个工具拦可以编辑字体,请问在里VB怎么实现.(注:不是MDI窗口,是普通的FORM)
- getfiletime这个API怎么没有用啊!
- 很简单的问题,可我不会,麻烦各位大侠看看,送分!!!!!!!!!
- 263zyf(控件)请进来,有分!
Option ExplicitPublic MDINew As IntegerSub NewObject()
MDINew = True
NewOleForm
If ParentForm.ActiveForm.OLE1.OLEType = vbOLENone Then
Unload ParentForm.ActiveForm
End If
End SubSub DisplayInstructions()
' Declare local variables.
Dim MsgText
Dim PB
' Initialize the paragraph break variable.
PB = Chr(10) & Chr(13) & Chr(10) & Chr(13)
' Display the instructions.
MsgText = "To insert a new object, choose New from the File menu, and then select an object from the Insert Object dialog box."
MsgText = MsgText & PB & "Once you have saved an inserted object using the Save As command, you can use the Open command on the File menu to view the object in subsequent sessions."
MsgText = MsgText & PB & "To edit an object, double-click the object to display the editing environment for the application from which the object originated."
MsgText = MsgText & PB & "Click the object with the right mouse button to view the object's verbs."
MsgText = MsgText & PB & "Use the Copy, Delete, and Paste Special commands to copy, delete, and paste objects."
MsgText = MsgText & PB & "Choose the Update command to update the contents of the insertable object."
MsgBox MsgText, 64, "OLE Container Control Demo Instructions"
End SubSub NewOleForm()
Dim Newform As New ChildForm
Newform.Show
' Only display the Insert Object dialog box if the user chose New from the File menu.
If MDINew Then
ParentForm.ActiveForm.OLE1.InsertObjDlg
End If
UpdateCaption
End SubSub OpenObject()
MDINew = False
NewOleForm
OpenSave ("Open")
If ParentForm.ActiveForm.OLE1.OLEType = vbOLENone Then
Unload ParentForm.ActiveForm
End If
End Sub' Opening a new file will only work with a file that contains a valid OLE Automation object.
' To see this work, follow this procedure while the application is running.
' 1) From the File menu, choose New, and then specify an object.
' 2) Edit the object, and then choose Save As from the File menu.
' 3) Click the menu-control box for the object to close it.
' 4) From the File menu, choose Open, and then select the file you just saved.
Sub OpenSave(Action As String)
Dim Filenum
Filenum = FreeFile
' Set the common dialog options and filters.
ParentForm.ActiveForm.CommonDialog1.Filter = _
"Insertable objects (*.OLE)|*.OLE|All files (*.*)|*.*"
ParentForm.ActiveForm.CommonDialog1.FilterIndex = 1
ParentForm.ActiveForm.OLE1.FileNumber = FilenumOn Error Resume Next Select Case Action
Case "Save"
' Display the Save As dialog box.
ParentForm.ActiveForm.CommonDialog1.ShowSave
If Err Then
' User chose Cancel.
If Err = 32755 Then
Exit Sub
Else
MsgBox "An unanticipated error occurred with the Save As dialog box."
End If
End If
' Open and save the file.
Open ParentForm.ActiveForm.CommonDialog1.filename For Binary As Filenum
If Err Then
MsgBox (Error)
Exit Sub
End If
ParentForm.ActiveForm.OLE1.SaveToFile Filenum
If Err Then MsgBox (Error) Case "Open"
' Display File Open dialog box.
ParentForm.ActiveForm.CommonDialog1.ShowOpen
If Err Then
' User chose Cancel.
If Err = 32755 Then
Exit Sub
Else
MsgBox "An unanticipated error occurred with the Open File dialog box."
End If
End If
' Open the file.
Open ParentForm.ActiveForm.CommonDialog1.filename For Binary As Filenum
If Err Then
Exit Sub
End If
' Display the hourglass mouse pointer.
Screen.MousePointer = 11
ParentForm.ActiveForm.OLE1.ReadFromFile Filenum
If (Err) Then
If Err = 30015 Then
MsgBox "Not a valid object."
Else
MsgBox Error$
End If
Unload ParentForm.ActiveForm
End If
' If no errors occur during open, activate the object.
ParentForm.ActiveForm.OLE1.DoVerb -1 ' Set the form properties now that the OLE container control contains an object.
UpdateCaption
' Restore the mouse pointer.
Screen.MousePointer = 0
End Select
Close Filenum
End SubSub UpdateCaption()
' Set the form properties now that it contains an object.
ParentForm.ActiveForm.Caption = ParentForm.ActiveForm.OLE1.Class + " Object"
On Error Resume Next
End Sub
Object = "{F9043C88-F6F2-101A-A3C9-08002B2F49FB}#1.1#0"; "COMDLG32.OCX"
Begin VB.Form ChildForm
AutoRedraw = -1 'True
Caption = "OLE Object Container"
ClientHeight = 3330
ClientLeft = 1140
ClientTop = 3735
ClientWidth = 5550
LinkTopic = "Form1"
MDIChild = -1 'True
ScaleHeight = 3330
ScaleWidth = 5550
Begin MSComDlg.CommonDialog CommonDialog1
Left = 315
Top = 105
_ExtentX = 847
_ExtentY = 847
FilterIndex = 4096
FontSize = 8.40483e-38
End
Begin VB.OLE OLE1
Height = 3252
Left = 0
TabIndex = 0
Top = 0
Width = 5532
End
Begin VB.Menu mnuFile
Caption = "&File"
NegotiatePosition= 1 'Left
Begin VB.Menu mnuFileNew
Caption = "&New..."
End
Begin VB.Menu mnuSave
Caption = "&Save As..."
End
Begin VB.Menu mnuOpen
Caption = "&Open"
End
Begin VB.Menu sep1
Caption = "-"
End
Begin VB.Menu mnuExit
Caption = "E&xit"
End
Begin VB.Menu sep2
Caption = "-"
End
Begin VB.Menu mnuAbout
Caption = "A&bout..."
End
End
Begin VB.Menu mnuEdit
Caption = "&Edit"
Begin VB.Menu mnuCopy
Caption = "&Copy"
End
Begin VB.Menu mnuDelete
Caption = "&Delete"
End
Begin VB.Menu mnuSpecial
Caption = "Paste &Special..."
End
Begin VB.Menu esep2
Caption = "-"
End
Begin VB.Menu mnuUpdate
Caption = "&Update "
End
End
Begin VB.Menu mnuCloseOLE
Caption = "&Close Ole Object"
NegotiatePosition= 3 'Right
End
Begin VB.Menu mnuWindow
Caption = "&Window"
WindowList = -1 'True
Begin VB.Menu mnuCascade
Caption = "&Cascade"
End
Begin VB.Menu mnuTile
Caption = "&Tile"
End
Begin VB.Menu mnuArrange
Caption = "&Arrange Icons"
End
End
End
Attribute VB_Name = "ChildForm"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option ExplicitPrivate Sub Form_Load()
On Error Resume Next OLE1.Move 0, 0
OLE1.Height = Me.Height
OLE1.Width = Me.Width
OLE1.HostName = "OLE Container Control Demo"
End SubPrivate Sub mnuAbout_Click()
DisplayInstructions
End SubPrivate Sub mnuArrange_Click()
ParentForm.Arrange vbArrangeIcons
End SubPrivate Sub mnuCascade_Click()
ParentForm.Arrange vbCascade
End SubPrivate Sub mnuClose_Click()
' Close the OLE container control.
OLE1.Close
End SubPrivate Sub mnuCloseOLE_Click()
OLE1.Close
End SubPrivate Sub mnuCopy_Click()
If OLE1.AppIsRunning = True Then
OLE1.Copy
Else
OLE1.AppIsRunning = True
If OLE1.AppIsRunning Then OLE1.Copy
End If
If OLE1.OLEType <> vbOLENone Then ' If the control contains a valid object...
' Display the hourglass mouse pointer.
Screen.MousePointer = 11
If OLE1.AppIsRunning Then
OLE1.Copy ' Copy the object onto the Clipboard.
End If
End If
Screen.MousePointer = 0
End SubPrivate Sub mnuDelete_Click()
If OLE1.OLEType <> vbOLENone Then ' If the OLE container control contains a valid object...
OLE1.Delete ' Delete the object, and then unload the form.
End If
Unload Me
End SubPrivate Sub mnuEdit_Click()
On Error Resume Next
If Err Then
MsgBox "No contained object."
End If
If OLE1.PasteOK Then
ParentForm.ActiveForm.mnuSpecial.Enabled = True
Else
ParentForm.ActiveForm.mnuSpecial.Enabled = False
End If
End SubPrivate Sub mnuExit_Click()
End
End SubPrivate Sub mnuFileNew_Click()
NewObject
End SubPrivate Sub mnuOpen_Click()
OpenObject
End SubPrivate Sub mnuSave_Click()
OpenSave ("Save")
End SubPrivate Sub mnuSpecial_Click()
If OLE1.PasteOK Then
MDINew = False
OLE1.PasteSpecialDlg
Screen.MousePointer = 11
UpdateCaption
Screen.MousePointer = 0
End If
End SubPrivate Sub mnuTile_Click()
ParentForm.Arrange vbTileHorizontal
End SubPrivate Sub mnuUpdate_Click()
Screen.MousePointer = 11
OLE1.Update
Screen.MousePointer = 0
End SubPrivate Sub Ole1_ObjectMove(Left As Single, Top As Single, Width As Single, Height As Single)
OLE1.Move OLE1.Left, OLE1.Top, Width, Height
OLE1.Move Left, Top, OLE1.Width, OLE1.Height
End SubPrivate Sub OLE1_Resize(HeightNew As Single, WidthNew As Single)
OLE1.SizeMode = vbOLESizeAutoSize
End SubPrivate Sub Ole1_Updated(Code As Integer)
OLE1.SizeMode = vbOLESizeAutoSize
End Sub
把OLECONT的启动改成ChildForm
这样您该知道与多文档无关了
将无法实现你需要的功能。必须使用多文档。如果非要用单文档工程,那么应该使用DELPHI。
但是DELPHI中OLE控件的问题是,与一些提供者有兼容性问题。
例如PROJECT和POWERPOINT。请参考:
http://www.csdn.net/expert/topic/418/418865.xml?temp=.3371393
http://www.csdn.net/expert/topic/556/556052.xml?temp=.5872003