如何在程序中嵌入DOS窗口
我要做的是在vb6窗体中嵌入一个已有的程序,该exe是dos界面。 --------------------编程问答-------------------- 思路:1、使用FindWindow查找到DOS界面窗口的句柄
2、使用SetParant将该窗口设置到目标窗体内 --------------------编程问答--------------------
--------------------编程问答-------------------- 谢谢及时指点,只要固定期在窗体中的位置就好了
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Sub Command1_Click()
Dim lngP As Long
Dim lngDOSHwnd As Long
lngDOSHwnd = FindWindow(vbNullString, "C:\WINDOWS\System32\cmd.exe")
lngP = SetParent(lngDOSHwnd, Me.hWnd)
End Sub
Private Sub Form_Load()
Shell "cmd.exe", vbNormalNoFocus
Me.WindowState = 2
End Sub
--------------------编程问答-------------------- 好人做到底
--------------------编程问答-------------------- 好人,非常感谢你
Option Explicit
Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long
Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long
Private Declare Function MoveWindow Lib "user32" (ByVal hwnd As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal bRepaint As Long) As Long
Private Sub Command1_Click()
Dim lngP As Long
Dim lngDOSHwnd As Long
lngDOSHwnd = FindWindow(vbNullString, "C:\WINDOWS\System32\cmd.exe")
lngP = SetParent(lngDOSHwnd, Me.hwnd)
lngP = MoveWindow(lngDOSHwnd, 100, 100, 200, 200, 0)
Me.Refresh
End Sub
Private Sub Form_Load()
Shell "cmd.exe"
Me.WindowState = 2
End Sub
--------------------编程问答-------------------- 非常感谢你不吝赐教,当我运行了一次调用dos后,点dos上的关闭按钮关掉dos。
再次点击COMMAND1_CLICK()时,就不出现dos了,是不是我并没有在vb里关掉调用的dos,怎么办呢?
--------------------编程问答-------------------- 在关闭CMD窗口前,要用lngP = SetParent(lngDOSHwnd, 0)执行一次。
--------------------编程问答-------------------- 谢谢你的指点,具体就是把Veron_04说的code修改一下用你语句,可没有成功,希望你再说一下好吗
--------------------编程问答-------------------- --------------------编程问答-------------------- 我是将commad_click按钮放在sstab里,这样的话dos时装载在form里的,是不是这个原因 --------------------编程问答-------------------- 把 Shell "cmd.exe" 放在command1里面。 不要放在Form_Load里面。
--------------------编程问答-------------------- 好,谢谢你
补充:VB , 基础类