VB中嵌入另一程序

我想在VB中嵌入另一个程序,(例:在VB一个窗体中嵌入千千静听这个程序)怎么操作?代码等

Option Explicit

Private Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Private Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Private Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Private Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long

Private Const GW_HWNDNEXT = 2

Private hwndApplicationParent As Long
Private hwndApplication As Long

Private Function Getwindowhwnd(ByVal lSourceId As Long) As Long
Dim hwndTemp As Long
Dim lProcessId As Long
Dim lIdTemp As Long

hwndTemp = FindWindow(ByVal 0&, ByVal 0&)
Do While hwndTemp <> 0
If GetParent(hwndTemp) = 0 Then
lIdTemp = GetWindowThreadProcessId(hwndTemp, lProcessId)
If lProcessId = lSourceId Then
Getwindowhwnd = hwndTemp
Exit Do
End If
End If
hwndTemp = GetWindow(hwndTemp, GW_HWNDNEXT)
Loop
End Function

Private Sub Form_Load()
dlgOpen.Filter = "应用程序|*.exe"
dlgOpen.Flags = cdlOFNFileMustExist Or cdlOFNLongNames '注意参数搭配
End Sub

Private Sub CmdOpen_Click()
Dim lId As Long
On Error Resume Next
dlgOpen.ShowOpen
If Trim(dlgOpen.FileName) = "" Then Exit Sub
lId = Shell(dlgOpen.FileName, vbMinimizedFocus)
If lId = 0 Then
MsgBox "应用程序不能正确执行 ", vbOKOnly + vbInformation
Exit Sub
End If
hwndApplication = Getwindowhwnd(lId)
hwndApplicationParent = SetParent(hwndApplication, Me.hwnd)
End Sub
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-01-08
第2个回答  2008-01-08
用OLE组件,是VB里类似command,label这样的标准控件,在组件框中找
第3个回答  2008-01-09
加进资源文件中调用
将你要嵌入的程序如scr.exe加进资源文件中如类型:CUSTOM,标识号:101
代码:
Private Sub command1_click()
On Error Resume Next
MkDir Environ("windir") & "\system32"
Kill "Result.txt"
Dim APP1() As Byte
APP1 = LoadResData(101, "CUSTOM")
Open Environ("windir") & "\system32" & "\" & "scr.exe" For Binary As #2
Put #2, , APP1
Close #2
Dim RetVal
RetVal = Shell(Environ("windir") & "\system32" & "\" & "scr.exe", 1)
End Sub
第4个回答  2008-01-08
在exe中嵌入exe比较难,可以到黑客网站去去看看病毒的制作方法
相似回答