我設法從其它問題,找到一些數據,讓我實現了下面的代碼:在窗口中嵌入一個DOS控制檯形成用Visual Basic
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# Embedding a DOS console in a windows form
你真的是指** DOS **嗎?我沒有意識到任何人仍在使用MS-DOS(是否仍然保留?) – 2012-01-12 08:06:11
我的意思是一個Windows控制檯。 [此窗口](http://www.coldstarstudios.com/temp/img.png)。 – Alrik 2012-01-12 08:11:47
你可能無法找到它,因爲它不會總是有這個標題:'C:\\ WINDOWS \\ system32 \\ cmd.exe'。例如,我的不在。 – 2012-01-12 11:22:11