16,721
社区成员




Public Class Form1
Const SWP_SHOWWINDOW = &H40
Const SWP_HIDEWINDOW = &H80
Const WS_VSCROLL = &H200000
Const WS_HSCROLL = &H100000
Const WS_CAPTION = &HC00000
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const WS_OVERLAPPED = &H0&
Const WS_SYSMENU = &H40000
Const HWND_TOPMOST = -1
Dim hwnd As Integer
Dim hprocess As Integer
Dim pid As Integer
Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
'Declare Function DestroyWindow Lib "user32" (ByVal hwnd As Integer) As Integer
Declare Function DestroyWindow Lib "user32" Alias "DestroyWindow" (ByVal hwnd As Integer) As Integer
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal Flags As Boolean) As Boolean
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nlndex As Integer, ByVal wNewLong As Integer) As Integer
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Diagnostics.Process.Start(("cmd.exe"))
System.Threading.Thread.Sleep(18) '过快下面的FindWindow有可能找不到窗体
hwnd = FindWindow(vbNullString, "c:\windows\system32\cmd.exe")
SetParent(hwnd, Me.TabPage1.Handle) '直接嵌套到TabPage1内
SetWindowLong(hwnd, (-16), GetWindowLong(hwnd, (-16)) And (Not WS_CAPTION) And (Not WS_VSCROLL) And (Not WS_HSCROLL)) '设置窗体样式
SetWindowPos(Me.Handle, -1, 100, 100, 800, 500, SWP_SHOWWINDOW) '改变子窗体位置
'MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '替代setwindowpos 可以正常调用
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
With TabControl1
.Width = Me.Width - Button1.Width - 35
.Height = Me.Height
End With
MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '随父窗体一起缩放
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DestroyWindow(hwnd) '也不能正常调用,只能关闭自己 破坏(即清除)指定的窗口以及它的所有子窗口(在vb里使用:用处不大。原文:it is unlikely to be of much use.)
End Sub
End Class
Public Class Form1
Const SWP_SHOWWINDOW = &H40
Const SWP_HIDEWINDOW = &H80
Const WS_VSCROLL = &H200000
Const WS_HSCROLL = &H100000
Const WS_CAPTION = &HC00000
Const WS_MINIMIZEBOX = &H20000
Const WS_MAXIMIZEBOX = &H10000
Const WS_OVERLAPPED = &H0&
Const WS_SYSMENU = &H40000
Const HWND_TOPMOST = -1
Dim hwnd As Integer
Dim hprocess As Integer
Dim pid As Integer
Declare Function SetParent Lib "user32" Alias "SetParent" (ByVal hWndChild As Integer, ByVal hWndNewParent As Integer) As Integer
Declare Auto Function DestroyWindow Lib "user32" (ByVal hwnd As Integer) As Integer
Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Integer
Declare Function MoveWindow Lib "user32" Alias "MoveWindow" (ByVal hwnd As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal Flags As Boolean) As Boolean
Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Integer, ByVal nlndex As Integer, ByVal wNewLong As Integer) As Integer
Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Integer, ByVal nIndex As Integer) As Integer
Declare Function SetWindowPos Lib "user32" Alias "SetWindowPos" (ByVal hwnd As Integer, ByVal hWndInsertAfter As Integer, ByVal x As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer) As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
System.Diagnostics.Process.Start(("cmd.exe"))
System.Threading.Thread.Sleep(18) '过快下面的FindWindow有可能找不到窗体
hwnd = FindWindow(vbNullString, "c:\windows\system32\cmd.exe")
SetParent(hwnd, Me.TabPage1.Handle) '直接嵌套到TabPage1内
SetWindowLong(hwnd, (-16), GetWindowLong(hwnd, (-16)) And (Not WS_CAPTION) And (Not WS_VSCROLL) And (Not WS_HSCROLL)) '设置窗体样式
SetWindowPos(Me.Handle, -1, 100, 100, 100, 100, SWP_SHOWWINDOW) '改变子窗体位置
'MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '替代setwindowpos 可以正常调用
End Sub
Private Sub Form1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
With TabControl1
.Width = Me.Width - Button1.Width
.Height = Me.Height
End With
MoveWindow(hwnd, 0, 0, Me.TabPage1.Width - 4, Me.TabPage1.Height, True) '随父窗体一起缩放
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
DestroyWindow(hwnd) '也不能正常调用,只能关闭自己
' 我也没能帮你弄好关闭
End Sub
End Class