Private Declare Function SetParent Lib "user32" (ByVal hWndChild As Long, ByVal hWndNewParent As Long) As Long Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, ByVal lpWindowName As String) As Long Dim oParent As Long, npad As Long 'oParent是原来的父窗口句柄,npad是记事本句柄 Private Sub Command1_Click() Shell "notepad.exe", vbNormalFocus '打开记事本 End Sub Private Sub Command2_Click() npad = FindWindow(vbNullString, "计算器") '获取记事本句柄 oParent = SetParent(npad, Me.hwnd) '把记事本设为自己的一个子窗口 End Sub Private Sub Command3_Click() SetParent npad, oParent '把记事本还原为桌面窗口。注意这时候用的句柄还是原来的! End Sub 改变窗体大小 Option Explicit Private Declare Function FindWindow Lib "user32" Alias "FindWindowA" (ByVal lpClassName As Any, ByVal lpWindowName As String) As Long Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal x As Long, ByVal y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long Private Sub Command1_Click() Dim WindowHandle As Long WindowHandle = FindWindow(vbNullString, "data:, - Google chrome") 'QQ2009 改为你的窗体的标题 SetWindowPos WindowHandle, -1, 0, 0, 2000, 2000, &H40 '2000,2000 是你要设置窗口的大小 End Sub SetWindowPos WindowHandle, 0, 0, 0, 350, 350, &H40 '2000,2000 End Sub
转载声明:本站发布文章及版权归原作者所有,转载本站文章请注明文章来源!