2013-05-26
展开全部
新建一个midi子窗体,将其linktopci属性设置为:MDIForm1并添加一个CommonDialog空间,命名为CommonDialog1在菜单编辑器中输入以下内容: 标题 名称 打开程序(&O) mnuOpen '顶级菜单栏 记事本(&N) mnuNotepad '一级菜单栏 打开(&O)... mnuOpenNotepad '二级菜单栏 释放(&R)... mnuResNotepad '二级菜单栏 计算器(&C) mnuCalc '一级菜单栏 打开(&O)... mnuOpenCalc '二级菜单栏 释放(&R)... mnuResCalc '二级菜单栏 QQ QQQQ '一级菜单栏 浏览(&V)... view '一级菜单栏 - mnuSep1 '分隔符退出(&Q) mnuClose '一级菜单栏 输入如下代码:Option ExplicitPrivate Notepad_OldParent&
Private Calc_OldParent&
Private Notepad_Hwnd&
Private Calc_Hwnd&
Private Sub mnuClose_Click()
Unload Me
End SubPrivate Sub mnuOpenCalc_Click()
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long pid = Shell("calc.exe", vbNormalFocus)
If pid = 0 Then
MsgBox "程序启动出现未知错误!"
Exit Sub
End If Calc_Hwnd& = InstanceToWnd(pid) Calc_OldParent& = SetParent(Calc_Hwnd&, Me.hwnd) mnuOpenCalc.Enabled = False
mnuResCalc.Enabled = True
End SubPrivate Sub mnuOpenNotepad_Click()
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long pid = Shell("notepad.exe", vbNormalFocus)
If pid = 0 Then
MsgBox "程序启动出现未知错误!"
Exit Sub
End If Notepad_Hwnd& = InstanceToWnd(pid) Notepad_OldParent& = SetParent(Notepad_Hwnd&, Me.hwnd) mnuOpenNotepad.Enabled = False
mnuResNotepad.Enabled = True
End Sub Private Sub mnuResCalc_Click()
SetParent Calc_Hwnd&, Calc_OldParent& mnuOpenCalc.Enabled = True
mnuResCalc.Enabled = False
End SubPrivate Sub mnuResNotepad_Click()
SetParent Notepad_Hwnd&, Notepad_OldParent& mnuOpenNotepad.Enabled = True
mnuResNotepad.Enabled = False
End SubPrivate Sub QQQQ_Click()
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long
CommonDialog1.Filter = "应用程序|*.exe"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
pid = Shell(CommonDialog1.FileName & " /START QQUIN: PWDHASH:DO/k3iTCiQbiCh8cv7rkpA== /STAT:40", vbNormalFocus)
If pid = 0 Then
MsgBox "程序启动出现未知错误!"
Exit Sub
End If Notepad_Hwnd& = InstanceToWnd(pid) Notepad_OldParent& = SetParent(Notepad_Hwnd&, Me.hwnd)End SubPrivate Sub view_Click()
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long
CommonDialog1.Filter = "应用程序|*.exe"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
pid = Shell(CommonDialog1.FileName, vbNormalFocus)
If pid = 0 Then
MsgBox "程序启动出现未知错误!"
Exit Sub
End If Notepad_Hwnd& = InstanceToWnd(pid) Notepad_OldParent& = SetParent(Notepad_Hwnd&, Me.hwnd)End Sub
新建一个模块,输入如下代码:Option ExplicitPublic Const GW_HWNDNEXT = 2Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongFunction InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long
Dim test_pid As Long
Dim test_thread_id As Long test_hwnd = FindWindow(ByVal 0&, ByVal 0&) Do While test_hwnd <> 0 If GetParent(test_hwnd) = 0 Then test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid) If test_pid = target_pid Then InstanceToWnd = test_hwnd
Exit Do
End If
End If test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function
Private Calc_OldParent&
Private Notepad_Hwnd&
Private Calc_Hwnd&
Private Sub mnuClose_Click()
Unload Me
End SubPrivate Sub mnuOpenCalc_Click()
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long pid = Shell("calc.exe", vbNormalFocus)
If pid = 0 Then
MsgBox "程序启动出现未知错误!"
Exit Sub
End If Calc_Hwnd& = InstanceToWnd(pid) Calc_OldParent& = SetParent(Calc_Hwnd&, Me.hwnd) mnuOpenCalc.Enabled = False
mnuResCalc.Enabled = True
End SubPrivate Sub mnuOpenNotepad_Click()
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long pid = Shell("notepad.exe", vbNormalFocus)
If pid = 0 Then
MsgBox "程序启动出现未知错误!"
Exit Sub
End If Notepad_Hwnd& = InstanceToWnd(pid) Notepad_OldParent& = SetParent(Notepad_Hwnd&, Me.hwnd) mnuOpenNotepad.Enabled = False
mnuResNotepad.Enabled = True
End Sub Private Sub mnuResCalc_Click()
SetParent Calc_Hwnd&, Calc_OldParent& mnuOpenCalc.Enabled = True
mnuResCalc.Enabled = False
End SubPrivate Sub mnuResNotepad_Click()
SetParent Notepad_Hwnd&, Notepad_OldParent& mnuOpenNotepad.Enabled = True
mnuResNotepad.Enabled = False
End SubPrivate Sub QQQQ_Click()
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long
CommonDialog1.Filter = "应用程序|*.exe"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
pid = Shell(CommonDialog1.FileName & " /START QQUIN: PWDHASH:DO/k3iTCiQbiCh8cv7rkpA== /STAT:40", vbNormalFocus)
If pid = 0 Then
MsgBox "程序启动出现未知错误!"
Exit Sub
End If Notepad_Hwnd& = InstanceToWnd(pid) Notepad_OldParent& = SetParent(Notepad_Hwnd&, Me.hwnd)End SubPrivate Sub view_Click()
Dim pid As Long
Dim buf As String
Dim buf_len As Long
Dim styles As Long
CommonDialog1.Filter = "应用程序|*.exe"
CommonDialog1.ShowOpen
If CommonDialog1.FileName = "" Then Exit Sub
pid = Shell(CommonDialog1.FileName, vbNormalFocus)
If pid = 0 Then
MsgBox "程序启动出现未知错误!"
Exit Sub
End If Notepad_Hwnd& = InstanceToWnd(pid) Notepad_OldParent& = SetParent(Notepad_Hwnd&, Me.hwnd)End Sub
新建一个模块,输入如下代码:Option ExplicitPublic Const GW_HWNDNEXT = 2Declare Function GetWindowThreadProcessId Lib "user32" (ByVal hwnd As Long, lpdwProcessId As Long) As Long
Declare Function GetParent Lib "user32" (ByVal hwnd As Long) As Long
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Long, ByVal lpWindowName As Long) As Long
Declare Function GetWindow Lib "user32" (ByVal hwnd As Long, ByVal wCmd As Long) As Long
Declare Function GetWindowText Lib "user32" Alias "GetWindowTextA" (ByVal hwnd As Long, ByVal lpString As String, ByVal cch As Long) As Long
Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As LongFunction InstanceToWnd(ByVal target_pid As Long) As Long
Dim test_hwnd As Long
Dim test_pid As Long
Dim test_thread_id As Long test_hwnd = FindWindow(ByVal 0&, ByVal 0&) Do While test_hwnd <> 0 If GetParent(test_hwnd) = 0 Then test_thread_id = GetWindowThreadProcessId(test_hwnd, test_pid) If test_pid = target_pid Then InstanceToWnd = test_hwnd
Exit Do
End If
End If test_hwnd = GetWindow(test_hwnd, GW_HWNDNEXT)
Loop
End Function
2013-05-26
展开全部
先把自己的程序窗口设置成MDI 然后通过自己的程序窗口调用其它的程序 这样 你的程序就成了主窗口了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询