VB中如何嵌入其他应用程序
我想要在VB窗口中设一按钮,点击之后,能调用另一程序,并且该程序不会出现它自己的程序窗口,而是在VB主窗口中显示,也就是调用程序后直接就把程序显示在VB的窗口中,这该如何...
我想要在VB窗口中设一按钮,点击之后,能调用另一程序,并且该程序不会出现它自己的程序窗口,而是在VB主窗口中显示,也就是调用程序后直接就把程序显示在VB的窗口中,这该如何才能实现,望高手们帮帮忙啊~~
谢谢ljl88900的回答,按你的做法可以实现在窗口里打开程序,但如果要把打开的程序固定在VB主窗口的中间,该怎么做?另外,我如果要用OLE控件的话,我要的程序也可以调用,但是为什么打开的程序不能象打开EXCEL或则word那样,可以在OLE窗口里打开,而是又打开另一窗口呢,高手们再次帮帮忙啊~~~ 展开
谢谢ljl88900的回答,按你的做法可以实现在窗口里打开程序,但如果要把打开的程序固定在VB主窗口的中间,该怎么做?另外,我如果要用OLE控件的话,我要的程序也可以调用,但是为什么打开的程序不能象打开EXCEL或则word那样,可以在OLE窗口里打开,而是又打开另一窗口呢,高手们再次帮帮忙啊~~~ 展开
2个回答
展开全部
UINT WinExec:
WinExec("C:\\Windows\\Notepad.exe",SW_SHOW);
WinExec("C:\\Windows\\Notepad.exe C:\\aa.txt",SW_SHOW);
WinExec("C:\\...\\IExplorer.exe www.microsoft.com"尘晌,SW_SHOW);
HINSTANCE ShellExecute:
ShellExecute (NULL,"Open","Some.txt",NULL,NULL);
ShellExecute (NULL,"Open","www.microsoft.com",NULL,NULL);
BOOL CreateProcess 比较麻烦,但是它的功能最强.可以给程序传值,
控制程序的据柄,制定继承状态等等.在桌面上双击誉兄历图标庆搜打开应用,程序就是用它实现的.在MSDN中有详细介绍.
以上三种函数由简而繁,按实际情况调用.
WinExec("C:\\Windows\\Notepad.exe",SW_SHOW);
WinExec("C:\\Windows\\Notepad.exe C:\\aa.txt",SW_SHOW);
WinExec("C:\\...\\IExplorer.exe www.microsoft.com"尘晌,SW_SHOW);
HINSTANCE ShellExecute:
ShellExecute (NULL,"Open","Some.txt",NULL,NULL);
ShellExecute (NULL,"Open","www.microsoft.com",NULL,NULL);
BOOL CreateProcess 比较麻烦,但是它的功能最强.可以给程序传值,
控制程序的据柄,制定继承状态等等.在桌面上双击誉兄历图标庆搜打开应用,程序就是用它实现的.在MSDN中有详细介绍.
以上三种函数由简而繁,按实际情况调用.
展开全部
'在窗体代码区复制下面代码,然后运行程序,缺丛即可看到效果。
'=====代码部分=====
Option Explicit
Private Declare Function SetParent Lib "user32.dll" ( _
ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Const WS_EX_MDICHILD As Long = &H40&
Private Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE As Long = (-20)
Private Const WS_CHILD = &H40000000
Private Const WS_CHILDWINDOW = (WS_CHILD)
'把计算器作为子伍扮芹窗体
Private Sub Form_Load()
Dim lngCalculator As Long
Dim lngStyle As Long
Dim lngExStyle As Long
Shell "calc.exe", vbNormalFocus
lngCalculator = FindWindow(vbNullString, "计算器")
If lngCalculator >腔毕 0 Then
SetParent lngCalculator, Me.hwnd
SetWindowLong lngCalculator, GWL_EXSTYLE, WS_EX_MDICHILD
End If
End Sub
'=====代码部分=====
Option Explicit
Private Declare Function SetParent Lib "user32.dll" ( _
ByVal hWndChild As Long, _
ByVal hWndNewParent As Long) As Long
Private Declare Function SetWindowLong Lib "user32.dll" Alias "SetWindowLongA" ( _
ByVal hwnd As Long, _
ByVal nIndex As Long, _
ByVal dwNewLong As Long) As Long
Private Declare Function FindWindow Lib "user32.dll" Alias "FindWindowA" ( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As Long
Private Const WS_EX_MDICHILD As Long = &H40&
Private Const GWL_STYLE = (-16)
Private Const GWL_EXSTYLE As Long = (-20)
Private Const WS_CHILD = &H40000000
Private Const WS_CHILDWINDOW = (WS_CHILD)
'把计算器作为子伍扮芹窗体
Private Sub Form_Load()
Dim lngCalculator As Long
Dim lngStyle As Long
Dim lngExStyle As Long
Shell "calc.exe", vbNormalFocus
lngCalculator = FindWindow(vbNullString, "计算器")
If lngCalculator >腔毕 0 Then
SetParent lngCalculator, Me.hwnd
SetWindowLong lngCalculator, GWL_EXSTYLE, WS_EX_MDICHILD
End If
End Sub
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询