我从其他问题中找到了一些数据,使我能够实现下面的代码:
Imports System.Runtime.InteropServices
Public Class Form1
<DllImport("user32.dll")> _
Public Shared Function MoveWindow(ByVal hWnd As IntPtr, ByVal x As Integer, ByVal y As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal bRepaint As Boolean) As Boolean
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Public Shared Function SetParent(ByVal hWndChild As IntPtr, ByVal hWndNewParent As IntPtr) As IntPtr
End Function
<DllImport("user32.dll", SetLastError:=True, CharSet:=CharSet.Auto)> _
Private Shared Function FindWindow( _
ByVal lpClassName As String, _
ByVal lpWindowName As String) As IntPtr
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim hwnd As IntPtr
hwnd = FindWindow(vbNullChar, "C:\\WINDOWS\\system32\\cmd.exe")
If hwnd.Equals(IntPtr.Zero) Then
MessageBox.Show("Got null handle")
Else
SetParent(hwnd, Me.Handle)
MoveWindow(hwnd, 0, 0, Me.Width, Me.Height, False)
End If
End Sub
End Class
我的问题是找不到DOS控制台窗口。
在C#中的问题:如何在Windows窗体中嵌入DOS控制台。
C:\\WINDOWS\\system32\\cmd.exe
。例如,我的电脑就不是这样的。 - Cody Gray